From 7edf470684cb87bd34b34f593694904769641fbf Mon Sep 17 00:00:00 2001 From: relikd Date: Mon, 21 Sep 2020 15:15:40 +0200 Subject: [PATCH] mylib.try_del --- src/common_lib.py | 10 +++++++++- src/download_itunes.py | 8 ++------ src/index_meta.py | 14 +++----------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/common_lib.py b/src/common_lib.py index c0c7807..6d3ebf2 100755 --- a/src/common_lib.py +++ b/src/common_lib.py @@ -259,7 +259,15 @@ def enum_data_appids(): 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): with open(path, 'r') as fp: diff --git a/src/download_itunes.py b/src/download_itunes.py index fa37097..fb2698d 100755 --- a/src/download_itunes.py +++ b/src/download_itunes.py @@ -48,12 +48,8 @@ def download_info(bundle_id, lang, force=False): json = mylib.download(url, isJSON=True) json = json['results'][0] # delete unused keys to save on storage - for key in ['supportedDevices', 'releaseNotes', 'description', - 'screenshotUrls', 'ipadScreenshotUrls']: - try: - del(json[key]) - except KeyError: - continue + mylib.try_del(json, ['supportedDevices', 'releaseNotes', 'description', + 'screenshotUrls', 'ipadScreenshotUrls']) mylib.json_write(fname, json, pretty=True) diff --git a/src/index_meta.py b/src/index_meta.py index dfb9cb0..3de5da6 100755 --- a/src/index_meta.py +++ b/src/index_meta.py @@ -19,14 +19,6 @@ def load_json_from_disk(fname): 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): return [ json['sum_rec'], @@ -62,14 +54,14 @@ def list_to_json(list): def write_summary_index(index, bundle_ids, deleteOnly=False): for bid in bundle_ids: # delete old value - try_del(index, [bid]) + mylib.try_del(index, [bid]) if deleteOnly: continue # set new value index[bid] = json_to_list(bundle_combine.get_evaluated(bid)) # sum of counts - try_del(index, ['_sum']) + mylib.try_del(index, ['_sum']) total = [0, 0] for val in index.values(): total[0] += val[0] @@ -79,7 +71,7 @@ def write_summary_index(index, bundle_ids, deleteOnly=False): def write_rank_index(index): - try_del(index, ['_sum', '_ranks', '_min', '_max']) + mylib.try_del(index, ['_sum', '_ranks', '_min', '_max']) mins = [] maxs = [] if len(index) > 0: