From f66c978466d9173baf6a8dac77b23dfaba74d362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Oudin?= Date: Sun, 25 Feb 2018 21:53:28 +0100 Subject: [PATCH] Tor runner has a run function to replay the history --- histories/tor_runner.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/histories/tor_runner.py b/histories/tor_runner.py index 0ac3e00..ca7b06f 100644 --- a/histories/tor_runner.py +++ b/histories/tor_runner.py @@ -6,6 +6,7 @@ import shutil import asyncio import aiohttp from aiosocks.connector import ProxyConnector, ProxyClientRequest +from time import sleep import async_timeout import stem.process as tor @@ -51,6 +52,19 @@ class TorInstance(): self.session = None self.process = None + def run(self): + """ Runs the Tor Instance on the history. + """ + t_start = time.now() + while history: + item = history.pop(0) + async with async_timeout.timeout(30): + await(self.query(item[0])) + t_end = time.now() + diff = (history[0][1] - item[0]) - (t_end - t_start) + if diff > 0 + sleep(diff) + def create_session(self): """ Create a aiohttp session.