Skip to content

Instantly share code, notes, and snippets.

Created Apr 16, 2014

What would you like to do?
listener from tor-weather
A module for listening to Tor for new consensus events. When one occurs,
initializes the checker/updater cascade in the updaters module.
import logging
from config import config
from weatherapp import updaters
from stem.control import EventType, Controller
import time
#very basic log setup
logging.basicConfig(format = '%(asctime) - 15s (%(process)d) %(message)s',
level = logging.DEBUG, filename = 'log/weather.log')
def newconsensus_listener(event):
Call C{updaters.run_all()} when a NEWCONSENSUS event is received.
@param event: The NEWCONSENSUS event. Not used by the function.
"""'Got a new consensus. Updating router table and ' + \
'checking all subscriptions.')
def listen():
"""Sets up a connection to Tor and initializes a controller to listen for
new consensus events.
ctrl = Controller.from_port(port = config.control_port)
ctrl.add_event_listener(newconsensus_listener, EventType.NEWCONSENSUS)
print 'Listening for new consensus events.''Listening for new consensus events.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.