def create_url_from_config(config): url = '{protocol}://{user}:{password}@{host}/{database}{encoding}' encoding = '?charset=utf8' if tim_commons.to_bool(config['unicode']) else '' return url.format( protocol='mysql', encoding=encoding, **config)
def app_main(self, config, options, args): # TODO: deal with new user registrations by listening to amqp and schedule the rest observer = PythonLoggingObserver() observer.start() # initialize some important maps db.configure_session(db.create_url_from_config(config['db'])) service.initialize() post_type.initialize() # Grab twitter consumer keys self.consumer_key = config['oauth']['twitter']['key'] self.consumer_secret = config['oauth']['twitter']['secret'] self.default_token_key = config['oauth']['twitter']['default_access_token'] self.default_token_secret = config['oauth']['twitter']['default_access_token_secret'] # Grab feed configuration self.wait_on_collector_query_delay = float(config['feed']['wait_on_collector_query_delay']) # Configure amqp amqp_host = config['amqp']['broker']['host'] amqp_port = int(config['amqp']['broker']['port']) amqp_spec = message_queue.create_spec_path(config['amqp']['broker']['spec']) self.amqp_exchange = config['amqp']['exchange']['name'] self.amqp = AmqpFactory(host=amqp_host, port=amqp_port, spec_file=amqp_spec) db_host = config['db']['host'] db_user = config['db']['user'] db_passwd = config['db']['password'] db_database = config['db']['database'] db_unicode = to_bool(config['db']['unicode']) self.db_pool = adbapi.ConnectionPool( 'MySQLdb', host=db_host, user=db_user, passwd=db_passwd, db=db_database, use_unicode=db_unicode, cp_noisy=True) self._process_twitter_users() reactor.run()