mirror of
https://github.com/correl/mtgsqlive.git
synced 2024-12-01 11:09:57 +00:00
wip
This commit is contained in:
parent
39067cf618
commit
9099f59346
1 changed files with 13 additions and 11 deletions
|
@ -16,33 +16,35 @@ def db_to_json(database_connection):
|
||||||
database_connection.row_factory = sqlite3.Row # Enable keys for the rows
|
database_connection.row_factory = sqlite3.Row # Enable keys for the rows
|
||||||
cursor = database_connection.cursor()
|
cursor = database_connection.cursor()
|
||||||
|
|
||||||
cursor.execute("SELECT DISTINCT setCode from cards")
|
cursor.execute("SELECT DISTINCT setCode from cards LIMIT 3,5")
|
||||||
|
|
||||||
mainDict = []
|
mainDict = []
|
||||||
returnData = ""
|
returnData = []
|
||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
for setCode in rows:
|
for setCode in rows:
|
||||||
setCode = remove_empty_keys(dict_from_row(setCode))
|
setCode = remove_empty_keys(dict_from_row(setCode))
|
||||||
cursor.execute("SELECT * FROM cards WHERE setCode = '%s'" % setCode["setCode"])
|
cursor.execute("SELECT * FROM cards WHERE setCode = '%s' LIMIT 5" % setCode["setCode"])
|
||||||
card_rows = cursor.fetchall()
|
card_rows = cursor.fetchall()
|
||||||
|
|
||||||
for row in card_rows:
|
for row in card_rows:
|
||||||
row = remove_empty_keys(dict_from_row(row))
|
row = remove_empty_keys(dict_from_row(row))
|
||||||
dump = json.dumps(row, sort_keys=True)
|
|
||||||
returnData += dump
|
returnData.append(row)
|
||||||
|
|
||||||
mainDict.append([setCode, returnData])
|
mainDict.append([setCode, returnData])
|
||||||
returnData = ""
|
returnData = []
|
||||||
database_connection.close()
|
database_connection.close()
|
||||||
return str(mainDict)
|
return mainDict
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
d = os.path.join(os.path.expanduser(input("Location of database: ")), "Magic DB.db")
|
#d = os.path.join(os.path.expanduser(input("Location of database: ")), "Magic DB.db")
|
||||||
|
d = os.path.join(os.path.expanduser("~/Desktop"), "Magic DB.db")
|
||||||
d = sqlite3.connect(d)
|
d = sqlite3.connect(d)
|
||||||
|
|
||||||
xml = os.path.join(os.path.expanduser(input("Location of save file: ")), "Output.json")
|
#xml = os.path.join(os.path.expanduser(input("Location of save file: ")), "Output.json")
|
||||||
|
xml = os.path.join(os.path.expanduser("~/Desktop"), "Output.json")
|
||||||
|
|
||||||
json_code = db_to_json(d)
|
json_code = json.dumps(db_to_json(d), indent=4, sort_keys=True)
|
||||||
|
|
||||||
writeFile = open(xml, 'w')
|
writeFile = open(xml, 'w')
|
||||||
writeFile.write(json_code)
|
writeFile.write(json_code)
|
||||||
|
|
Loading…
Reference in a new issue