mylib.try_del

This commit is contained in:
relikd
2020-09-21 15:15:40 +02:00
parent f56abb6a9b
commit 7edf470684
3 changed files with 14 additions and 18 deletions

View File

@@ -259,7 +259,15 @@ def enum_data_appids():
yield path[prfx:].replace(os.sep, '.') yield path[prfx:].replace(os.sep, '.')
# JSON read # JSON
def try_del(index, keys):
for x in keys:
try:
del(index[x])
except KeyError:
pass
def json_read(path): def json_read(path):
with open(path, 'r') as fp: with open(path, 'r') as fp:

View File

@@ -48,12 +48,8 @@ def download_info(bundle_id, lang, force=False):
json = mylib.download(url, isJSON=True) json = mylib.download(url, isJSON=True)
json = json['results'][0] json = json['results'][0]
# delete unused keys to save on storage # delete unused keys to save on storage
for key in ['supportedDevices', 'releaseNotes', 'description', mylib.try_del(json, ['supportedDevices', 'releaseNotes', 'description',
'screenshotUrls', 'ipadScreenshotUrls']: 'screenshotUrls', 'ipadScreenshotUrls'])
try:
del(json[key])
except KeyError:
continue
mylib.json_write(fname, json, pretty=True) mylib.json_write(fname, json, pretty=True)

View File

@@ -19,14 +19,6 @@ def load_json_from_disk(fname):
return mylib.json_read(fname) if mylib.file_exists(fname) else {} return mylib.json_read(fname) if mylib.file_exists(fname) else {}
def try_del(index, keys):
for x in keys:
try:
del(index[x])
except KeyError:
pass
def json_to_list(json): def json_to_list(json):
return [ return [
json['sum_rec'], json['sum_rec'],
@@ -62,14 +54,14 @@ def list_to_json(list):
def write_summary_index(index, bundle_ids, deleteOnly=False): def write_summary_index(index, bundle_ids, deleteOnly=False):
for bid in bundle_ids: for bid in bundle_ids:
# delete old value # delete old value
try_del(index, [bid]) mylib.try_del(index, [bid])
if deleteOnly: if deleteOnly:
continue continue
# set new value # set new value
index[bid] = json_to_list(bundle_combine.get_evaluated(bid)) index[bid] = json_to_list(bundle_combine.get_evaluated(bid))
# sum of counts # sum of counts
try_del(index, ['_sum']) mylib.try_del(index, ['_sum'])
total = [0, 0] total = [0, 0]
for val in index.values(): for val in index.values():
total[0] += val[0] total[0] += val[0]
@@ -79,7 +71,7 @@ def write_summary_index(index, bundle_ids, deleteOnly=False):
def write_rank_index(index): def write_rank_index(index):
try_del(index, ['_sum', '_ranks', '_min', '_max']) mylib.try_del(index, ['_sum', '_ranks', '_min', '_max'])
mins = [] mins = []
maxs = [] maxs = []
if len(index) > 0: if len(index) > 0: