mirror of
https://github.com/correl/mtgsqlive.git
synced 2024-12-01 03:00:09 +00:00
minor changes
This commit is contained in:
parent
54c713e7d6
commit
d2408a9b51
2 changed files with 20 additions and 5 deletions
|
@ -86,6 +86,10 @@ def json_to_db(json_file_opened, database_connection):
|
||||||
c.close()
|
c.close()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
if len(sys.argv) != 4:
|
||||||
|
print("Must provide 3 arguements: should_create, database_location, json_location")
|
||||||
|
os._exit(1)
|
||||||
|
|
||||||
i = sys.argv[1] # Should create new DB
|
i = sys.argv[1] # Should create new DB
|
||||||
db_path = os.path.expanduser(sys.argv[2]) # File location for database
|
db_path = os.path.expanduser(sys.argv[2]) # File location for database
|
||||||
|
|
||||||
|
|
|
@ -5,19 +5,23 @@ import os
|
||||||
import fileinput
|
import fileinput
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def id(x):
|
def id(x):
|
||||||
return x
|
return x
|
||||||
|
|
||||||
DECODERS = { 'setName': id, 'setCode': id, 'setReleaseDate': id }
|
DECODERS = { 'setName': id, 'setCode': id, 'setReleaseDate': id }
|
||||||
|
|
||||||
def dict_from_row(row):
|
def dict_from_row(row):
|
||||||
return {k: DECODERS.get(k, json.loads)(v) for k, v in zip(row.keys(), row) if v is not None}
|
return {k: DECODERS.get(k, json.loads)(v) for k, v in zip(row.keys(), row) if v is not None}
|
||||||
|
|
||||||
|
def remove_set_info(dictionary):
|
||||||
|
dictionary.pop("setName", None)
|
||||||
|
dictionary.pop("setCode", None)
|
||||||
|
dictionary.pop("setReleaseDate", None)
|
||||||
|
return dictionary
|
||||||
|
|
||||||
def set_dictionary(row):
|
def set_dictionary(row):
|
||||||
return dict(zip(row.keys(), row))
|
return dict(zip(row.keys(), row))
|
||||||
|
|
||||||
|
|
||||||
def db_to_json(database_connection):
|
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()
|
||||||
|
@ -35,11 +39,14 @@ def db_to_json(database_connection):
|
||||||
setReleaseDate = None
|
setReleaseDate = None
|
||||||
for row in card_rows:
|
for row in card_rows:
|
||||||
row = dict_from_row(row)
|
row = dict_from_row(row)
|
||||||
returnData.append(row)
|
|
||||||
if not setName or not setReleaseDate:
|
if not setName or not setReleaseDate:
|
||||||
setName = row["setName"]
|
setName = row["setName"]
|
||||||
setReleaseDate = row["setReleaseDate"]
|
setReleaseDate = row["setReleaseDate"]
|
||||||
|
|
||||||
|
row = remove_set_info(row)
|
||||||
|
returnData.append(row)
|
||||||
|
|
||||||
mainDict[setCode["setCode"]] = dict(zip(["cards", "name", "releaseDate"], [returnData, setName, setReleaseDate]))
|
mainDict[setCode["setCode"]] = dict(zip(["cards", "name", "releaseDate"], [returnData, setName, setReleaseDate]))
|
||||||
setName = None
|
setName = None
|
||||||
setReleaseDate = None
|
setReleaseDate = None
|
||||||
|
@ -49,6 +56,10 @@ def db_to_json(database_connection):
|
||||||
return mainDict
|
return mainDict
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
if len(sys.argv) != 3:
|
||||||
|
print("Must provide 2 arguements: database_location, json_output_location")
|
||||||
|
os._exit(1)
|
||||||
|
|
||||||
db_path = sqlite3.connect(os.path.expanduser(sys.argv[1])) # File location for database
|
db_path = sqlite3.connect(os.path.expanduser(sys.argv[1])) # File location for database
|
||||||
file_path = os.path.expanduser(sys.argv[2]) # File location for output
|
file_path = os.path.expanduser(sys.argv[2]) # File location for output
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue