X-Git-Url: https://git.yukkurigames.com/?p=mlpccg-meta.git;a=blobdiff_plain;f=mlpccg%2FCardDb.py;h=77d0b2424075409bfdb7745f5ca167e86470eeb9;hp=cadbc37951ea72546ecb75f5cac3d240fe6efeb8;hb=HEAD;hpb=0460c3c46cd330bbae7043e42a8a490662bf1e60 diff --git a/mlpccg/CardDb.py b/mlpccg/CardDb.py index cadbc37..77d0b24 100644 --- a/mlpccg/CardDb.py +++ b/mlpccg/CardDb.py @@ -5,7 +5,7 @@ import logging import time class CardDb: - set_ids = { + set_ids = { # NOTE: if there is ever an 'f' in here, update the ponyhead link generation 'Premiere': 'pr', 'Canterlot Nights': 'cn', 'Rock \'n Rave': 'rr', @@ -15,14 +15,16 @@ class CardDb: set_names = {} # generated - def __init__(self, json_path='data/cards.json', extra_path='data/cards_extra.json'): + def __init__(self, url='https://dl.dropboxusercontent.com/u/32733446/cards.json'): logging.debug('init card database') + json_path = 'cards.json' + for name, id in CardDb.set_ids.iteritems(): CardDb.set_names[id] = name if not os.path.isfile(json_path) or time.time() - os.path.getmtime(json_path) >= 24 * 60 * 60: - self.download_cards_json(json_path) + self.download_cards_json(json_path, url) self._db = self.parse_cards_json(json_path) self._by_name = {} @@ -35,8 +37,6 @@ class CardDb: for alt_id in card['allIds']: self._by_id['%s%s' % (CardDb.set_ids[card['set']], alt_id.lower())] = card - self.integrate_cards_extra_json(extra_path) - def all(self): return self._db @@ -55,21 +55,7 @@ class CardDb: logging.exception('failed') return [] - def integrate_cards_extra_json(self, extra_path): - logging.debug('parsing %s', extra_path) - try: - with open(extra_path) as f: - extra = json.load(f) - for card_id, data in extra.items(): - try: - self._by_id[card_id.lower()].update(data) - except: - logging.exception('failed extra data for %s', card_id) - - except IOError: - logging.exception('failed') - - def download_cards_json(self, json_path='data/cards.json', url='https://dl.dropboxusercontent.com/u/32733446/cards.json'): + def download_cards_json(self, json_path, url): logging.debug('downloading %s from %s', json_path, url) try: urllib.urlretrieve(url, json_path)