本文整理汇总了Python中twython.Twython.lookup_status方法的典型用法代码示例。如果您正苦于以下问题:Python Twython.lookup_status方法的具体用法?Python Twython.lookup_status怎么用?Python Twython.lookup_status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twython.Twython
的用法示例。
在下文中一共展示了Twython.lookup_status方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_twitter_data
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import lookup_status [as 别名]
def update_twitter_data(self):
twitter = Twython(
TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET,
TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_SECRET
)
# get the data from Twitter API
twitter_data = twitter.lookup_status(id=','.join(self.tweet_ids()))
# so ugly
for tweet_data in twitter_data:
tweet_data_id = str(tweet_data['id'])
tweet_data_media = tweet_data.get('entities').get('media')
tweet_data_photo = tweet_data_media[0].get('media_url_https') if len(tweet_data_media) else None
tweet_data_text = tweet_data.get('text')
tweet_data_text = strip_tweet_text(tweet_data_text)
if self.tweet1.endswith(tweet_data_id):
if not self.tweet1_photo: self.tweet1_photo = tweet_data_photo
if not self.tweet1_text: self.tweet1_text = tweet_data_text
if self.tweet2.endswith(tweet_data_id):
if not self.tweet2_photo: self.tweet2_photo = tweet_data_photo
if not self.tweet2_text: self.tweet2_text = tweet_data_text
if self.tweet3.endswith(tweet_data_id):
if not self.tweet3_photo: self.tweet3_photo = tweet_data_photo
if not self.tweet3_text: self.tweet3_text = tweet_data_text
if self.tweet4.endswith(tweet_data_id):
if not self.tweet4_photo: self.tweet4_photo = tweet_data_photo
if not self.tweet4_text: self.tweet4_text = tweet_data_text
if self.tweet5.endswith(tweet_data_id):
if not self.tweet5_photo: self.tweet5_photo = tweet_data_photo
if not self.tweet5_text: self.tweet5_text = tweet_data_text
示例2: status_lookup
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import lookup_status [as 别名]
def status_lookup(ids):
"""
Retrieve status(es) via Twitter REST API.
@param ids: list of tweet ids
Returns a status/tweet object for each id in input
"""
ids = list(set(ids))
len_ids = len(ids) # @DEBUG
ids = ','.join(ids)
tw = Twython(CREDENTIALS['APP_KEY'],
CREDENTIALS['APP_SECRET'],
CREDENTIALS['ACCESS_KEY'],
CREDENTIALS['ACCESS_SECRET'])
res = tw.lookup_status(id=ids)
return res
示例3: get_matches
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import lookup_status [as 别名]
def get_matches(user, id_str):
cardList = list()
acctDict = keys #get_api_keys()
twitter = Twython(acctDict['ConsumerKey'], acctDict['ConsumerSecret'], acctDict['AccessToken'], acctDict['AccessTokenSecret'])
conn = sqlite3.connect('..\Swapp_app\users.db')
conn.row_factory = sqlite3.Row
c = conn.cursor()
c.execute('SELECT * from Notifications WHERE username ="'+user+'";')
notification_rows = c.fetchall()
conn.close()
for notification in notification_rows:
if notification['tweet_id'] <= id_str:
break;
status = twitter.lookup_status(id=notification['tweet_id'])
print status
cardList.append(processTweet(status))
return jsonify({'cards': cardList[::-1]})
示例4: print
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import lookup_status [as 别名]
# intro message to user
print("Storing tweets...")
with open(inputFileName, "r") as inputFile:
# Again using a buffer so it isn't constantly writing to disk.
buffer = ""
for line in inputFile:
# remove the newline character and superfluous comma at end of line
line = line[0:-2]
# get the tweet data from twitter, up to 100 tweets at a time
status = twitter.lookup_status(id=line)
# convert each tweet's worth of data into a string and add it to the buffer
for x in status:
#y = str((str(x).encode('utf-8'))) # this is rough but idk how else to deal with unicode errors
buffer += (tweetDict2Xml(x))
# see if we need to write to the file and clear the buffer
c+=1
if not(c%20):
print("...working "+str(c*100))
#outputFile.write(buffer.encode('utf-8'))
outputFile.write(bytes(buffer, "utf-8"))
buffer = ""
示例5: Twython
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import lookup_status [as 别名]
import time
from twython import Twython
from secrets import *
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
tweetids = []
fp = open('data/pyastro16-tweets.json')
for line in fp.readlines():
if line.startswith('{'):
try:
tweet = json.loads(line)
if 'retweeted_status' not in tweet:
tweetids.append(tweet['id'])
except Exception:
pass
chunksize = 99 # We're not allowed to grab everything at once
out = open('data/pyastro16-twitter-stats.csv', 'w')
out.write('id,favorite_count,retweet_count,created_at\n')
for idx_start in range(0, len(tweetids) + chunksize, chunksize):
print('Querying {} tweets from tweet #{}'.format(chunksize, idx_start))
ids = ','.join([str(tid) for tid in tweetids[idx_start:idx_start + chunksize]])
time.sleep(1)
tweets = twitter.lookup_status(id=ids)
for tweet in tweets:
out.write('{id},{favorite_count},{retweet_count},{created_at}\n'.format(**tweet))
out.close()
示例6: TwitterHelper
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import lookup_status [as 别名]
#.........这里部分代码省略.........
place = result["result"]["places"][0]
location.place_id_twitter = place["id"]
return location
else:
return None
@retry(**retry_args)
def update_profile_image(self, file_path):
if file_path:
logger.info("updating profile image %s" % file_path)
with open(file_path, 'rb') as file:
self.twitter.update_profile_image(image=file)
@retry(**retry_args)
def update_profile_banner_image(self, file_path):
if file_path:
logger.info("updating banner image %s" % file_path)
with open(file_path, 'rb') as file:
try:
self.twitter.update_profile_banner_image(banner=file)
except TwythonError as ex:
if "Response was not valid JSON" in str(ex):
# twython issue i think
logger.warning(ex)
else:
raise
@retry(**retry_args)
def update_profile(self, **kwargs):
return self.twitter.update_profile(**kwargs)
@retry(**retry_args)
def get_list_statuses(self, **kwargs):
return self.twitter.get_list_statuses(**kwargs)
@retry(**retry_args)
def get_user_suggestions_by_slug(self, **kwargs):
return self.twitter.get_user_suggestions_by_slug(**kwargs)
@retry(**retry_args)
def get_user_suggestions(self, **kwargs):
return self.twitter.get_user_suggestions(**kwargs)
@retry(**retry_args)
def lookup_status(self, **kwargs):
return self.twitter.lookup_status(**kwargs)
@retry(**retry_args)
def get_followers(self, **kwargs):
kwargs["stringify_ids"] = True
followers = set()
cursor = -1
while cursor != "0":
kwargs["cursor"] = cursor
logger.info("getting followers")
response = self.twitter.get_followers_ids(**kwargs)
cursor = response["next_cursor_str"]
followers = followers.union(set(response["ids"]))
return followers
@retry(**retry_args)
def get_following(self, **kwargs):
kwargs["stringify_ids"] = True
following = set()
cursor = -1
while cursor != "0":
kwargs["cursor"] = cursor
logger.info("getting following")
response = self.twitter.get_friends_ids(**kwargs)
cursor = response["next_cursor_str"]
following = following.union(set(response["ids"]))
return following
@retry(**retry_args)
def update_rate_limits(self):
data = self.twitter.get_application_rate_limit_status()
self.rates = RateLimits(data)
logger.info("Updated rate limits for {}: {}".format(self.identity.screen_name, self.rates.display()))
def _rate_limit(self, limit_name, func, *args, **kwargs):
if self.rates.can(limit_name):
try:
return func(*args, **kwargs)
except Exception as ex:
logger.warning(ex)
return None
else:
logger.warning("{} limit exceeded".format(limit_name))
return None
@retry(**retry_args)
def get_statuses(self, id_strs):
id_strs_csv = ",".join(id_strs)
return self.twitter.lookup_status(id=id_strs_csv)
@retry(**retry_args)
def get_status(self, id_str):
return self.twitter.show_status(id=id_str)
示例7: open
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import lookup_status [as 别名]
outfile = '/users/a/r/areagan/fun/twitter/scraping/data-2/{0:019d}-{1:019d}.json'.format(numCompleted,numCompleted+numToGrab*100-1)
outlog = '/users/a/r/areagan/fun/twitter/scraping/log-2/{0:019d}-{1:019d}.log'.format(numCompleted,numCompleted+numToGrab*100-1)
f = codecs.open(outfile,'w','utf8')
# f = codecs.open("test-output.json",'a','utf8')
g = open(outlog,'w')
# f.write('test\n')
# f.close()
# print(tweetIDs)
for i,tweetIDlist in enumerate(tweetIDs):
# time.sleep(1)
g.write('getting tweet ID ' + str(tweetIDlist[0]) + ' to ' + str(tweetIDlist[-1]) + '\n')
try:
tweets = twitter.lookup_status(id=tweetIDlist,map="false",trim_user="false",entities="true")
for tweet in tweets:
# print(tweet["id"])
json.dump(tweet,f,ensure_ascii=False)
f.write('\n')
# ujson.dump(tweet,f,ensure_ascii=False)
# print(tweets)
# print(len(tweets))
# f.write('\n')
g.write(",".join([tweet["id_str"] for tweet in tweets]))
g.write('\n')
except TwythonError as e:
g.write(str(e))
g.write('\n')
# raise(e)
# print(e)
示例8: window
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import lookup_status [as 别名]
orig_tweet_id = 608648346048303104
manos_tweet_id = 608658245352353792
"""
Returns fully-hydrated tweet objects
for up to 100 tweets per request, as
specified by comma-separated values
passed to the id parameter.
Requests / 15-min window (user auth) 180
Requests / 15-min window (app auth) 60
"""
params = {'id':orig_tweet_id}
response = timeline_twitter.lookup_status(**params)
#print response
for status in response:
print status['user']['screen_name']
print status['retweet_count']
"""
Returns a collection of up to 100 user IDs belonging
to users who have retweeted the tweet specified by the
id parameter.
you can cursor this...
Requests / 15-min window (user auth) 15
Requests / 15-min window (app auth) 60