def authenticate(usr='******', pswd='0'): if usr == '0': usr = raw_input("twitter username: "******"password: ") auth = tweepy.BasicAuthHandler(usr, pswd) api = tweepy.API(auth) return api
def __init__(self, secondary_tag_list, u, p, savers): self.auth = tweepy.BasicAuthHandler(username=u, password=p) self.api = tweepy.API(auth_handler=self.auth, secure=True, retry_count=3) self.savers = savers secondary_tag_string = '#(' + '|'.join( map(lambda x: x[1:], secondary_tag_list)) + ')' self.prog = re.compile(secondary_tag_string, re.IGNORECASE)
def collect(settings): mailer = gmailer.Gmailer(settings.get('GMAIL_USER'), settings.get('GMAIL_PASSWORD')) message = "Starting collection at: %s, %s" % (datetime.datetime.now(), settings.get('APP_ID')) mailer.send_gmail(settings.get('OPS_EMAILS'), "Collection started: %s" % settings.get('APP_ID'), message) #Rotate files more frequently data_log_path = settings.get('DATA_DIRECTORY') + settings.get( 'DATA_LOG_NAME') app_log_path = settings.get('APP_LOG_DIRECTORY') + settings.get( 'APP_LOG_NAME') stream_listener = gatherer.TwitterStreamListener(data_log_path, app_log_path, 'M', 15) logger = logging.getLogger(gatherer.LoggingConfig.APP_LOG) logger.info(message) try: auth = tweepy.BasicAuthHandler(settings.get('TWITTER_USERNAME'), settings.get('TWITTER_PASSWORD')) stream = tweetstream.CompliantStream( auth, stream_listener, 5, stream_log_name=settings.get('STREAM_LOG_NAME')) stream.filter(track=settings.get('KEYWORDS')) # The exception handling is pretty heavy here. Issues happen infrequently, so any information # we can get is useful. except Exception as exception: trace = traceback.format_exc() message = "Keyword collection terminated at: %s reason: %s, %s" % ( datetime.datetime.now(), trace, settings.get('APP_ID')) logger.exception(message) mailer.send_gmail(settings.get('OPS_EMAILS'), 'Exception %s' % settings.get('APP_ID'), message) except: trace = traceback.format_exc() message = "Keyword collection terminated with empty exception at: %s reason: %s, %s " % ( datetime.datetime.now(), trace, settings.get('APP_ID')) logger.exception(message) mailer.send_gmail(settings.get('OPS_EMAILS'), 'Empty Exception: %s' % settings.get('APP_ID'), message) raise else: message = "Application terminated at: %s. No exception. %s" % ( datetime.datetime.now(), settings.get('APP_ID')) logger.error(message) mailer.send_gmail(settings.get('OPS_EMAILS'), 'No Exception: %s' % settings.get('APP_ID'), message)
def twitter_post(user, message): if not user.twitter_username or not user.twitter_password: return False basic_auth = tweepy.BasicAuthHandler(user.twitter_username, user.twitter_password) api = tweepy.API(basic_auth) update = api.update_status(message) print update.text return True
def twitter_post(user, message): try: tuser = TwitterUser.objects.get(user=user) except ObjectDoesNotExist: return False basic_auth = tweepy.BasicAuthHandler(tuser.username, tuser.password) api = tweepy.API(basic_auth) update = api.update_status(message) print update.text return True
def main(): auth = tweepy.BasicAuthHandler(username=settings.username, password=settings.password) api = tweepy.API(auth_handler=auth, secure=True, retry_count=3) last_id = get_last_id(settings.lastid) debug_print('Loading friends list') friends = api.friends_ids() debug_print('Friend list loaded, size: %d' % len(friends)) try: debug_print('Retrieving mentions') replies = api.mentions() except Exception, e: # quit on error here print e exit(1)
def test_account(self): """Load timeline if account exists""" self.timer.stop() if self.settings.contains("User") and self.settings.contains("use"): username = base64.b64decode(self.settings.value("User").toString()) password = base64.b64decode(self.settings.value("use").toString()) self.auth = tweepy.BasicAuthHandler(username, password) self.api = tweepy.API(self.auth) if not self.api.verify_credentials(): QtGui.QMessageBox.warning( self, 'Warning', "Could not authenticate twitter \ account", QtGui.QMessageBox.Ok) else: #Refresh static twitter timelines every 5 minutes. self.connect(self.timer, QtCore.SIGNAL("timeout()"), self.load_home_tweets) self.connect(self.timer, QtCore.SIGNAL("timeout()"), self.load_mentions_tweets) #Load timelines onces the mainwindow GUI is loaded. QtCore.QTimer.singleShot(0, self.load_home_tweets) QtCore.QTimer.singleShot(0, self.load_mentions_tweets) self.timer.start(300000)
def init_twitter(self, username, password): auth = tweepy.BasicAuthHandler(username, password) api = tweepy.API(auth) return api
def __init__(self, u, p): self.auth = tweepy.BasicAuthHandler(username=u, password=p) self.api = tweepy.API(auth_handler=self.auth, secure=True, retry_count=3) return
def main(argv): """main program - display list of images""" epd = EPD() epd.clear() print('panel = {p:s} {w:d} x {h:d} version={v:s}'.format(p=epd.panel, w=epd.width, h=epd.height, v=epd.version)) # initially set all white background image = Image.new('1', epd.size, WHITE) # prepare for drawing draw = ImageDraw.Draw(image) # set a longer timeout on socket operations socket.setdefaulttimeout(60) # find some fonts # fonts are in different places on Raspbian/Angstrom so search possible_name_fonts = [ # '/usr/share/fonts/truetype/freefont/FreeSans.ttf', # R.Pi '/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono-Bold.ttf', # R.Pi '/usr/share/fonts/truetype/freefont/FreeMono.ttf', # R.Pi '/usr/share/fonts/truetype/LiberationMono-Bold.ttf', # B.B '/usr/share/fonts/truetype/DejaVuSansMono-Bold.ttf' # B.B '/usr/share/fonts/TTF/DejaVuSansMono-Bold.ttf' # Arch ] possible_message_fonts = [ '/usr/share/fonts/truetype/droid/DroidSansFallbackFull.ttf', # R.Pi '/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf', # R.Pi '/usr/share/fonts/truetype/freefont/FreeMono.ttf', # R.Pi '/usr/share/fonts/truetype/LiberationSans-Regular.ttf', # B.B '/usr/share/fonts/truetype/DejaVuSans.ttf' # B.B '/usr/share/fonts/TTF/DejaVuSans.ttf' # Arch ] name_font_name = find_font(possible_name_fonts) if '' == name_font_name: raise 'no name font file found' message_font_name = find_font(possible_message_fonts) if '' == message_font_name: raise 'no message font file found' name_font = ImageFont.truetype(name_font_name, 14) message_font = ImageFont.truetype(message_font_name, 12) # start up tweepy streaming if tweepy_auth.basic: auth = tweepy.BasicAuthHandler(tweepy_auth.USERNAME, tweepy_auth.PASSWORD) else: auth = tweepy.OAuthHandler(tweepy_auth.CONSUMER_KEY, tweepy_auth.CONSUMER_SECRET) auth.set_access_token(tweepy_auth.ACCESS_TOKEN, tweepy_auth.ACCESS_TOKEN_SECRET) listener = StreamMonitor(epd, image, draw, name_font, message_font) stream = tweepy.Stream(auth, listener) setTerms = argv # stream.sample() # low bandwidth public stream stream.filter(track=setTerms)
def validate_password(username, password): basic_auth = tweepy.BasicAuthHandler(username, password) api = tweepy.API(basic_auth) return api.verify_credentials()
def login(): auth = tweepy.BasicAuthHandler('user', 'pass') return tweepy.API(auth)
def identi(self): auth = tweepy.BasicAuthHandler(username, password) ica = tweepy.API(auth, host = 'identi.ca', api_root = '/api', secure = True) ica.update_status(self.status)
def update_status(cls, username, password, status): from django.utils import simplejson as json import tweepy auth = tweepy.BasicAuthHandler(username, password) bot = tweepy.API(auth) bot.update_status(str(unicode(status).encode("utf-8")))
def main(): auth = tweepy.BasicAuthHandler("danhak", "alphadot25") stream = tweepy.Stream(auth, StreamWatcherListener(), timeout=None) stream.sample()
def get_pull_page_tweets(self): auth = tweepy.BasicAuthHandler("dooflin5", "Airjordan23!?") api = tweepy.API(auth)