mirror of
https://github.com/correl/mtgsqlive.git
synced 2024-12-01 03:00:09 +00:00
split cards to sets
This commit is contained in:
parent
a642418064
commit
39067cf618
1 changed files with 17 additions and 10 deletions
|
@ -16,25 +16,32 @@ def db_to_json(database_connection):
|
|||
database_connection.row_factory = sqlite3.Row # Enable keys for the rows
|
||||
cursor = database_connection.cursor()
|
||||
|
||||
cursor.execute(""" SELECT * from cards ORDER BY setCode""")
|
||||
cursor.execute("SELECT DISTINCT setCode from cards")
|
||||
|
||||
# TODO: Figure out how to put them into LEA {cards}, LEB {cards}, ..., SOI {cards}
|
||||
mainDict = []
|
||||
returnData = ""
|
||||
rows = cursor.fetchall()
|
||||
for row in rows:
|
||||
row = remove_empty_keys(dict_from_row(row))
|
||||
dump = json.dumps(row, sort_keys=True)
|
||||
returnData += dump
|
||||
|
||||
for setCode in rows:
|
||||
setCode = remove_empty_keys(dict_from_row(setCode))
|
||||
cursor.execute("SELECT * FROM cards WHERE setCode = '%s'" % setCode["setCode"])
|
||||
card_rows = cursor.fetchall()
|
||||
|
||||
for row in card_rows:
|
||||
row = remove_empty_keys(dict_from_row(row))
|
||||
dump = json.dumps(row, sort_keys=True)
|
||||
returnData += dump
|
||||
|
||||
mainDict.append([setCode, returnData])
|
||||
returnData = ""
|
||||
database_connection.close()
|
||||
return returnData
|
||||
return str(mainDict)
|
||||
|
||||
def main():
|
||||
d = os.path.join(os.path.expanduser(input("Location of database: ")), "Magic DB.db")
|
||||
d = sqlite3.connect(d)
|
||||
|
||||
|
||||
xml = os.path.join(os.path.expanduser(input("Location of save file: ")), "Output.json")
|
||||
|
||||
|
||||
json_code = db_to_json(d)
|
||||
|
||||
writeFile = open(xml, 'w')
|
||||
|
|
Loading…
Reference in a new issue