X-Git-Url: https://git.yukkurigames.com/?p=mlpccg-meta.git;a=blobdiff_plain;f=mlpccg%2FCardDb.py;h=77d0b2424075409bfdb7745f5ca167e86470eeb9;hp=043bc92ec68d2d3cc6b0610d0f8e2e311fd68208;hb=HEAD;hpb=a7a7ac1456426456a5a33ebeac28693804693716 diff --git a/mlpccg/CardDb.py b/mlpccg/CardDb.py index 043bc92..77d0b24 100644 --- a/mlpccg/CardDb.py +++ b/mlpccg/CardDb.py @@ -2,9 +2,10 @@ import json import os import urllib 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', @@ -14,14 +15,16 @@ class CardDb: set_names = {} # generated - def __init__(self, json_path='cards.json', extra_path='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 = {} @@ -34,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 @@ -54,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='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)