Created
July 13, 2016 21:01
-
-
Save ZeldaZach/00c798eaf1a33e6ddf3c92d1d38f1643 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import json | |
| import sqlite3 | |
| import time | |
| JSON_FILE = "AllSets-x.json" #Set Name | |
| DB_FILE = "Magic " + str(time.time()) + ".db" | |
| # Get the value of the card, return None if NULL | |
| def getVal(data, field): | |
| try: | |
| retVal = str(data[field]) | |
| except KeyError: | |
| retVal = None | |
| return retVal | |
| traffic = json.load(open(JSON_FILE)) | |
| conn = sqlite3.connect(DB_FILE) | |
| c = conn.cursor() | |
| c.execute('create table table_name (name, names, setName, thisSet, setReleaseDate, thisCard_id, manaCost, cmc, colors, colorIdentity, supertypes, types, subtypes, rarity, text, flavor, artist, number, power, toughness, loyalty, multiverseid, variations, reserved, rulings, printings, legalities)') | |
| # Get the setnames in the AllSets file and put them into a dictionary for later use | |
| setNames = [] | |
| for i in traffic.keys(): | |
| setNames.append(i) | |
| # Iterate through each set, one at a time | |
| for thisSet in setNames: | |
| data = traffic[thisSet] # All of the data for the set (I.e. SOI-x.json) | |
| setName = data["name"] | |
| setReleaseDate = data["releaseDate"] | |
| setCards = data["cards"] # Now iterate through the setCards for each card in the set | |
| for thisCard in setCards: | |
| thisCard_id = getVal(thisCard, "id") | |
| name = getVal(thisCard, "name") | |
| names = getVal(thisCard, "names") | |
| manaCost = getVal(thisCard, "manaCost") | |
| cmc = getVal(thisCard, "cmc") | |
| colors = getVal(thisCard, "colors") | |
| colorIdentity = getVal(thisCard, "colorIdentity") | |
| supertypes = getVal(thisCard, "supertypes") | |
| types = getVal(thisCard, "types") | |
| subtypes = getVal(thisCard, "subtypes") | |
| rarity = getVal(thisCard, "rarity") | |
| text = getVal(thisCard, "text") | |
| flavor = getVal(thisCard, "flavor") | |
| artist = getVal(thisCard, "artist") | |
| number = getVal(thisCard, "number") | |
| power = getVal(thisCard, "power") | |
| toughness = getVal(thisCard, "toughness") | |
| loyalty = getVal(thisCard, "loyalty") | |
| multiverseid = getVal(thisCard, "multiverseid") | |
| variations = getVal(thisCard, "variations") | |
| reserved = getVal(thisCard, "reserved") | |
| rulings = getVal(thisCard, "rulings") | |
| printings = getVal(thisCard, "printings") | |
| legalities = getVal(thisCard, "legalities") | |
| thisCard_data = [name, names, setName, thisSet, setReleaseDate, thisCard_id, manaCost, cmc, colors, colorIdentity, supertypes, types, subtypes, rarity, text, flavor, artist, number, power, toughness, loyalty, multiverseid, variations, reserved, rulings, printings, legalities] | |
| c.execute('insert into table_name values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', thisCard_data) | |
| conn.commit() | |
| c.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment