Skip to content

Instantly share code, notes, and snippets.

@ZeldaZach
Created July 13, 2016 20:12
Show Gist options
  • Select an option

  • Save ZeldaZach/d11e328f44fc870f8dc7cbc04b96ce28 to your computer and use it in GitHub Desktop.

Select an option

Save ZeldaZach/d11e328f44fc870f8dc7cbc04b96ce28 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import json
import sqlite3
import time
JSON_FILE = "SOI-x.json" #Set Name
DB_FILE = "Magic " + str(time.time()) + ".db"
traffic = json.load(open(JSON_FILE))["cards"]
conn = sqlite3.connect(DB_FILE)
c = conn.cursor()
c.execute('create table table_name (name, manaCost, cmc, colors, type_, supertypes, types, subtypes, rarity, text, flavor, artist, number, power, toughness, layout, multiverseid, imageName, id_, names, colorIdentity, loyalty, variations, watermark, border, timeshifted, hand, life, reserved, releaseDate, starter, rulings, foreignNames, printings, originalType, legalities, source)')
for i in range(0, len(traffic)):
try:
name = str(traffic[i]["name"])
except KeyError:
name = None
try:
manaCost = str(traffic[i]["manaCost"])
except KeyError:
manaCost = None
try:
cmc = str(traffic[i]["cmc"])
except KeyError:
cmc = None
try:
colors = str(traffic[i]["colors"])
except KeyError:
colors = None
try:
type_ = str(traffic[i]["type"])
except KeyError:
type_ = None
try:
supertypes = str(traffic[i]["supertypes"])
except KeyError:
supertypes = None
try:
types = str(traffic[i]["types"])
except KeyError:
types = None
try:
subtypes = str(traffic[i]["subtypes"])
except KeyError:
subtypes = None
try:
rarity = str(traffic[i]["rarity"])
except KeyError:
rarity = None
try:
text = str(traffic[i]["text"])
except KeyError:
text = None
try:
flavor = str(traffic[i]["flavor"])
except KeyError:
flavor = None
try:
artist = str(traffic[i]["artist"])
except KeyError:
artist = None
try:
number = str(traffic[i]["number"])
except KeyError:
number = None
try:
power = str(traffic[i]["power"])
except KeyError:
power = None
try:
toughness = str(traffic[i]["toughness"])
except KeyError:
toughness = None
try:
layout = str(traffic[i]["layout"])
except KeyError:
layout = None
try:
multiverseid = str(traffic[i]["multiverseid"])
except KeyError:
multiverseid = None
try:
imageName = str(traffic[i]["imageName"])
except KeyError:
imageName = None
try:
id_ = str(traffic[i]["id"])
except KeyError:
id_ = None
try:
names = str(traffic[i]["names"])
except KeyError:
names = None
try:
colorIdentity = str(traffic[i]["colorIdentity"])
except KeyError:
colorIdentity = None
try:
loyalty = str(traffic[i]["loyalty"])
except KeyError:
loyalty = None
try:
variations = str(traffic[i]["variations"])
except KeyError:
variations = None
try:
watermark = str(traffic[i]["watermark"])
except KeyError:
watermark = None
try:
border = str(traffic[i]["border"])
except KeyError:
border = None
try:
timeshifted = str(traffic[i]["timeshifted"])
except KeyError:
timeshifted = None
try:
hand = str(traffic[i]["hand"])
except KeyError:
hand = None
try:
life = str(traffic[i]["life"])
except KeyError:
life = None
try:
reserved = str(traffic[i]["reserved"])
except KeyError:
reserved = None
try:
releaseDate = str(traffic[i]["releaseDate"])
except KeyError:
releaseDate = None
try:
starter = str(traffic[i]["starter"])
except KeyError:
starter = None
try:
rulings = str(traffic[i]["rulings"])
except KeyError:
rulings = None
try:
foreignNames = str(traffic[i]["foreignNames"])
except KeyError:
foreignNames = None
try:
printings = str(traffic[i]["printings"])
except KeyError:
printings = None
try:
originalType = str(traffic[i]["originalType"])
except KeyError:
originalType = None
try:
legalities = str(traffic[i]["legalities"])
except KeyError:
legalities = None
try:
source = str(traffic[i]["source"])
except KeyError:
source = None
data = [name, manaCost, cmc, colors, type_, supertypes, types, subtypes, rarity, text, flavor, artist, number, power, toughness, layout, multiverseid, imageName, id_, names, colorIdentity, loyalty, variations, watermark, border, timeshifted, hand, life, reserved, releaseDate, starter, rulings, foreignNames, printings, originalType, legalities, source]
#print(data)
c.execute('insert into table_name values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', data)
conn.commit()
c.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment