Skip to content

Instantly share code, notes, and snippets.

@ZeldaZach
Last active July 13, 2016 20:01
Show Gist options
  • Select an option

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

Select an option

Save ZeldaZach/8d15bc60f87d12b65b9d82a426fad125 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import json
import sqlite3
import time
JSON_FILE = "SOI.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_)')
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
data = [name, manaCost, cmc, colors, type_, supertypes, types, subtypes, rarity, text, flavor, artist, number, power, toughness, layout, multiverseid, imageName, id_]
#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