46
48
# Try creating the tables
48
50
self.__cur.execute(config.create_trophy_command)
51
except sqlite3.OperationalError:
52
print("Trophy Table existed")
49
55
self.__cur.execute(config.create_desc_command)
56
except sqlite3.OperationalError:
57
print("Description Table existed")
50
60
self.__cur.execute(config.create_app_command)
61
except sqlite3.OperationalError:
62
print("App Table existed")
51
65
self.__cur.execute(config.create_set_command)
66
except sqlite3.OperationalError:
67
print("Set Table existed")
52
70
self.__cur.execute(config.create_history_command)
53
print("All tables create successfully")
54
71
except sqlite3.OperationalError:
55
print("Table existed")
72
print("History Table existed")
57
75
self.__res_cursor=None
61
79
fetch_trp = config.fetch_trophy_where %("id",)
62
80
res_trophy = self.__cur.execute(fetch_trp, { "value":json_data["id"] })
63
81
if(len(res_history.fetchall()) == 0 and len(res_trophy.fetchall()) == 0):
65
# Inserting Description
66
# Searching and Inserting Sets
67
# Searching and Inserting Apps
83
# Searching and Inserting Sets
84
set_list = self.__cur.execute(config.fetch_set_byname, (json_data["setname"],))
85
matched_set = set_list.fetchone()
86
if matched_set is None:
87
# Does not exist, create one
88
print("Set '%s' does not exist. Creating." %(json_data["setname"],))
89
setid = int(random.random()*10000000)
90
self.__cur.execute(config.insert_set_command, (setid, json_data["setname"], json_data["seticon"]))
93
print("Set '%s' already exists. Will be reused" %(matched_set[1],))
94
setid = matched_set[0]
96
# Searching and Inserting Apps
97
app_list = self.__cur.execute(config.fetch_app_byapp, (json_data["app"],))
98
matched_app = app_list.fetchone()
99
if matched_app is None:
100
# Does not exist, create one
101
print("App '%s' does not exist. Creating." %(json_data["app"],))
102
appid = int(random.random()*10000000)
103
self.__cur.execute(config.insert_app_command, (appid, json_data["app"], json_data["appname"]))
106
print("App '%s' already exists. Will be reused" %(matched_app[1],))
107
appid = matched_app[0]
109
# Inserting Description
110
desc_list = json_data["desc"]
111
for desc in desc_list:
112
self.__cur.execute(config.insert_desc_command, (json_data["id"], desc["lang"], desc["desc"]))
114
timestamp = int(datetime.datetime(1970,01,01).today().strftime("%s"))
68
117
# Inserting Trophy
118
self.__cur.execute(config.insert_trophy_command, ( json_data["id"], \
119
json_data["title"], \
120
json_data["iconpath"], \
123
int(json_data["priority"]), \
124
bool(json_data["unlocked"]), \
126
json_data["stockicon"]))
69
128
# Inserting History
129
self.__cur.execute(config.insert_history_command, (json_data["id"], timestamp))
72
print("Insertion Failed")
75
137
def AwardTrophy(self, id):