From b914c445d1a8c9e73f9a979042b2482034ab124e Mon Sep 17 00:00:00 2001 From: tritoch Date: Mon, 19 Jun 2017 11:35:13 -0500 Subject: [PATCH 1/3] Aftermath handling for MTGS --- spoilers.py | 74 ++++++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/spoilers.py b/spoilers.py index fe5bdfeb..8b98913f 100644 --- a/spoilers.py +++ b/spoilers.py @@ -50,27 +50,33 @@ def parse_mtgs(mtgs, manual_cards=[], card_corrections=[], delete_cards=[], spli if count < 1: sys.exit("No cards found, exiting to prevent file overwrite") - #for manual_card in manual_cards: - #initialize some keys - #manual_card['colorArray'] = [] - #manual_card['colorIdentityArray'] = [] - #manual_card['color'] = '' - #manual_card['colorIdentity'] = '' - #if not manual_card.has_key('rules'): - # manual_card['rules'] = '' - #if not manual_card.has_key('pow'): - # manual_card['pow'] = '' - #if not manual_card.has_key('setnumber'): - # manual_card['setnumber'] = '0' - #if not manual_card.has_key('type'): - # manual_card['type'] = '' - #see if this is a dupe - #and remove the spoiler version - #i trust my manual cards over their data - #for card in cards: - # if card['name'] == manual_card['name']: - # cards.remove(card) - #cards.append(manual_card) + cards2 = [] + for card in cards: + if 'rules' in card: + htmltags = re.compile(r'<.*?>') + card['rules'] = htmltags.sub('', card['rules']) + if '//' in card['name']: + print 'Splitting up Aftermath card ' + card['name'] + card['name'] = card['name'].replace(' // ','//') + card1 = card.copy() + card1['name'] = card['name'].split('//')[0] + card1['rules'] = card['rules'].split('\n\n\n')[0] + card2 = dict(cost='',cmc='',img='',pow='',name='',rules='',type='', + color='', altname='', colorIdentity='', colorArray=[], colorIdentityArray=[], setnumber='', rarity='') + card2["name"] = card['name'].split('//')[1] + card2["rules"] = "Aftermath" + card['rules'].split('Aftermath')[1] + card2['cost'] = re.findall(r'{.*}',card['rules'])[0].replace('{','').replace('}','').upper() + card2['type'] = re.findall(r'}\n.*\n', card['rules'])[0].replace('}','').replace('\n','') + if 'setnumber' in card: + card1['setnumber'] = card['setnumber'] + 'a' + card2['setnumber'] = card['setnumber'] + 'b' + if 'rarity' in card: + card2['rarity'] = card['rarity'] + cards2.append(card1) + cards2.append(card2) + else: + cards2.append(card) + cards = cards2 for card in cards: card['name'] = card['name'].replace(''', '\'') @@ -89,17 +95,10 @@ def parse_mtgs(mtgs, manual_cards=[], card_corrections=[], delete_cards=[], spli .replace('Costner',"Counter") card['type'] = card['type'].replace(' ',' ')\ .replace('Crature', 'Creature') + if card['type'][-1] == ' ': card['type'] = card['type'][:-1] - #if card['name'] in card_corrections: - # for correction in card_corrections[card['name']]: - # if correction != 'name': - # card[correction] = card_corrections[card['name']][correction] - # for correction in card_corrections[card['name']]: - # if correction == 'name': - # oldname = card['name'] - # card['name'] = card_corrections[oldname]['name'] - # card['rules'] = card['rules'].replace(oldname, card_corrections[oldname][correction]) + if 'cost' in card and len(card['cost']) > 0: workingCMC = 0 stripCost = card['cost'].replace('{','').replace('}','') @@ -109,8 +108,8 @@ def parse_mtgs(mtgs, manual_cards=[], card_corrections=[], delete_cards=[], spli elif not manaSymbol == 'X': workingCMC += 1 card['cmc'] = workingCMC - # figure out color - for c in 'WUBRG': + + for c in 'WUBRG': #figure out card's color if c not in card['colorIdentity']: if c in card['cost']: card['color'] += c @@ -121,14 +120,15 @@ def parse_mtgs(mtgs, manual_cards=[], card_corrections=[], delete_cards=[], spli cleanedcards = [] - #let's remove any cards that are named in delete_cards array - for card in cards: + for card in cards: #let's remove any cards that are named in delete_cards array if not card['name'] in delete_cards: cleanedcards.append(card) cards = cleanedcards cardlist = [] cardarray = [] + + for card in cards: dupe = False for dupecheck in cardarray: @@ -750,7 +750,11 @@ def get_image_urls(mtgjson, isfullspoil, setname, setlongname, setSize=269): if match3: c['url'] = match3.groupdict()['img'] else: - match2 = re.search(mythicspoilerpattern.format((c['name']).lower().replace(' ', '').replace(''', '').replace('-', '').replace('\'','').replace(',', '')), text2, re.DOTALL) + if 'names' in c: + mythicname = c['names'][0] + c['names'][1] + else: + mythicname = c['name'] + match2 = re.search(mythicspoilerpattern.format(mythicname.lower().replace(' ', '').replace(''', '').replace('-', '').replace('\'','').replace(',', '')), text2, re.DOTALL) if match2 and not isfullspoil: c['url'] = match2.group(0).replace(' src="', 'http://mythicspoiler.com/').replace('">', '') pass From 9f1b096e0c035b66d21da2e14acca8e7819cf62e Mon Sep 17 00:00:00 2001 From: tritoch Date: Mon, 19 Jun 2017 11:55:09 -0500 Subject: [PATCH 2/3] Allow comments in JSON files --- cards_corrections.json | 7 +++++++ cards_delete.json | 10 +++++++++- main.py | 13 +++++-------- requirements.txt | 3 ++- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/cards_corrections.json b/cards_corrections.json index 7a73a41b..25ef57c2 100644 --- a/cards_corrections.json +++ b/cards_corrections.json @@ -1,2 +1,9 @@ +// Objects to be fixed +// "Card Name": { +// "Key": "New Value" +// } +// List of Keys: +// + { } \ No newline at end of file diff --git a/cards_delete.json b/cards_delete.json index fe51488c..509ff735 100644 --- a/cards_delete.json +++ b/cards_delete.json @@ -1 +1,9 @@ -[] +// List of card strings to be removed +// [ +// "Card Name 1", +// "Card Name 2" +// ] +// Case-sensitive + +[ +] \ No newline at end of file diff --git a/main.py b/main.py index ed4791b9..fa32421b 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,8 @@ # -*- coding: utf-8 -*- import spoilers -import sys import os -import shutil -#import configparser +import commentjson import json -#import urllib presets = { "isfullspoil": False, #when full spoil comes around, we only want to use WOTC images @@ -17,17 +14,17 @@ presets = { } with open('set_info.json') as data_file: - setinfos = json.load(data_file) + setinfos = commentjson.load(data_file) with open('cards_manual.json') as data_file: - manual_sets = json.load(data_file) + manual_sets = commentjson.load(data_file) #manual_cards = manual_cards['cards'] with open('cards_corrections.json') as data_file: - card_corrections = json.load(data_file) + card_corrections = commentjson.load(data_file) with open('cards_delete.json') as data_file: - delete_cards = json.load(data_file) + delete_cards = commentjson.load(data_file) errorlog = [] diff --git a/requirements.txt b/requirements.txt index f053885b..09b173ce 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ feedparser lxml Pillow datetime -beautifulsoup4 \ No newline at end of file +beautifulsoup4 +commentjson \ No newline at end of file From aac7664cafefde9024eb466bbeceed1d21a8ac66 Mon Sep 17 00:00:00 2001 From: tritoch Date: Mon, 19 Jun 2017 13:06:40 -0400 Subject: [PATCH 3/3] Revert "Allow comments in JSON files" This reverts commit 9f1b096e0c035b66d21da2e14acca8e7819cf62e. --- cards_corrections.json | 7 ------- cards_delete.json | 10 +--------- main.py | 13 ++++++++----- requirements.txt | 3 +-- 4 files changed, 10 insertions(+), 23 deletions(-) diff --git a/cards_corrections.json b/cards_corrections.json index 25ef57c2..7a73a41b 100644 --- a/cards_corrections.json +++ b/cards_corrections.json @@ -1,9 +1,2 @@ -// Objects to be fixed -// "Card Name": { -// "Key": "New Value" -// } -// List of Keys: -// - { } \ No newline at end of file diff --git a/cards_delete.json b/cards_delete.json index 509ff735..fe51488c 100644 --- a/cards_delete.json +++ b/cards_delete.json @@ -1,9 +1 @@ -// List of card strings to be removed -// [ -// "Card Name 1", -// "Card Name 2" -// ] -// Case-sensitive - -[ -] \ No newline at end of file +[] diff --git a/main.py b/main.py index fa32421b..ed4791b9 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,11 @@ # -*- coding: utf-8 -*- import spoilers +import sys import os -import commentjson +import shutil +#import configparser import json +#import urllib presets = { "isfullspoil": False, #when full spoil comes around, we only want to use WOTC images @@ -14,17 +17,17 @@ presets = { } with open('set_info.json') as data_file: - setinfos = commentjson.load(data_file) + setinfos = json.load(data_file) with open('cards_manual.json') as data_file: - manual_sets = commentjson.load(data_file) + manual_sets = json.load(data_file) #manual_cards = manual_cards['cards'] with open('cards_corrections.json') as data_file: - card_corrections = commentjson.load(data_file) + card_corrections = json.load(data_file) with open('cards_delete.json') as data_file: - delete_cards = commentjson.load(data_file) + delete_cards = json.load(data_file) errorlog = [] diff --git a/requirements.txt b/requirements.txt index 09b173ce..f053885b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,5 +3,4 @@ feedparser lxml Pillow datetime -beautifulsoup4 -commentjson \ No newline at end of file +beautifulsoup4 \ No newline at end of file