aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan <me@jordan.im>2019-06-26 21:52:09 -0700
committerJordan <me@jordan.im>2019-06-26 21:52:09 -0700
commit279721eb9df87672213ba8ae1856698efc5d3d5f (patch)
tree813b05d34d93a8d7a559df9e91706c99106a9ee6
parent18648ffc8aa6e5a561358fc822cde752dc593cea (diff)
downloadallium-279721eb9df87672213ba8ae1856698efc5d3d5f.tar.gz
allium-279721eb9df87672213ba8ae1856698efc5d3d5f.zip
general cleanup, rm write()
-rwxr-xr-xtor-metrics/generate.py36
-rw-r--r--tor-metrics/templates/base.html8
-rw-r--r--tor-metrics/templates/effective_family.html6
3 files changed, 27 insertions, 23 deletions
diff --git a/tor-metrics/generate.py b/tor-metrics/generate.py
index b6b2b3c..3235bd0 100755
--- a/tor-metrics/generate.py
+++ b/tor-metrics/generate.py
@@ -27,8 +27,8 @@ def unsorted(relays, filename, is_index):
template = env.get_template(filename)
template_render = template.render(relays=relays, is_index=is_index)
output = os.path.join(config.CONFIG['output_root'], filename)
- with open(output, 'w', encoding='utf8') as out:
- out.write(template_render)
+ with open(output, 'w', encoding='utf8') as html:
+ html.write(template_render)
def effective_family(relays):
template = env.get_template('effective_family.html')
@@ -48,8 +48,15 @@ def effective_family(relays):
if fingerprint in p_relay['effective_family']:
members.append(p_relay)
bandwidth += p_relay['observed_bandwidth']
- write(output_path, members, bandwidth, template, fingerprint,
- category='family')
+ dir_path = os.path.join(output_path, fingerprint)
+ os.makedirs(dir_path)
+ f_bandwidth = round(bandwidth / 1000000, 2) # convert to MB/s
+ rendered = template.render(relays=members, bandwidth=f_bandwidth,
+ is_index=False, path_prefix='../../', deactivate='family',
+ family=fingerprint)
+ with open(os.path.join(dir_path, 'index.html'), 'w',
+ encoding='utf8') as html:
+ html.write(rendered)
def pages_by_key(relays, key):
template = env.get_template(key + '.html')
@@ -68,18 +75,15 @@ def pages_by_key(relays, key):
if p_relay.get(key) and p_relay[key] == relay[key]:
found_relays.append(p_relay)
bandwidth += p_relay['observed_bandwidth']
- write(output_path, found_relays, bandwidth, template, relay[key])
-
-def write(parent_dir, relays, bandwidth, template, key, category=None):
- dir_path = os.path.join(parent_dir, key)
- os.makedirs(dir_path)
- f_bandwidth = round(bandwidth / 1000000, 2) # convert to MB/s
- rendered = template.render(relays=relays, bandwidth=f_bandwidth,
- focused=key, is_index=False, category=category, path_prefix='../../',
- special_countries=countries.the_prefixed)
- with open(os.path.join(dir_path, 'index.html'), 'w', encoding='utf8') as html:
- html.write(rendered)
-
+ dir_path = os.path.join(output_path, relay[key])
+ os.makedirs(dir_path)
+ f_bandwidth = round(bandwidth / 1000000, 2) # convert to MB/s
+ rendered = template.render(relays=found_relays,
+ bandwidth=f_bandwidth, is_index=False, path_prefix='../../',
+ deactivate=key, special_countries=countries.the_prefixed)
+ with open(os.path.join(dir_path, 'index.html'), 'w',
+ encoding='utf8') as html:
+ html.write(rendered)
relays = Relays()
generate_html(relays)
diff --git a/tor-metrics/templates/base.html b/tor-metrics/templates/base.html
index 4f75ab1..95ef872 100644
--- a/tor-metrics/templates/base.html
+++ b/tor-metrics/templates/base.html
@@ -36,14 +36,14 @@
{% else %}
{% set obs_bandwidth = '%s %s'|format((relay['observed_bandwidth'] / 1000)|round(2, 'common'), 'KB/s') %}{% endif %}
- {% if category != 'family' and relay['effective_family']|length > 1 %}
+ {% if deactivate != 'family' and relay['effective_family']|length > 1 %}
<td>{{ relay['nickname'] }} (<a href="{{ path_prefix }}family/{{ relay['effective_family'][0] }}/">{{ relay['effective_family']|length }}</a>)</td>
{% else %}
<td>{{ relay['nickname'] }}</td>{% endif %}
<td>{{ obs_bandwidth }}</td>
<td class="visible-md visible-lg">{{ relay['or_addresses'][0].split(':', 1)[0] }}</td>
- {% if relay['as'] %}{% if focused != 'as' %}
+ {% if relay['as'] %}{% if deactivate != 'as' %}
<td><a href="{{ path_prefix }}as/{{ relay['as'] }}/">{{ relay['as'] }}</a></td>
{% else %}
<td>{{ relay['as'] }}</td>{% endif %}
@@ -55,14 +55,14 @@
{% else %}
<td>Unknown</td>{% endif %}
- {% if relay['country'] %}{% if focused != 'country' %}
+ {% if relay['country'] %}{% if deactivate != 'country' %}
<td><a href="{{ path_prefix }}country/{{ relay['country'] }}/"><img src="{{ path_prefix }}static/images/cc/{{ relay['country'] }}.png" title="{{ relay['country_name'] }}" alt="{{ relay['country_name'] }}"></a></td>
{% else %}
<td><img src="{{ path_prefix }}static/images/cc/{{ relay['country'] }}.png" title="{{ relay['country_name'] }}" alt="{{ relay['country_name'] }}"></td>{% endif %}
{% else %}
<td>X</td>{% endif %}
- {% if focused != 'platform' %}
+ {% if deactivate != 'platform' %}
<td><a href="{{ path_prefix }}platform/{{ relay['platform'] }}/">{{ relay['platform'] }}</a></td>
{% else %}
<td>{{ relay['platform'] }}</td>{% endif %}
diff --git a/tor-metrics/templates/effective_family.html b/tor-metrics/templates/effective_family.html
index 1acec41..fec8609 100644
--- a/tor-metrics/templates/effective_family.html
+++ b/tor-metrics/templates/effective_family.html
@@ -1,4 +1,4 @@
{% extends "base.html" %}
-{% block title %}Tor Relays :: Family {{ focused }}{% endblock %}
-{% block header %}<a href="../../">Home</a> :: Family {{ focused }}{% endblock %}
-{% block description %}Relays with effective family member {{ focused }} are responsible for ~{{ bandwidth }} MB/s of traffic.{% endblock %}
+{% block title %}Tor Relays :: Family {{ family }}{% endblock %}
+{% block header %}<a href="../../">Home</a> :: Family {{ family }}{% endblock %}
+{% block description %}Relays with effective family member {{ family }} are responsible for ~{{ bandwidth }} MB/s of traffic.{% endblock %}