This commit is contained in:
Rémi Oudin 2018-02-26 17:12:19 +01:00
parent 7c8ec7351c
commit dedc66bb9d
2 changed files with 17 additions and 10 deletions

View file

@ -5,6 +5,7 @@ interests, keywords...
from collections import namedtuple from collections import namedtuple
import random import random
import asyncio
from math import floor from math import floor
from xml.etree import ElementTree as ET from xml.etree import ElementTree as ET
from datetime import datetime from datetime import datetime
@ -107,15 +108,18 @@ class History(models.Model):
output += str(entry) + '\n' output += str(entry) + '\n'
return output return output
async def play_histories(self): async def _handler(self):
runner = await TorInstance.create(self.return_history(), self.user.browser_fingerprint.serialize_headers())
await runner.run()
self.played = True
self.save()
def play_histories(self):
""" Actually plays the history. """ Actually plays the history.
""" """
self.played = True loop = asyncio.new_event_loop()
runner = await TorInstance.create( asyncio.set_event_loop(loop)
self.return_history(), loop.run_until_complete(asyncio.wait([self._handler()]))
self.user.browser_fingerprint.serialize_headers())
runner.run()
self.save()
def to_xml(self, xml_root=None): def to_xml(self, xml_root=None):
''' Exports the current history to xml ''' ''' Exports the current history to xml '''

View file

@ -58,7 +58,9 @@ class TorInstance():
async def run(self): async def run(self):
""" Runs the Tor Instance on the history. """ Runs the Tor Instance on the history.
""" """
while (self.history[0][1] - dt.datetime.now()).total_seconds >= 10: while (self.history) and (dt.datetime.combine(self.history[0][1],
dt.datetime.min.time()) -
dt.datetime.now()).total_seconds() >= 10:
print("Sleeping") print("Sleeping")
sleep(10) sleep(10)
while self.history: while self.history:
@ -66,8 +68,9 @@ class TorInstance():
async with async_timeout.timeout(30): async with async_timeout.timeout(30):
await(self.query(item[0])) await(self.query(item[0]))
now = dt.datetime.now() now = dt.datetime.now()
if now <= self.history[0][1]: print(self.history[0])
sleep((self.history[0][1] - now).total_seconds()) if now <= dt.datetime.combine(self.history[0][1], dt.datetime.min.time()):
sleep((dt.datetime.combine(self.history[0][1], dt.datetime.min.time()) - now).total_seconds())
def create_session(self): def create_session(self):