@@ -0,0 +1,2301 @@
+'''%0AUsage:%0A  python scraper_converter.py scraped.db formatted.db%0A%0AProcesses the cards scraped using the gatherer downloader and adds sane attributes fields for querying%0A(int pow/toughness, cmc) and saves the output to a new sqlite database.%0A%0ACard attributes are saved according to finder.models.Card%0A'''%0A%0Aimport sqlsoup%0Afrom finder import (%0A    controllers,%0A    models,%0A    util%0A)%0A%0Asides = %5Bu'left', u'right'%5D%0A%0A# raw field name =%3E models.Card attribute name%0A# note that these are only the fields we care about (printedname, printedrules etc are omitted)%0Afield_conversion = %7B%0A    'id': 'multiverse_id',%0A    'name': 'name',%0A    'cost': 'cost',%0A    'color': 'color',%0A    'type': 'type',%0A    'set': 'set',%0A    'rarity': 'rarity',%0A    'power': 'power',%0A    'toughness': 'toughness',%0A    'rules': 'oracle_rules',%0A    'flavor': 'flavor_text',%0A    'watermark': 'watermark',%0A    'cardnum': 'number',%0A    'artist': 'artist',%0A    'rulings': 'rulings'%0A%7D%0A%0A%0Adef convert(indb, outdb, scale=10):%0A    '''Convert each entry in indb using various parsers and save to outdb'''%0A    src = sqlsoup.SQLSoup('sqlite:///%7B%7D'.format(indb))%0A%0A    dst = None%0A    raise NotImplementedError('dst is None!')%0A%0A    rows = src.MTGCardInfo.all()%0A    for row in rows:%0A        convert_row(row, dst, scale=scale)%0A%0A%0Adef convert_row(row, dst, scale=10):%0A    '''Convert a src row into one or more dst cards'''%0A    name = util.sanitize(row.name)%0A    attrs = %7Bdkey: getattr(row, skey) for skey, dkey in field_conversion.iteritems()%7D%0A    # Split card, process both halves%0A    if u'//' in name:%0A        for side in sides:%0A            dst.add(to_card(attrs, scale=scale, split=side))%0A    else:%0A        dst.add(to_card(attrs, scale=scale))%0A%0A%0Adef to_card(attrs, scale=10, split=''):%0A    '''attrs is a dictionary whose keys are finder.model.Card attributes.'''%0A    card = models.Card(**attrs)%0A    controllers.process_card(card, scale=scale, split=split)%0A    return card%0A%0Aif __name__ == %22__main__%22:%0A    import argparse%0A    parser = argparse.ArgumentParser()%0A    parser.add_argument('input', help='sqlite .db database to load from (should use gatherer downloader save format')%0A    parser.add_argument('output', help='filename to save well-formed card sqlite .db database to')%0A%0A    args = parser.parse_args()%0A    convert(args.input, args.output, scale=10)%0A

Add shell of "GathererDownloader" converter