本文整理汇总了Python中twython.Twython.get_mentions_timeline方法的典型用法代码示例。如果您正苦于以下问题:Python Twython.get_mentions_timeline方法的具体用法?Python Twython.get_mentions_timeline怎么用?Python Twython.get_mentions_timeline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twython.Twython
的用法示例。
在下文中一共展示了Twython.get_mentions_timeline方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_mentions_timeline [as 别名]
def main():
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
startup = True
lastCheck = time.time()
statusUpdate = time.time()
running = True
while running:
if startup:
# Set a limit for how far back we read. Things that were sent to us
# before we powered on won't get read.
startTime = datetime.datetime.utcnow().isoformat()
limitTweet = twitter.update_status(status="Powered on at " +
startTime)
lastRead = datetime.datetime.strptime(limitTweet['created_at'],
'%a %b %d %H:%M:%S %z %Y')
startup = False
selfCheckTime = time.time()
if (time.time() - lastCheck >= 90):
# Every minute and a half, create a dictionary consisting of each
# user's handle and the request they make.
lastCheck = time.time()
userRequests = []
mentions = twitter.get_mentions_timeline()
for i in mentions:
tweetTimestamp = datetime.datetime.strptime(i['created_at'],
'%a %b %d %H:%M:%S %z %Y')
if tweetTimestamp <= lastRead:
# Stop if we've read this tweet already.
break
else:
user = '@' + i['user']['screen_name'] + ' '
request = i['text']
userRequests.append({'user':user, 'request':request,
'timestamp':tweetTimestamp})
# Now that we've gotten our mentions we're going to go through and
# fulfill each user's request.
for i in userRequests:
lastRead = i['timestamp']
maxLength = 140 - len(i['user'])
if ('fortune' in i['request']):
process = subprocess.run(['fortune', '-s', '-n ' +
str(maxLength)],
stdout=subprocess.PIPE)
# Convert our subprocess object's output to a string
fortune = ''
for j in process.stdout:
fortune += chr(j)
fortune = fortune.strip('\n')
twitter.update_status(status=user + fortune)
del userRequests[userRequests.index(i)]
#If it's been an hour since running a self-check, we'll do that here.
if (time.time() - selfCheckTime >= 3600):
twitter.update_status(status = 'Self-check at ' +
datetime.datetime.utcnow().isoformat())
selfCheckTime = time.time()
示例2: main
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_mentions_timeline [as 别名]
def main():
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
mentions = twitter.get_mentions_timeline()
if newMention(mentions[0]):
IDFile.write(mentions[0]['id_str']+'\n')
#pprint.pprint(mentions[0])
tweet = createTweet(mentions[0])
print("@GetTheWeather just tweeted the following:")
print(tweet)
twitter.update_status(status=tweet)
示例3:
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_mentions_timeline [as 别名]
print
tweets = twitter.get_home_timeline()
for tweet in tweets:
print "%d -> %s" % (tweet['id'], tweet['text'])
print
print "User timeline"
print "============="
print
print "La user timeline son los tweets míos"
print
tweets = twitter.get_user_timeline()
for tweet in tweets:
print "%d -> %s" % (tweet['id'], tweet['text'])
print
print "Mentions timeline"
print "================="
print
print "La mentions timeline son los tweets donde aparezco como @arduinoandoain"
print
tweets = twitter.get_mentions_timeline()
for tweet in tweets:
print "%d -> %s" % (tweet['id'], tweet['text'])
示例4: extractUsername
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_mentions_timeline [as 别名]
def extractUsername(post):
user = None
screen_name = None
if "user" in post:
user = post["user"]
if "screen_name" in user:
screen_name = user["screen_name"]
return screen_name
twitter_acnt = Twython(
Configs.consumer_key,
Configs.consumer_secret,
Configs.access_token_key,
Configs.access_token_secret)
mention_posts = twitter_acnt.get_mentions_timeline(since_id=lastIncomingId)
for post in mention_posts:
print str(extractUsername(post)) + ": " + str(extractImageUrl(post)) + "\n"
url = extractImageUrl(post)
if url != None:
image_data = urllib2.urlopen(url).read()
im = Image.open(BytesIO(image_data))
print str(im)
示例5: TwythonAPITestCase
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_mentions_timeline [as 别名]
class TwythonAPITestCase(unittest.TestCase):
def setUp(self):
client_args = {
'headers': {
'User-Agent': '__twython__ Test'
},
'allow_redirects': False
}
oauth2_client_args = {
'headers': {} # This is so we can hit coverage that Twython sets User-Agent for us if none is supplied
}
self.api = Twython(app_key, app_secret,
oauth_token, oauth_token_secret,
client_args=client_args)
self.oauth2_api = Twython(app_key, access_token=access_token,
client_args=oauth2_client_args)
def test_construct_api_url(self):
"""Test constructing a Twitter API url works as we expect"""
url = 'https://api.twitter.com/1.1/search/tweets.json'
constructed_url = self.api.construct_api_url(url, q='#twitter')
self.assertEqual(constructed_url, 'https://api.twitter.com/1.1/search/tweets.json?q=%23twitter')
def test_get(self):
"""Test Twython generic GET request works"""
self.api.get('account/verify_credentials')
def test_post(self):
"""Test Twython generic POST request works, with a full url and
with just an endpoint"""
update_url = 'https://api.twitter.com/1.1/statuses/update.json'
status = self.api.post(update_url, params={'status': 'I love Twython!'})
self.api.post('statuses/destroy/%s' % status['id_str'])
def test_get_lastfunction_header(self):
"""Test getting last specific header of the last API call works"""
self.api.get('statuses/home_timeline')
self.api.get_lastfunction_header('x-rate-limit-remaining')
def test_get_lastfunction_header_not_present(self):
"""Test getting specific header that does not exist from the last call returns None"""
self.api.get('statuses/home_timeline')
header = self.api.get_lastfunction_header('does-not-exist')
self.assertEqual(header, None)
def test_get_lastfunction_header_no_last_api_call(self):
"""Test attempting to get a header when no API call was made raises a TwythonError"""
self.assertRaises(TwythonError, self.api.get_lastfunction_header,
'no-api-call-was-made')
def test_search_gen(self):
"""Test looping through the generator results works, at least once that is"""
search = self.api.search_gen('twitter', count=1)
counter = 0
while counter < 2:
counter += 1
result = next(search)
new_id_str = int(result['id_str'])
if counter == 1:
prev_id_str = new_id_str
time.sleep(1) # Give time for another tweet to come into search
if counter == 2:
self.assertTrue(new_id_str > prev_id_str)
def test_encode(self):
"""Test encoding UTF-8 works"""
self.api.encode('Twython is awesome!')
def test_html_for_tweet(self):
"""Test HTML for Tweet returns what we want"""
tweet_text = self.api.html_for_tweet(test_tweet_object)
self.assertEqual(test_tweet_html, tweet_text)
def test_html_for_tweet_expanded_url(self):
"""Test using expanded url in HTML for Tweet displays full urls"""
tweet_text = self.api.html_for_tweet(test_tweet_object,
use_expanded_url=True)
# Make sure full url is in HTML
self.assertTrue('http://google.com' in tweet_text)
def test_html_for_tweet_short_url(self):
"""Test using expanded url in HTML for Tweet displays full urls"""
tweet_text = self.api.html_for_tweet(test_tweet_object, False)
# Make sure HTML doesn't contain the display OR exapanded url
self.assertTrue(not 'http://google.com' in tweet_text)
self.assertTrue(not 'google.com' in tweet_text)
def test_raise_error_on_bad_ssl_cert(self):
"""Test TwythonError is raised by a RequestException when an actual HTTP happens"""
self.assertRaises(TwythonError, self.api.get, 'https://example.com')
# Timelines
def test_get_mentions_timeline(self):
"""Test returning mentions timeline for authenticated user succeeds"""
self.api.get_mentions_timeline()
#.........这里部分代码省略.........
示例6: Twython
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_mentions_timeline [as 别名]
secrets = f.read().split("\n")
# close the file
f.close()
# sort them
apiKey = secrets[0]
apiSecret = secrets[1]
accessToken = secrets[2]
accessTokenSecret = secrets[3]
# instantiate Twython
twitter = Twython(apiKey, apiSecret, accessToken, accessTokenSecret)
# get info about recent mentions
data = twitter.get_mentions_timeline(count=10)
# useful variables
new = True
first = True
replacement_most_recent = ""
# look at each mention
for mention in data:
# if top of the list, save id (this wil be the new most recently responded to)
if first:
replacement_most_recent = str(mention["id"])
first = False
# get id of previous most recent tweet responded to
示例7: int
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_mentions_timeline [as 别名]
c.sendto(msg, (IP_ADDRESS, PORT))
#c.close()
time.sleep(1)
oldMention=""
#run the stuff
while True:
#initiate the timer
start_mins = int(time.time() / 60)
print "startMins: " + str(start_mins)
#get newest mention
fullMsage = twitter.get_mentions_timeline() #get the full message one time, we will parse this message
print fullMsage
#get the user
mentionUser = fullMsage[0]['user']['screen_name']
#get the text
mention = fullMsage[0]['text']
#create the OSC message for /user
usermsg = OSC.OSCMessage(address = "/user")
usermsg.append(mentionUser)
#parse the mention text (remove @news_glass)
mention = mention.replace("@news_glass ", "") #"@news_glass"
mentions = mention.split()
示例8: TwythonAPITestCase
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_mentions_timeline [as 别名]
class TwythonAPITestCase(unittest.TestCase):
def setUp(self):
self.api = Twython(app_key, app_secret,
oauth_token, oauth_token_secret)
# Timelines
def test_get_mentions_timeline(self):
'''Test returning mentions timeline for authenticated user succeeds'''
self.api.get_mentions_timeline()
def test_get_user_timeline(self):
'''Test returning timeline for authenticated user and random user
succeeds'''
self.api.get_user_timeline() # Authenticated User Timeline
self.api.get_user_timeline(screen_name='twitter') # Random User Timeline
def test_get_protected_user_timeline_following(self):
'''Test returning a protected user timeline who you are following
succeeds'''
self.api.get_user_timeline(screen_name=protected_twitter_1)
def test_get_protected_user_timeline_not_following(self):
'''Test returning a protected user timeline who you are not following
fails and raise a TwythonAuthError'''
self.assertRaises(TwythonAuthError, self.api.get_user_timeline,
screen_name=protected_twitter_2)
def test_get_home_timeline(self):
'''Test returning home timeline for authenticated user succeeds'''
self.api.get_home_timeline()
# Tweets
def test_get_retweets(self):
'''Test getting retweets of a specific tweet succeeds'''
self.api.get_retweets(id=test_tweet_id)
def test_show_status(self):
'''Test returning a single status details succeeds'''
self.api.show_status(id=test_tweet_id)
def test_update_and_destroy_status(self):
'''Test updating and deleting a status succeeds'''
status = self.api.update_status(status='Test post just to get deleted :(')
self.api.destroy_status(id=status['id_str'])
def test_retweet(self):
'''Test retweeting a status succeeds'''
retweet = self.api.retweet(id='99530515043983360')
self.api.destroy_status(id=retweet['id_str'])
def test_retweet_twice(self):
'''Test that trying to retweet a tweet twice raises a TwythonError'''
retweet = self.api.retweet(id='99530515043983360')
self.assertRaises(TwythonError, self.api.retweet,
id='99530515043983360')
# Then clean up
self.api.destroy_status(id=retweet['id_str'])
def test_get_oembed_tweet(self):
'''Test getting info to embed tweet on Third Party site succeeds'''
self.api.get_oembed_tweet(id='99530515043983360')
def test_get_retweeters_ids(self):
'''Test getting ids for people who retweeted a tweet succeeds'''
self.api.get_retweeters_ids(id='99530515043983360')
# Search
def test_search(self):
'''Test searching tweets succeeds'''
self.api.search(q='twitter')
# Direct Messages
def test_get_direct_messages(self):
'''Test getting the authenticated users direct messages succeeds'''
self.api.get_direct_messages()
def test_get_sent_messages(self):
'''Test getting the authenticated users direct messages they've
sent succeeds'''
self.api.get_sent_messages()
def test_send_get_and_destroy_direct_message(self):
'''Test sending, getting, then destory a direct message succeeds'''
message = self.api.send_direct_message(screen_name=protected_twitter_1,
text='Hey d00d!')
self.api.get_direct_message(id=message['id_str'])
self.api.destroy_direct_message(id=message['id_str'])
def test_send_direct_message_to_non_follower(self):
'''Test sending a direct message to someone who doesn't follow you
fails'''
self.assertRaises(TwythonError, self.api.send_direct_message,
screen_name=protected_twitter_2, text='Yo, man!')
# Friends & Followers
def test_get_user_ids_of_blocked_retweets(self):
'''Test that collection of user_ids that the authenticated user does
not want to receive retweets from succeeds'''
#.........这里部分代码省略.........
示例9: TwythonEndpointsTestCase
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_mentions_timeline [as 别名]
class TwythonEndpointsTestCase(unittest.TestCase):
def setUp(self):
client_args = {
'headers': {
'User-Agent': '__twython__ Test'
},
'allow_redirects': False
}
# This is so we can hit coverage that Twython sets
# User-Agent for us if none is supplied
oauth2_client_args = {
'headers': {}
}
self.api = Twython(app_key, app_secret,
oauth_token, oauth_token_secret,
client_args=client_args)
self.oauth2_api = Twython(app_key, access_token=access_token,
client_args=oauth2_client_args)
# Timelines
@unittest.skip('skipping non-updated test')
def test_get_mentions_timeline(self):
"""Test returning mentions timeline for authenticated user succeeds"""
self.api.get_mentions_timeline()
@unittest.skip('skipping non-updated test')
def test_get_user_timeline(self):
"""Test returning timeline for authenticated user and random user
succeeds"""
self.api.get_user_timeline() # Authenticated User Timeline
self.api.get_user_timeline(screen_name='twitter')
# Random User Timeline
@unittest.skip('skipping non-updated test')
def test_get_protected_user_timeline_following(self):
"""Test returning a protected user timeline who you are following
succeeds"""
self.api.get_user_timeline(screen_name=protected_twitter_1)
@unittest.skip('skipping non-updated test')
def test_get_protected_user_timeline_not_following(self):
"""Test returning a protected user timeline who you are not following
fails and raise a TwythonAuthError"""
self.assertRaises(TwythonAuthError, self.api.get_user_timeline,
screen_name=protected_twitter_2)
@unittest.skip('skipping non-updated test')
def test_retweeted_of_me(self):
"""Test that getting recent tweets by authenticated user that have
been retweeted by others succeeds"""
self.api.retweeted_of_me()
@unittest.skip('skipping non-updated test')
def test_get_home_timeline(self):
"""Test returning home timeline for authenticated user succeeds"""
self.api.get_home_timeline()
# Tweets
@unittest.skip('skipping non-updated test')
def test_get_retweets(self):
"""Test getting retweets of a specific tweet succeeds"""
self.api.get_retweets(id=test_tweet_id)
@unittest.skip('skipping non-updated test')
def test_show_status(self):
"""Test returning a single status details succeeds"""
self.api.show_status(id=test_tweet_id)
@unittest.skip('skipping non-updated test')
def test_update_and_destroy_status(self):
"""Test updating and deleting a status succeeds"""
status = self.api.update_status(status='Test post just to get \
deleted :( %s' % int(time.time()))
self.api.destroy_status(id=status['id_str'])
@unittest.skip('skipping non-updated test')
def test_get_oembed_tweet(self):
"""Test getting info to embed tweet on Third Party site succeeds"""
self.api.get_oembed_tweet(id='99530515043983360')
@unittest.skip('skipping non-updated test')
def test_get_retweeters_ids(self):
"""Test getting ids for people who retweeted a tweet succeeds"""
self.api.get_retweeters_ids(id='99530515043983360')
# Search
@unittest.skip('skipping non-updated test')
def test_search(self):
"""Test searching tweets succeeds"""
self.api.search(q='twitter')
# Direct Messages
@unittest.skip('skipping non-updated test')
def test_get_direct_messages(self):
"""Test getting the authenticated users direct messages succeeds"""
self.api.get_direct_messages()
#.........这里部分代码省略.........
示例10: Twython
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_mentions_timeline [as 别名]
auth_props = t.get_authentication_tokens(callback_url='http://localhost.com/login_twitter.html')
oauth_token = '90926098-ha8yQlvDrtI92odzBcVlBehmxGpZdrOQqLOJAFs4E'
oauth_token_secret = '2n8hPIA9yF6J20G9ZjWAcDLAnKarvSYbYyjV8EDw'
oauth_verifier = ''
try:
t = Twython(app_key, app_secret, oauth_token, oauth_token_secret)
followers = t.get_followers_ids()
for follower_id in followers['ids']:
print follower_id
tweets = t.get_home_timeline()
for tweet in tweets:
print 'Name: %s \n' % (tweet['user']['name'].encode('utf-8'))
print 'Tweet: %s \n' % (tweet['text'].encode('utf-8'))
mentions = t.get_mentions_timeline()
for mention in mentions:
print 'Name: %s \n' % (mention['user']['name'].encode('utf-8'))
print 'Mention: %s \n' % (mention['text'].encode('utf-8'))
except TwythonAuthError as e:
print e
except TwythonError as er:
print er
示例11: raw_input
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_mentions_timeline [as 别名]
# Post
post = raw_input("Write your tweet: ")
twitter.update_status(status=post)
# Get timelines
print twitter.get_user_timeline(screen_name = "name")
print twitter.get_home_timeline(count = 5)
# Search
print twitter.search(q="linux", result_type="popular")
# Follow
twitter.create_friendship(screen_name = "LinuxUserMag")
# Retweet
twitter.retweet(id = "12345")
# Favouriting
twitter.create_favorite(id = "12345")
print twitter.get_favorites()
# Mentions
print twitter.get_mentions_timeline(count="5")
# Trending
print twitter.get_place_trends(id="1")
# Retrieve lists
print twitter.get_list_statuses(id = "12345")
示例12: Twython
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_mentions_timeline [as 别名]
######################################################################################
########################### MAIN START ###########################
######################################################################################
t = Twython(
app_key="NrNZ8RhqUPBNIIj3YvPhZW3j3",
app_secret="uK0r77j92JvIIK4i6NujCoRhHUoQHfeF3V346lDciV0XqXGes1",
oauth_token="34105126-rHyDJNCTwRUsFXCyfmBUmVrnZrI1WanMVnh0uZ2yo",
oauth_token_secret="PKYPTwmTrHGLvmngU4maT1RPWr0EGvfLz6d5PGbJY",
)
while True:
id = transfer
if id != 0:
mentions = t.get_mentions_timeline(since_id="%d" % id)
for g in mentions:
userarray = g["user"]
entities = g["entities"]
try:
media = entities["media"][0]
picurl = media["media_url"]
ppic = userarray["profile_image_url"]
tweet = g["text"]
print tweet
id = g["id"]
if id > transfer:
transfer = id
picname = grep(picurl, picnameregex)
urllib.urlretrieve(picurl, "tpics/%s" % picname)
overlay(tweet, "tpics/%s" % picname, ppic)
示例13: Tweety
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_mentions_timeline [as 别名]
class Tweety(object):
"""
Twitter client using Twython
"""
def __init__(self, app_key=TWITTER_APP_KEY, app_secret=TWITTER_APP_SECRET,
oauth_token=TWITTER_OAUTH_TOKEN, oauth_token_secret=TWITTER_OAUTH_SECRET):
try:
self.twitter = Twython(
app_key,
app_secret,
oauth_token,
oauth_token_secret)
self.cache = RedisCache({
'server': REDIS_SERVER,
'port': REDIS_PORT,
'database': REDIS_DATABASE,
'key_prefix': 'domus-twitter'
})
except TwythonAuthError:
raise Exception("Unable to connect to twitter")
def __get_friends(self):
"""
Using twitter get_friends and redis, gets a list of screen names
:return:a list of twitter users
"""
results = self.cache.get('twitter_friends')
if not results:
try:
results = [a['screen_name'] for a in self.twitter.get_friends_list()['users']]
self.cache.store('twitter_friends',json.dumps(results), expires=120)
except (TwythonError, TwythonRateLimitError):
raise Exception('Unable to get followers list')
else:
results = json.loads(results)
return results
def tweet(self, message,to_friends=False):
"""
Writtes a twit
:param message: what to tweet
:param to_friends: send to all friends?
:return:
"""
try:
if to_friends:
for a_friend in self.__get_friends():
mention = "@{} ".format(a_friend)
available_chars = 140 - len(mention)
self.twitter.update_status(
status=(mention+message)[:available_chars] + ((mention+message)[(available_chars-2):] and '..'))
else:
self.twitter.update_status(
status=message[:140] + (message[138:] and '..'))
except (TwythonError, TwythonRateLimitError):
raise Exception("Unable to post update")
def dm(self, user, message):
try:
self.twitter.send_direct_message(screen_name=user, text=message)
except TwythonError:
raise Exception("Unable to send dm to {}".format(user))
def get_dms(self):
"""
Gets a list of dms. Stores the last id seen so the next request is for the new messages only.
:return: a dict of the form {tweet_id:{sender:screen_name,text:the_message}}
"""
results = {}
dms = []
last_id = self.cache.get('twitter_last_dm')
if last_id:
dms = self.twitter.get_direct_messages(count=100,since_id = last_id)
else:
dms = self.twitter.get_direct_messages(count=100)
if dms:
last_id = 0
for a_dm in dms:
results[a_dm['id']] = {'from':a_dm['sender_screen_name'],'text': a_dm['text']}
last_id = a_dm['id'] if a_dm['id'] > last_id else last_id
self.cache.store('twitter_last_dm', last_id)
return results
def get_mentions(self):
"""
Gets a list of mentions. Stores the last id seen so the next request is for the new messages only.
:return: a dict of the form {tweet_id:{sender:screen_name,text:the_message}}
"""
results = {}
mentions = []
last_id = self.cache.get('twitter_last_mention')
if last_id:
mentions = self.twitter.get_mentions_timeline(count=100,since_id = last_id)
else:
mentions = self.twitter.get_mentions_timeline(count=100)
if mentions:
last_id = 0
for a_mention in mentions:
results[a_mention['id']] = {'from':a_mention['user']['screen_name'],'text': a_mention['text']}
#.........这里部分代码省略.........
示例14: SenseHat
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_mentions_timeline [as 别名]
from sense_hat import SenseHat
from twython import Twython
sense = SenseHat()
sense.clear()
app_key = 'appkey'
app_secret = 'appsecret'
access_token = 'accesstoken'
access_token_secret = 'accesstokensecret'
handle = Twython(app_key, app_secret, access_token, access_token_secret)
mention = handle.get_mentions_timeline(count=1)
for mentions in mention:
color = mentions['text']
color = color[13:len(color)].lower()
if color == 'red':
print('cherry')
sense.clear([255, 0, 0])
elif color == 'orange':
print('mango')
sense.clear([255, 127, 0])
elif color == 'yellow':
print('pineapple')
sense.clear([255, 255, 0])
elif color == 'green':
print('key lime')
sense.clear([0, 255, 0])
elif color == 'blue':
print('blueberry')
sense.clear([0, 0, 255])
elif color == 'indigo':
print('blackberry')
sense.clear([75, 0, 130])
示例15: setup_all
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_mentions_timeline [as 别名]
from mention import *
import time, os
setup_all()
create_all()
CONSUMER_KEY = os.environ['CONSUMER_KEY']
CONSUMER_SECRET = os.environ['CONSUMER_SECRET']
OAUTH_TOKEN = os.environ['OAUTH_TOKEN']
OAUTH_SECRET = os.environ['OAUTH_SECRET']
twitter = Twython(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET)
img = open("album_artwork.jpeg", 'rb')
while True:
for mention in twitter.get_mentions_timeline():
status_id = str(mention['id'])
if not Mention.query.filter_by(status_id=status_id).all():
screen_name = '@' + mention['user']['screen_name']
try:
twitter.update_status_with_media(status = screen_name,
media = img,
in_reply_to_status_id = status_id)
except:
continue
finally:
Mention(status_id=status_id) # builds new mention
session.commit() # saves Mention
else:
print 'We replied to this one already!'