def __init__(self, auth, listener, **options): self.auth = auth self.listener = listener self.running = False self.config = tweetsclient.Config().get() self.client_id = options.get('client_id', None) self.client_secret = options.get("client_secret", None) logging.info(u"client id/secret is: {0}/{1}", self.client_id, self.client_secret) if self.client_id and self.client_secret: self.expired = 3600 else: self.expired = None #self.timeout = options.get('timeout') #self.retry_count = options.get("retry_count") # values according to https://dev.twitter.com/docs/streaming-apis/connecting#Reconnecting self.retry_time_start = options.get("retry_time", 90) #self.retry_420_start = options.get("retry_420", 60.0) self.retry_time_cap = options.get("retry_time_cap", 320.0) self.snooze_time_step = options.get("snooze_time", 0.25) self.snooze_time_cap = options.get("snooze_time_cap", 16) self.buffer_size = options.get("buffer_size", 1500) #self.api = API() #self.session = requests.Session() #self.session.headers = options.get("headers") or {} #self.session.params = None self.body = None self.retry_time = self.retry_time_start self.snooze_time = self.snooze_time_step
def __init__(self, heart): super(TweetEntityWorker, self).__init__() self.heart = heart self.config = tweetsclient.Config().get() self.db_connect_params = { 'host': self.config.get('database', 'host'), 'port': int(self.config.get('database', 'port')), 'db': self.config.get('database', 'database'), 'user': self.config.get('database', 'username'), 'passwd': self.config.get('database', 'password'), 'charset': "utf8mb4", 'use_unicode': True }
def __init__(self, queue, *args, **kwargs): super(TweetListener, self).__init__(*args, **kwargs) self.queue = queue self.config = tweetsclient.Config().get() self.database = MySQLdb.connect( host=self.config.get('database', 'host'), port=int(self.config.get('database', 'port')), db=self.config.get('database', 'database'), user=self.config.get('database', 'username'), passwd=self.config.get('database', 'password'), charset="utf8mb4", use_unicode=True) self.database.autocommit(True) # needed if you're using InnoDB self.database.cursor().execute('SET NAMES UTF8MB4') self.users = self.get_users()
def __init__(self): self.config = tweetsclient.Config().get() consumer_key = self.config.get('tweets-client', 'consumer_key') consumer_secret = self.config.get('tweets-client', 'consumer_secret') access_token = self.config.get('tweets-client', 'access_token') access_token_secret = self.config.get('tweets-client', 'access_token_secret') log.debug("Consumer credentials: {key}, {secret}", key=consumer_key, secret=consumer_secret) log.debug("Access credentials: {token}, {secret}", token=access_token, secret=access_token_secret) self.twitter_auth = tweepy.OAuthHandler(consumer_key, consumer_secret) self.twitter_auth.set_access_token(access_token, access_token_secret) try: username = self.twitter_auth.get_username() log.notice("Authenticated as {user}".format(user=username)) except tweepy.error.TweepError as e: log.error(e)
def __init__(self): self.last_beat = datetime.datetime.now() config = tweetsclient.Config().get() try: self.interval = datetime.timedelta(seconds=float( config.get('tweets-client', 'heartbeat_interval'))) except: logbook.warning( "No heartbeat_interval configuration parameter, skipping heartbeat." ) raise StopIteration try: directory = config.get('tweets-client', 'heartbeats_directory') except: logbook.warning( "No heartbeats_directory configuration parameter, skipping heartbeat." ) raise StopIteration if not os.path.isdir(directory): logbook.warning( "The heartbeats_directory parameter ({0}) is not a directory.", directory) raise StopIteration scriptname = os.path.basename(sys.argv[0]) self.filepath = os.path.join(directory, scriptname) start_time = datetime.datetime.now().isoformat() self.pid = os.getpid() with file(self.filepath, 'w') as fil: fil.write( anyjson.serialize({ 'pid': self.pid, 'started': start_time }))
def get_config(self): log.debug("Reading config ...") self.config = tweetsclient.Config().get()
import ConfigParser import pytz import datetime smtpconfig = ConfigParser.ConfigParser() smtpconfig.read('conf/tweets-client.ini') smtp = smtplib.SMTP(smtpconfig.get('moderation-alerts', 'mail_host'), smtpconfig.get('moderation-alerts', 'mail_port')) smtp.login(smtpconfig.get('moderation-alerts', 'mail_username'), smtpconfig.get('moderation-alerts', 'mail_password')) recipient = smtpconfig.get('moderation-alerts', 'unmoderated_recipient') sender = smtpconfig.get('moderation-alerts', 'sender') max_tweets = smtpconfig.getint('moderation-alerts', 'max_tweets') config = tweetsclient.Config().get() conn = MySQLdb.connect(host=config.get('database', 'host'), port=int(config.get('database', 'port')), db=config.get('database', 'database'), user=config.get('database', 'username'), passwd=config.get('database', 'password'), charset="utf8mb4", use_unicode=True) cur = conn.cursor() cur.execute("""SELECT * FROM `deleted_tweets` WHERE reviewed=0 """) tweets = cur.fetchall() unmoderated = len(tweets) if unmoderated > max_tweets: tz = pytz.timezone(unicode('US/Eastern')) dtnow = datetime.datetime.now(tz)
def __init__(self): self.config = tweetsclient.Config().get() self.user = self.config.get('tweets-client', 'username') self.passwd = self.config.get('tweets-client', 'password')
def __init__(self, options={}): self.options = options # get config self.config = tweetsclient.Config().get()
def __init__(self): self.config = tweetsclient.Config().get() """