<commit_before>#!/usr/bin/env python

import json
import operator

from os import listdir
from dateutil.parser import parse
from dateutil.tz import tzlocal
from datetime import datetime
from math import floor

from stem.descriptor import parse_file
from stem.exit_policy import AddressType


class Router():
    def __init__(self, router, tminus):
        self.Fingerprint = router.fingerprint
        self.Address = router.address
        self.IsAllowedDefault = router.exit_policy._is_allowed_default
        self.Rules = []
        self.Tminus = tminus


def get_hours(td):
    try:
        s = td.total_seconds()
    catch AttributeError:
        # workaround for py2.6
        s = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 1e6) / 1e6
    return int(floor(s / 3600))


exits = {}
now = datetime.now(tzlocal())
consensuses = listdir("data/consensuses")
consensuses.sort(reverse=True)
exit_lists = listdir("data/exit-lists")

for f in consensuses:

    # strip -consensus
    d = f[:-10]

    # consensus from t hours ago
    t = get_hours(now - parse(d))

    # read in consensus and store routes in exits<commit_msg>except<commit_after>#!/usr/bin/env python

import json
import operator

from os import listdir
from dateutil.parser import parse
from dateutil.tz import tzlocal
from datetime import datetime
from math import floor

from stem.descriptor import parse_file
from stem.exit_policy import AddressType


class Router():
    def __init__(self, router, tminus):
        self.Fingerprint = router.fingerprint
        self.Address = router.address
        self.IsAllowedDefault = router.exit_policy._is_allowed_default
        self.Rules = []
        self.Tminus = tminus


def get_hours(td):
    try:
        s = td.total_seconds()
    except AttributeError:
        # workaround for py2.6
        s = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 1e6) / 1e6
    return int(floor(s / 3600))


exits = {}
now = datetime.now(tzlocal())
consensuses = listdir("data/consensuses")
consensuses.sort(reverse=True)
exit_lists = listdir("data/exit-lists")

for f in consensuses:

    # strip -consensus
    d = f[:-10]

    # consensus from t hours ago
    t = get_hours(now - parse(d))

    # read in consensus and store routes in exits
{'fraction_non_alphanumeric': 0.09549071618037135, 'fraction_numerical': 0.015915119363395226, 'mean_word_length': 3.152293577981651, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '306593', 'n_tokens_mistral': 747, 'n_tokens_neox': 698, 'n_words': 203}