#!/usr/bin/env python3 import sys import common_lib as mylib import lib_graphs as Graph import lib_html as HTML import bundle_combine # get_evaluated, fname_evaluated import index_app_names # get_name import index_categories # get_categories def trkr_if(flag): return ' class="trckr"' if flag else '' def domain_w_count(domain, count): if count > 1: return '{} ({})'.format(domain, count) return domain def gen_dom_tags(sorted_arr, fn_a_html, onlyTrackers=False): src = '' anyMark = False for name, count, mark in sorted_arr: anyMark |= mark src += fn_a_html(name, domain_w_count(name, count), attr_str=trkr_if(mark and not onlyTrackers)) + ' ' if src: if anyMark: src += '
* Potential trackers are highlighted
' clss = ' trckr' if onlyTrackers else '' return f'' else: return '– None –' def gen_dotgraph(arr): return Graph.dotgraph([(domain_w_count(title, num), num, trkr_if(f)) for title, num, f in arr]) def stat(col, title, ident, value, optional=None): return Graph.rank_tile(title, value, optional, { 'id': ident, 'class': 'col' + str(col)}) def gen_page(bundle_id, obj): def round_num(num): return format(num, '.1f') # .rstrip('0').rstrip('.') def as_pm(value): return round_num(value) + '/min' def as_percent(value): return round_num(value * 100) + '%' def seconds_to_time(seconds): seconds = int(seconds) minutes, seconds = divmod(seconds, 60) hours, minutes = divmod(minutes, 60) return '{:02d}:{:02d}:{:02d}'.format(hours, minutes, seconds) name = index_app_names.get_name(bundle_id) gernes = index_categories.get_categories(bundle_id) obj['tracker'] = list(filter(lambda x: x[2], obj['subdom'])) HTML.write(mylib.path_out_app(bundle_id), f'''Bundle-id:{ bundle_id }
| App Categories: | { ', '.join([HTML.a_category(i, name) for i, name in gernes]) } |
| Last Update: | {HTML.date_utc(obj['last_date'])} |
Download: json
''', title=name) def process(bundle_ids): print('generating html: apps ...') i = 0 for bid in mylib.appids_in_out(bundle_ids): gen_page(bid, bundle_combine.get_evaluated(bid)) mylib.symlink(bundle_combine.fname_evaluated(bid), mylib.path_out_app(bid, 'data.json')) mylib.printf(' .' if i == 0 else '.') i = (i + 1) % 50 if i == 0: print('') # close printf print('') # close printf print('') if __name__ == '__main__': args = sys.argv[1:] if len(args) > 0: process(args) else: # process(['*']) mylib.usage(__file__, '[bundle_id] [...]')