本文整理汇总了Python中tweepy.API.lookup_users方法的典型用法代码示例。如果您正苦于以下问题:Python API.lookup_users方法的具体用法?Python API.lookup_users怎么用?Python API.lookup_users使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tweepy.API
的用法示例。
在下文中一共展示了API.lookup_users方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: unwrapped_callback
# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import lookup_users [as 别名]
def unwrapped_callback(self, resp):
if resp is None:
raise LoginCallbackError(_("You denied the request to login"))
# Try to read more from the user's Twitter profile
auth = TwitterOAuthHandler(self.consumer_key, self.consumer_secret)
if self.access_key is not None and self.access_secret is not None:
auth.set_access_token(self.access_key, self.access_secret)
else:
auth.set_access_token(resp['oauth_token'], resp['oauth_token_secret'])
api = TwitterAPI(auth)
try:
twinfo = api.lookup_users(user_ids=[resp['user_id']])[0]
fullname = twinfo.name
avatar_url = twinfo.profile_image_url_https.replace('_normal.', '_bigger.')
except TweepError:
fullname = None
avatar_url = None
return {'userid': resp['user_id'],
'username': resp['screen_name'],
'fullname': fullname,
'avatar_url': avatar_url,
'oauth_token': resp['oauth_token'],
'oauth_token_secret': resp['oauth_token_secret'],
'oauth_token_type': None, # Twitter doesn't have token types
}
示例2: unwrapped_callback
# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import lookup_users [as 别名]
def unwrapped_callback(self, resp):
if resp is None:
raise LoginCallbackError(_("You denied the request to login"))
# Try to read more from the user's Twitter profile
auth = TwitterOAuthHandler(self.consumer_key, self.consumer_secret)
if self.access_key is not None and self.access_secret is not None:
auth.set_access_token(self.access_key, self.access_secret)
else:
auth.set_access_token(resp["oauth_token"], resp["oauth_token_secret"])
api = TwitterAPI(auth)
try:
twinfo = api.lookup_users(user_ids=[resp["user_id"]])[0]
fullname = twinfo.name
avatar_url = twinfo.profile_image_url_https.replace("_normal.", "_bigger.")
except TweepError:
fullname = None
avatar_url = None
return {
"userid": resp["user_id"],
"username": resp["screen_name"],
"fullname": fullname,
"avatar_url": avatar_url,
"oauth_token": resp["oauth_token"],
"oauth_token_secret": resp["oauth_token_secret"],
"oauth_token_type": None, # Twitter doesn't have token types
}
示例3: StreamConsumerThreadClass
# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import lookup_users [as 别名]
class StreamConsumerThreadClass(threading.Thread):
def __init__(self, term="", oauthfile="", follow=False, user=False, track=False):
threading.Thread.__init__(self)
self.searchterm = term
self.name = term
self.consume = True
self.follow = follow
self.user = user
self.track = track
listener = MongoDBListener()
try:
oauth = json.loads(open(oauthfile, "r").read())
if "consumer_key" in oauth:
auth = OAuthHandler(oauth["consumer_key"], oauth["consumer_secret"])
auth.set_access_token(oauth["access_token"], oauth["access_token_secret"])
self.api = API(auth)
if not self.api.verify_credentials():
raise Exception("Invalid credentials")
self.stream = Stream(auth, listener, timeout=60)
except:
print "Error logging to Twitter"
raise
def stop_consume(self):
self.stream.disconnect()
def run(self):
now = datetime.datetime.now()
if self.user:
print "Twitter Stream of the OAuth user: started at: %s" % (now)
else:
print "Twitter Stream with terms: %s started at: %s" % (self.getName(), now)
connected = False
while True:
try:
if not connected:
connected = True
if self.user:
self.stream.userstream(_with="followings")
elif self.follow:
user_ids = []
for user in self.api.lookup_users([], self.searchterm.split(","), False):
user_ids.append(user.id)
self.stream.filter(follow=[",".join("{0}".format(n) for n in user_ids)])
elif self.track:
self.stream.filter(track=[self.searchterm])
except SSLError, sse:
print sse
connected = False
except Exception, e:
print "Stream error"
raise e
示例4: TweetStream
# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import lookup_users [as 别名]
#.........这里部分代码省略.........
with self.db_lock:
self.database.execute("INSERT INTO links VALUES (?, ?)", (url, response_at.headers["Refresh"][6:]))
self.database.commit()
elif "Location" in response_at.headers:
arc_url.append(response_at.headers["Location"])
with self.db_lock:
self.database.execute("INSERT INTO links VALUES (?, ?)", (url, response_at.headers["Location"]))
self.database.commit()
#if "Location" in response_pe.headers:
# arc_url.append("http://peeep.us" + response_pe.headers["Location"])
# with self.db_lock:
# self.database.execute("INSERT INTO links VALUES (?, ?)", (url, "http://peeep.us" + response_pe.headers["Location"]))
# self.database.commit()
return arc_url or None
def m_tweet_archive_sync(self, url):
future_at = self.gsession.post(ARCHIVE_TODAY_URL, data={
"url": url,
}, headers={
"Referer": "https://archive.is",
"Connection": "close",
}, timeout=30, verify=True, allow_redirects=False)
future_ts = self.gsession.get("http://tweetsave.com/api.php?mode=save&tweet=", params={
"mode": "save",
"tweet": url
}, timeout=30)
response = future_ts.result()
response_at = future_at.result()
arc_url = []
try:
payload = response.json()
if "redirect" in payload and payload["status"] == "OK":
arc_url.append(payload["redirect"])
with self.db_lock:
self.database.execute("INSERT INTO links VALUES (?, ?)", (url, payload["redirect"]))
self.database.commit()
except:
pass
if "Refresh" in response_at.headers:
arc_url.append(response_at.headers["Refresh"][6:])
with self.db_lock:
self.database.execute("INSERT INTO links VALUES (?, ?)", (url, response_at.headers["Refresh"][6:]))
self.database.commit()
elif "Location" in response_at.headers:
arc_url.append(response_at.headers["Location"])
with self.db_lock:
self.database.execute("INSERT INTO links VALUES (?, ?)", (url, response_at.headers["Location"]))
self.database.commit()
return arc_url
def m_convert_ids_to_users(self, l):
return self.twapi.lookup_users(user_ids=l)
def m_get_userid(self, name):
name = name.lower()
if name in self.id_cache:
return self.id_cache[name]
else:
try:
user = self.twapi.get_user(screen_name=name)
except:
return None
self.id_cache[name] = user.id_str
return user.id_str
def midori_push(self, tweet, arc, channel, the_url=None):
tw = HTML_PARSER.unescape(tweet.text).replace("\n", " ")
for url in tweet.entities["urls"]:
tw = tw.replace(url["url"], url["expanded_url"])
if arc:
text = (u"@{0}: \"{1}\" {3}({2})".format(
tweet.author.screen_name, tw, ", ".join(arc),
"({0}) ".format(the_url) if the_url else ""))
else:
text = (u"@{0}: \"{1}\" ({2})".format(
tweet.author.screen_name, tw, the_url))
self.mapi.privmsg(channel, text)
def on_status(self, tweet):
if self.filter_others and tweet.author.id_str not in self.follow_ids:
return True
the_url = "https://twitter.com/{0}/status/{1}".format(tweet.author.screen_name, tweet.id_str)
if tweet.author.id_str not in self.silenced_ids:
self.midori_push(tweet, None, self.cfg["channel"], the_url)
links = self.m_tweet_archive_sync(the_url)
if tweet.author.id_str not in self.silenced_ids:
self.mapi.privmsg(self.cfg["channel"], "-> {0}".format(", ".join(links)))
return True
def on_disconnect(self, status):
print(status)
print("disconnected :^(")
self.mapiobj.privmsg(CHANNEL, "Lost connection.")