class OAuth(): """OAuth object""" __gtype_name__ = "OAuth" oauth_token = None oauth_token_secret = None def __init__(self): self.auth = Twython( base64.b64decode(APP_KEY), base64.b64decode(APP_SECRET)) self.auth = self.auth.get_authentication_tokens() self.oauth_token = self.auth['oauth_token'] self.oauth_token_secret = self.auth['oauth_token_secret'] def get_oauth_url(self): return self.auth['auth_url'] def get_tokens(self, pin): self.twitter = Twython( base64.b64decode(APP_KEY), base64.b64decode( APP_SECRET), self.oauth_token, self.oauth_token_secret) try: __authorized_tokens = self.twitter.get_authorized_tokens(pin) self.oauth_token = __authorized_tokens['oauth_token'] self.oauth_token_secret = __authorized_tokens['oauth_token_secret'] return True except TwythonError as e: print(e) return False
class OAuth(): """OAuth object""" __gtype_name__ = "OAuth" oauth_token = None oauth_token_secret = None def __init__(self): self.auth = Twython(base64.b64decode(APP_KEY), base64.b64decode(APP_SECRET)) self.auth = self.auth.get_authentication_tokens() self.oauth_token = self.auth['oauth_token'] self.oauth_token_secret = self.auth['oauth_token_secret'] def get_oauth_url(self): return self.auth['auth_url'] def get_tokens(self, pin): self.twitter = Twython(base64.b64decode(APP_KEY), base64.b64decode(APP_SECRET), self.oauth_token, self.oauth_token_secret) try: __authorized_tokens = self.twitter.get_authorized_tokens(pin) self.oauth_token = __authorized_tokens['oauth_token'] self.oauth_token_secret = __authorized_tokens['oauth_token_secret'] return True except TwythonError as e: print(e) return False
def __init__(self, token, secret): self.session = Twython(base64.b64decode(APP_KEY), base64.b64decode(APP_SECRET), token, secret) try: self.authenticated_user = self.session.verify_credentials() except TwythonError: print(TwythonError.msg) self.tweet_count = Settings().get('tweet_count')
def get_tokens(self, pin): self.twitter = Twython(base64.b64decode(APP_KEY), base64.b64decode(APP_SECRET), self.oauth_token, self.oauth_token_secret) try: __authorized_tokens = self.twitter.get_authorized_tokens(pin) self.oauth_token = __authorized_tokens['oauth_token'] self.oauth_token_secret = __authorized_tokens['oauth_token_secret'] return True except TwythonError as e: print(e) return False
def get_tokens(self, pin): self.twitter = Twython( base64.b64decode(APP_KEY), base64.b64decode( APP_SECRET), self.oauth_token, self.oauth_token_secret) try: __authorized_tokens = self.twitter.get_authorized_tokens(pin) self.oauth_token = __authorized_tokens['oauth_token'] self.oauth_token_secret = __authorized_tokens['oauth_token_secret'] return True except TwythonError as e: print(e) return False
def __init__(self): self.auth = Twython( base64.b64decode(APP_KEY), base64.b64decode(APP_SECRET)) self.auth = self.auth.get_authentication_tokens() self.oauth_token = self.auth['oauth_token'] self.oauth_token_secret = self.auth['oauth_token_secret']
class Twitter(): """Twitter object""" __gtype_name__ = "Twitter" def __init__(self, token, secret): self.session = Twython(base64.b64decode(APP_KEY), base64.b64decode(APP_SECRET), token, secret) try: self.authenticated_user = self.session.verify_credentials() except TwythonError: print(TwythonError.msg) self.tweet_count = Settings().get('tweet_count') def create_favorite(self, tweet_id, favorite): self.session.create_favorite(id=tweet_id) if not favorite \ else self.session.destroy_favorite(id=tweet_id) def destroy_tweet(self, tweet_id): self.session.destroy_status(id=tweet_id) def destroy_dm(self, dm_id): self.session.destroy_direct_message(id=dm_id) def retweet(self, tweet_id): self.session.retweet(id=tweet_id) def get_user(self, screen_name, cb): data = self.session.show_user(screen_name=screen_name) cb(data) def update_status(self, data): # with media, upload if data['media_path']: photo = open(data['media_path'], 'rb') # is a reply? if data['in_reply_to_status_id']: self.session.update_status_with_media(status=data['status'], media=photo, in_reply_to_status_id= data['in_reply_to_status_id']) else: self.session.update_status_with_media( status=data['status'], media=photo) # plain status else: # is a reply? if data['in_reply_to_status_id']: self.session.update_status(status=data['status'], in_reply_to_status_id= data['in_reply_to_status_id']) else: self.session.update_status(status=data['status']) def send_dm_status(self, data): self.session.send_direct_message(text=data['status'], screen_name=data['screen_name']) def search(self, txt, oldest_id, cb): try: query = urllib.unquote(txt).encode("utf8") if oldest_id > 0: data = self.session.search(q=query, #result_type="recent", count=self.tweet_count, max_id=oldest_id - 1) else: data = self.session.search(q=query, #result_type="recent", count=self.tweet_count) except TwythonError as e: print(e) return None cb(data, txt)
def __init__(self): self.auth = Twython(base64.b64decode(APP_KEY), base64.b64decode(APP_SECRET)) self.auth = self.auth.get_authentication_tokens() self.oauth_token = self.auth['oauth_token'] self.oauth_token_secret = self.auth['oauth_token_secret']