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()
|
||||
|
||||
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
|
||||
db_path = os.path.expanduser(sys.argv[2]) # File location for database
|
||||
|
||||
|
|
|
@ -5,19 +5,23 @@ import os
|
|||
import fileinput
|
||||
import sys
|
||||
|
||||
|
||||
def id(x):
|
||||
return x
|
||||
|
||||
DECODERS = { 'setName': id, 'setCode': id, 'setReleaseDate': id }
|
||||
|
||||
|
||||
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}
|
||||
|
||||
def remove_set_info(dictionary):
|
||||
dictionary.pop("setName", None)
|
||||
dictionary.pop("setCode", None)
|
||||
dictionary.pop("setReleaseDate", None)
|
||||
return dictionary
|
||||
|
||||
def set_dictionary(row):
|
||||
return dict(zip(row.keys(), row))
|
||||
|
||||
|
||||
|
||||
def db_to_json(database_connection):
|
||||
database_connection.row_factory = sqlite3.Row # Enable keys for the rows
|
||||
cursor = database_connection.cursor()
|
||||
|
@ -35,11 +39,14 @@ def db_to_json(database_connection):
|
|||
setReleaseDate = None
|
||||
for row in card_rows:
|
||||
row = dict_from_row(row)
|
||||
returnData.append(row)
|
||||
|
||||
if not setName or not setReleaseDate:
|
||||
setName = row["setName"]
|
||||
setReleaseDate = row["setReleaseDate"]
|
||||
|
||||
row = remove_set_info(row)
|
||||
returnData.append(row)
|
||||
|
||||
mainDict[setCode["setCode"]] = dict(zip(["cards", "name", "releaseDate"], [returnData, setName, setReleaseDate]))
|
||||
setName = None
|
||||
setReleaseDate = None
|
||||
|
@ -49,6 +56,10 @@ def db_to_json(database_connection):
|
|||
return mainDict
|
||||
|
||||
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
|
||||
file_path = os.path.expanduser(sys.argv[2]) # File location for output
|
||||
|
||||
|
|
Loading…
Reference in a new issue