diff options
author | Jordan <me@jordan.im> | 2024-05-20 21:02:19 -0700 |
---|---|---|
committer | Jordan <me@jordan.im> | 2024-05-20 21:02:19 -0700 |
commit | 79205ebcf9f086e0760024eb1789dd91ad6b3902 (patch) | |
tree | 1f63dddf3e3b43ef5a45ca28ab29f90a30a374c8 /allium/allium.py | |
parent | de188cb69927d13811a1be2e201f6be59f1a177d (diff) | |
download | allium-master.tar.gz allium-master.zip |
Diffstat (limited to 'allium/allium.py')
-rwxr-xr-x | allium/allium.py | 88 |
1 files changed, 52 insertions, 36 deletions
diff --git a/allium/allium.py b/allium/allium.py index 533eb66..05258db 100755 --- a/allium/allium.py +++ b/allium/allium.py @@ -1,13 +1,13 @@ #!/usr/bin/env python3 -''' +""" File: allium.py (executable) Generate complete set of relay HTML pages and copy static files to the output_dir Default output directory: ./www -''' +""" import argparse import os @@ -17,18 +17,28 @@ from lib.relays import Relays ABS_PATH = os.path.dirname(os.path.abspath(__file__)) -if __name__ == '__main__': - desc = 'allium: generate static tor relay metrics and statistics' +if __name__ == "__main__": + desc = "allium: generate static tor relay metrics and statistics" parser = argparse.ArgumentParser(description=desc) - parser.add_argument('--out', dest='output_dir', type=str, - default="./www", - help='directory to store rendered files (default "./www")', - required=False) - parser.add_argument('--onionoo-url', dest='onionoo_url', type=str, - default="https://onionoo.torproject.org/details", - help='onionoo HTTP URL (default '\ - '"https://onionoo.torproject.org/details")', - required=False) + parser.add_argument( + "--out", + dest="output_dir", + type=str, + default="./www", + help='directory to store rendered files (default "./www")', + required=False, + ) + parser.add_argument( + "--onionoo-url", + dest="onionoo_url", + type=str, + default="https://onionoo.torproject.org/details", + help=( + "onionoo HTTP URL (default " + '"https://onionoo.torproject.org/details")' + ), + required=False, + ) args = parser.parse_args() # object containing onionoo data and processing routines @@ -40,40 +50,44 @@ if __name__ == '__main__': # index and "all" HTML relay sets; index set limited to 500 relays RELAY_SET.write_misc( - template = 'index.html', - path = 'index.html', - path_prefix = './', - is_index = True, - ) - RELAY_SET.write_misc( - template = 'all.html', - path = 'misc/all.html' + template="index.html", + path="index.html", + path_prefix="./", + is_index=True, ) + RELAY_SET.write_misc(template="all.html", path="misc/all.html") # miscellaneous page filename suffixes and sorted-by keys misc_pages = { - 'by-bandwidth': '1.bandwidth', - 'by-exit-count': '1.exit_count,1.bandwidth', - 'by-middle-count': '1.middle_count,1.bandwidth', - 'by-first-seen': '1.first_seen,1.bandwidth' + "by-bandwidth": "1.bandwidth", + "by-exit-count": "1.exit_count,1.bandwidth", + "by-middle-count": "1.middle_count,1.bandwidth", + "by-first-seen": "1.first_seen,1.bandwidth", } # miscellaneous-sorted (per misc_pages k/v) HTML pages for k, v in misc_pages.items(): RELAY_SET.write_misc( - template = 'misc-families.html', - path = 'misc/families-{}.html'.format(k), - sorted_by = v + template="misc-families.html", + path="misc/families-{}.html".format(k), + sorted_by=v, ) RELAY_SET.write_misc( - template = 'misc-networks.html', - path = 'misc/networks-{}.html'.format(k), - sorted_by = v + template="misc-networks.html", + path="misc/networks-{}.html".format(k), + sorted_by=v, ) # onionoo keys used to generate pages by unique value; e.g. AS43350 - keys = ['as', 'contact', 'country', 'family', 'flag', 'platform', - 'first_seen'] + keys = [ + "as", + "contact", + "country", + "family", + "flag", + "platform", + "first_seen", + ] for k in keys: RELAY_SET.write_pages_by_key(k) @@ -82,6 +96,8 @@ if __name__ == '__main__': RELAY_SET.write_relay_info() # copy static directory and its contents if it doesn't exist - if not os.path.exists(os.path.join(args.output_dir, 'static')): - copytree(os.path.join(ABS_PATH, 'static'), - os.path.join(args.output_dir, 'static')) + if not os.path.exists(os.path.join(args.output_dir, "static")): + copytree( + os.path.join(ABS_PATH, "static"), + os.path.join(args.output_dir, "static"), + ) |