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 = {}
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
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)