aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan <me@jordan.im>2020-05-16 13:43:29 -0700
committerJordan <me@jordan.im>2020-05-16 13:43:29 -0700
commite6f230d7afb0da982e392966cfb5a42c77f948f2 (patch)
treea534c9529813aacfdb395b8acce288c1d410b6b8
parente83d51740ef94d7eca890fa7d3cf8a22d567a4d9 (diff)
downloadallium-e6f230d7afb0da982e392966cfb5a42c77f948f2.tar.gz
allium-e6f230d7afb0da982e392966cfb5a42c77f948f2.zip
move generate_html() function calls to main()
-rwxr-xr-xtor-metrics/generate.py41
1 files changed, 17 insertions, 24 deletions
diff --git a/tor-metrics/generate.py b/tor-metrics/generate.py
index ce3fa2a..21263a2 100755
--- a/tor-metrics/generate.py
+++ b/tor-metrics/generate.py
@@ -21,29 +21,6 @@ ABS_PATH = os.path.dirname(os.path.abspath(__file__))
ENV = Environment(loader=FileSystemLoader(os.path.join(ABS_PATH, 'templates')),
trim_blocks=True, lstrip_blocks=True)
-def generate_html(relays):
- '''
- Render and write complete set of relay pages to disk by calling each group's
- respective function
-
- Files are written to 'www' by default (defined in config.py)
-
- :relays: relays class object containing relay set (list of dict)
- '''
- sort_relays(relays)
- pages_by_key(relays, 'as')
- pages_by_key(relays, 'country')
- pages_by_key(relays, 'platform')
- pages_by_flag(relays)
- effective_family(relays)
- unsorted(relays, 'index.html', is_index=True)
- unsorted(relays, 'all.html', is_index=False)
- relay_info(relays)
- static_src_path = os.path.join(ABS_PATH, 'static')
- static_dest_path = os.path.join(config.CONFIG['output_root'], 'static')
- if not os.path.exists(static_dest_path):
- copytree(static_src_path, static_dest_path)
-
def sort_relays(relays):
'''
Add a list of dict sorted by unique keys derived from relays as they're
@@ -256,6 +233,7 @@ def relay_info(relays):
html.write(rendered)
if __name__ == '__main__':
+ # make request to onionoo, populate relays object
try:
RELAY_SET = Relays()
except Exception as err:
@@ -263,4 +241,19 @@ if __name__ == '__main__':
print(err)
sys.exit()
- generate_html(RELAY_SET)
+ # generate relay HTML documents
+ sort_relays(RELAY_SET)
+ pages_by_key(RELAY_SET, 'as')
+ pages_by_key(RELAY_SET, 'country')
+ pages_by_key(RELAY_SET, 'platform')
+ pages_by_flag(RELAY_SET)
+ effective_family(RELAY_SET)
+ unsorted(RELAY_SET, 'index.html', is_index=True)
+ unsorted(RELAY_SET, 'all.html', is_index=False)
+ relay_info(RELAY_SET)
+
+ # copy static directory and its contents
+ static_src_path = os.path.join(ABS_PATH, 'static')
+ static_dest_path = os.path.join(config.CONFIG['output_root'], 'static')
+ if not os.path.exists(static_dest_path):
+ copytree(static_src_path, static_dest_path)