From 724d7ab319fe80cb98df41034b989d4ad8ec910c Mon Sep 17 00:00:00 2001 From: relikd Date: Sat, 5 Sep 2020 23:30:37 +0200 Subject: [PATCH] Fix key error + log exceptions to error.log --- api/v1/contribute/index.php | 2 +- src/bundle_combine.py | 6 ++--- src/common_lib.py | 3 +++ src/main.py | 53 ++++++++++++++++++++++--------------- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/api/v1/contribute/index.php b/api/v1/contribute/index.php index f1a25d8..c597328 100644 --- a/api/v1/contribute/index.php +++ b/api/v1/contribute/index.php @@ -55,7 +55,7 @@ function make_output($msg, $url=null, $when=null, $key=null) { function response_success($bundle_id, $key) { $url = $bundle_id ? 'https://appchk.de/app/'.$bundle_id.'/index.html' : null; # next update will be in ... X seconds (up to 1 min) - make_output('ok', $url, ceil(time()/120)*120 - time(), $key); + make_output('ok', $url, ceil(time()/60)*60 - time(), $key); } function response_fail($error) { diff --git a/src/bundle_combine.py b/src/bundle_combine.py index b6ff3b2..b5f9193 100755 --- a/src/bundle_combine.py +++ b/src/bundle_combine.py @@ -34,14 +34,14 @@ def dict_increment(ddic, key, num): def json_combine(bundle_id): - res = dict() + res = dict({'#rec': 0, '#logs': 0}) domA = dict() # unique sub domains domB = dict() # total sub domains domC = dict() # unique parent domains domD = dict() # total parent domains for fname, jdata in mylib.enum_jsons(bundle_id): res['name'] = jdata['app-name'] - dict_increment(res, '#rec', 1) + res['#rec'] += 1 dict_increment(res, 'rec-total', jdata['duration']) try: logs = jdata['logs'] @@ -49,7 +49,7 @@ def json_combine(bundle_id): for subdomain in logs: occurs = len(logs[subdomain]) sub_tracker = tracker.is_tracker(subdomain) - dict_increment(res, '#logs', occurs) + res['#logs'] += 1 dict_increment(domA, subdomain, 1) dict_increment(domB, subdomain, occurs) par_dom = get_parent_domain(subdomain) diff --git a/src/common_lib.py b/src/common_lib.py index 94f2f43..261c864 100755 --- a/src/common_lib.py +++ b/src/common_lib.py @@ -6,6 +6,7 @@ import glob import json import shutil import logging +import traceback from pathlib import Path import urllib.request as curl @@ -77,6 +78,8 @@ def valid_bundle_id(bundle_id): def err(scope, msg, logOnly=False): + if isinstance(msg, Exception): + msg = traceback.format_exc() logger.error('[{}] {}'.format(scope, msg)) if not logOnly: print(' [ERROR] ' + msg) diff --git a/src/main.py b/src/main.py index 0fb0552..c32c37d 100755 --- a/src/main.py +++ b/src/main.py @@ -24,14 +24,20 @@ def print_usage_and_exit(): def del_id(bundle_ids): + print('removing apps from website:') if bundle_ids == ['*']: bundle_ids = list(mylib.enum_appids()) + update_index = False for bid in bundle_ids: dest = mylib.path_out_app(bid) if mylib.dir_exists(dest): + print(' ' + bid) mylib.rm(dest) - html_index.process() + update_index = True + print('') + if update_index: + html_index.process() def combine_and_update(bundle_ids, where=None, forceGraphs=False): @@ -70,25 +76,28 @@ def tracker_update(): combine_and_update(['*'], where=new_trackers) -if __name__ == '__main__': - args = sys.argv[1:] - if len(args) == 0: - print_usage_and_exit() - cmd = args[0] - params = args[1:] - if cmd == 'import': - import_update() - elif cmd == 'del': - if len(params) == 0: +try: + if __name__ == '__main__': + args = sys.argv[1:] + if len(args) == 0: print_usage_and_exit() - del_id(params) # ['_manually'] - elif cmd == 'run': - if len(params) == 0: - print_usage_and_exit() - combine_and_update(params) # ['*'], where=['test.com'] - elif cmd == 'icons': - if bundle_download.download_missing_icons(force=False): - html_index.process() - elif cmd == 'tracker': - tracker_update() - # tracker_download.combine_all('x') + cmd = args[0] + params = args[1:] + if cmd == 'import': + import_update() + elif cmd == 'del': + if len(params) == 0: + print_usage_and_exit() + del_id(params) # ['_manually'] + elif cmd == 'run': + if len(params) == 0: + print_usage_and_exit() + combine_and_update(params) # ['*'], where=['test.com'] + elif cmd == 'icons': + if bundle_download.download_missing_icons(force=False): + html_index.process() + elif cmd == 'tracker': + tracker_update() + # tracker_download.combine_all('x') +except Exception as e: + mylib.err('critical', e)