本文整理汇总了Python中twython.Twython.get_list_members方法的典型用法代码示例。如果您正苦于以下问题:Python Twython.get_list_members方法的具体用法?Python Twython.get_list_members怎么用?Python Twython.get_list_members使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twython.Twython
的用法示例。
在下文中一共展示了Twython.get_list_members方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Collect
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_list_members [as 别名]
class Collect(object):
"""Get, merge and filter the members of the provided Twitter lists."""
def __init__(self, lists, refine=True, append=False):
"""
:param lists: a python list of twitter list urls
"""
urls = list(set(lists)) # remove duplicates
stopwords = ["", "https:", "twitter.com"]
cr = [app_key, app_secret, auth_token, auth_secret]
self.refine = refine
self.append = append
self.twitter = Twython(*cr)
self.urls = []
for url in urls:
args = [arg for arg in url.split("/") if arg not in stopwords]
self.urls.append({"url": url, "args": args})
self.members = self.__members()
def __members(self):
"""Get and merge all members of the provided Twitter lists."""
print("Collecting...")
users = []
for url in self.urls:
slug = url["args"][2]
owner = url["args"][0]
args = {"slug": slug, "owner_screen_name": owner, "count": 5000}
members = self.__list_members(**args)
users += [member for member in members["users"]]
# filter users
if self.refine:
users = remove_duplicate_users(users)
users = refine(users)
print("Users: %s" % len(users))
return users
@limiter("lists/members")
def __list_members(self, *args, **kwargs):
"""Twython method wrapper, to envoke rate limiter."""
return self.twitter.get_list_members(**kwargs)
def store(self):
"""Store the users from the lists to the database."""
if not self.append:
# remove existing users
db.users.remove({})
db.users.insert_many(self.members)
示例2: int
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_list_members [as 别名]
try:
listid = int(target)
except:
listid = target
try:
x = int(owner)
except:
x = owner
me = cred["screen_name"]
now = dd.utcnow()
if isinstance(listid, str) is True:
try:
mdata = twitter.get_list_members(slug=listid, owner_screen_name=x,
count=5000)
except TwythonError as e:
print(e)
elif isinstance(listid, int) is True:
try:
mdata = twitter.get_list_members(list_id=listid, owner_screen_name=x,
count=5000)
except TwythonError as e:
print(e)
if isinstance(listid, str) is True:
try:
sdata = twitter.get_list_subscribers(slug=listid,
owner_screen_name=x, count=5000)
except TwythonError as e:
print(e)
示例3: TwythonAPITestCase
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_list_members [as 别名]
#.........这里部分代码省略.........
self.api.create_favorite(id=test_tweet_id)
self.api.destroy_favorite(id=test_tweet_id)
# Lists
def test_show_lists(self):
'''Test show lists for specified user'''
self.api.show_lists(screen_name='twitter')
def test_get_list_statuses(self):
'''Test timeline of tweets authored by members of the
specified list succeeds'''
self.api.get_list_statuses(list_id=test_list_id)
def test_create_update_destroy_list_add_remove_list_members(self):
'''Test create a list, adding and removing members then
deleting the list succeeds'''
the_list = self.api.create_list(name='Stuff')
list_id = the_list['id_str']
self.api.update_list(list_id=list_id, name='Stuff Renamed')
# Multi add/delete members
self.api.create_list_members(list_id=list_id,
screen_name='johncena,xbox')
self.api.delete_list_members(list_id=list_id,
screen_name='johncena,xbox')
# Single add/delete member
self.api.add_list_member(list_id=list_id, screen_name='justinbieber')
self.api.delete_list_member(list_id=list_id, screen_name='justinbieber')
self.api.delete_list(list_id=list_id)
def test_get_list_memberships(self):
'''Test list of lists the authenticated user is a member of succeeds'''
self.api.get_list_memberships()
def test_get_list_subscribers(self):
'''Test list of subscribers of a specific list succeeds'''
self.api.get_list_subscribers(list_id=test_list_id)
def test_subscribe_is_subbed_and_unsubscribe_to_list(self):
'''Test subscribing, is a list sub and unsubbing to list succeeds'''
self.api.subscribe_to_list(list_id=test_list_id)
# Returns 404 if user is not a subscriber
self.api.is_list_subscriber(list_id=test_list_id,
screen_name=screen_name)
self.api.unsubscribe_from_list(list_id=test_list_id)
def test_is_list_member(self):
'''Test returning if specified user is member of a list succeeds'''
# Returns 404 if not list member
self.api.is_list_member(list_id=test_list_id, screen_name='jack')
def test_get_list_members(self):
'''Test listing members of the specified list succeeds'''
self.api.get_list_members(list_id=test_list_id)
def test_get_specific_list(self):
'''Test getting specific list succeeds'''
self.api.get_specific_list(list_id=test_list_id)
def test_get_list_subscriptions(self):
'''Test collection of the lists the specified user is
subscribed to succeeds'''
self.api.get_list_subscriptions(screen_name='twitter')
示例4: getResponses
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_list_members [as 别名]
cur.execute('SELECT responseTweetID, respondedToTweetID FROM Responders;' #isValid = 2 is for someone who's confirmed it NOT valid
)
count = 0
while count < numentries:
responseTweetID, respondedToTweetID = cur.fetchone()
if respondedToTweetID in alertids:
alertids[respondedToTweetID].append(responseTweetID)
else:
alertids[respondedToTweetID] = [responseTweetID]
count += 1
return alertids
potentialResponses= getResponses()
del potentialResponses[None]
kindnessResponders = twitter.get_list_members(slug='kindness-responders'
, owner_screen_name='weaware')
for p in kindnessResponders['users']:
timeline = twitter.get_user_timeline(screen_name=p['screen_name'],count=200, exclude_replies=False)
for t in timeline:
if (t['in_reply_to_status_id'] in potentialResponses):
print "the original tweet:" + str(t['in_reply_to_status_id'])
print "the tweet that is the response" + str(t['id'])
print "the event:" + str(potentialResponses[t['in_reply_to_status_id']])
positiveResponseText= twitter.show_status(id=t['id'])['text']
positiveResponseTime = twitter.show_status(id=t['id'])['created_at']
cur.execute("SELECT percentDamaged FROM Response ORDER BY timeAndDate DESC LIMIT 1;")
updatedDamageLevel = cur.fetchone()[0]+10
try:
print positiveResponseTime
cur.execute("INSERT INTO Response (percentDamaged, damageURL, positiveAction, timeAndDate, timePositive) VALUES (%s,'%s','%s','%s', '%s');" %
示例5: TwitterHelper
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_list_members [as 别名]
#.........这里部分代码省略.........
self.identity.statistics.record_retweet()
except TwythonError as ex:
if "You have already retweeted this tweet" in str(ex):
logger.warning(ex)
else:
raise
@retry(**retry_args)
def add_user_to_list(self, list_id, user_id, screen_name):
self.twitter.create_list_members(list_id=list_id, user_id=user_id, screen_name=screen_name)
@retry(**retry_args)
def block_user(self, user_id, user_screen_name=None):
self.twitter.create_block(user_id=user_id, screen_name=user_screen_name)
@retry(**retry_args)
def get_user_timeline(self, **kwargs):
return self._rate_limit("/statuses/user_timeline", self.twitter.get_user_timeline, **kwargs)
def unblock_user(self, user):
self.twitter.destroy_block(user_id=user.id, screen_name=user.screen_name)
@retry(**retry_args)
def unblock_users(self):
user_ids = self.twitter.list_block_ids(stringify_ids=True)
for user_id in user_ids["ids"]:
self.twitter.destroy_block(user_id=user_id)
@retry(**retry_args)
def show_owned_lists(self):
return self.twitter.show_owned_lists()["lists"]
@retry(**retry_args)
def get_list_members(self, list_id):
return self.twitter.get_list_members(list_id=list_id, count=5000, include_entities=False)
@blocked
@retry(**retry_args)
def create_list(self, **kwargs):
return self.twitter.create_list(**kwargs)
@retry(**retry_args)
def follow(self, user_id, screen_name):
logger.info("following user id {} @{}".format(user_id, screen_name))
self.twitter.create_friendship(user_id=user_id, screen_name=screen_name)
self.identity.statistics.increment("Follows")
@retry(**retry_args)
def unfollow(self, user_id, screen_name):
logger.info("unfollowing user id {} @{}".format(user_id, screen_name))
self.twitter.destroy_friendship(user_id=user_id, screen_name=screen_name)
self.identity.statistics.increment("Unfollows")
@retry(**retry_args)
def block(self, user_id, screen_name):
logger.info("blocking user id {} @{}".format(user_id, screen_name))
self.twitter.create_block(user_id=user_id, screen_name=screen_name)
self.identity.statistics.increment("Blocks")
@retry(**retry_args)
def report(self, user_id, screen_name):
logger.info("reporting user id {} @{}".format(user_id, screen_name))
self.twitter.report_spam(user_id=user_id, screen_name=screen_name)
self.identity.statistics.increment("Reports")
@retry(**retry_args)
示例6: TwythonAPITestCase
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_list_members [as 别名]
#.........这里部分代码省略.........
self.api.update_list(list_id=list_id, name='Stuff Renamed')
screen_names = ['johncena', 'xbox']
# Multi add/delete members
self.api.create_list_members(list_id=list_id,
screen_name=screen_names)
self.api.delete_list_members(list_id=list_id,
screen_name=screen_names)
# Single add/delete member
self.api.add_list_member(list_id=list_id, screen_name='justinbieber')
self.api.delete_list_member(list_id=list_id, screen_name='justinbieber')
self.api.delete_list(list_id=list_id)
def test_get_list_subscribers(self):
"""Test list of subscribers of a specific list succeeds"""
self.api.get_list_subscribers(list_id=test_list_id)
def test_subscribe_is_subbed_and_unsubscribe_to_list(self):
"""Test subscribing, is a list sub and unsubbing to list succeeds"""
self.api.subscribe_to_list(list_id=test_list_id)
# Returns 404 if user is not a subscriber
self.api.is_list_subscriber(list_id=test_list_id,
screen_name=screen_name)
self.api.unsubscribe_from_list(list_id=test_list_id)
def test_is_list_member(self):
"""Test returning if specified user is member of a list succeeds"""
# Returns 404 if not list member
self.api.is_list_member(list_id=test_list_id, screen_name='jack')
def test_get_list_members(self):
"""Test listing members of the specified list succeeds"""
self.api.get_list_members(list_id=test_list_id)
def test_get_specific_list(self):
"""Test getting specific list succeeds"""
self.api.get_specific_list(list_id=test_list_id)
def test_get_list_subscriptions(self):
"""Test collection of the lists the specified user is
subscribed to succeeds"""
self.api.get_list_subscriptions(screen_name='twitter')
def test_show_owned_lists(self):
"""Test collection of lists the specified user owns succeeds"""
self.api.show_owned_lists(screen_name='twitter')
# Saved Searches
def test_get_saved_searches(self):
"""Test getting list of saved searches for authenticated
user succeeds"""
self.api.get_saved_searches()
def test_create_get_destroy_saved_search(self):
"""Test getting list of saved searches for authenticated
user succeeds"""
saved_search = self.api.create_saved_search(query='#Twitter')
saved_search_id = saved_search['id_str']
self.api.show_saved_search(id=saved_search_id)
self.api.destroy_saved_search(id=saved_search_id)
# Places & Geo
示例7: Twython
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_list_members [as 别名]
while count < numentries:
alertids.append(cur.fetchone()[0])
count += 1
return alertids
#### This stuff connects us to twitter.com
APP_KEY = 'nope'
APP_SECRET = 'nope'
OAUTH_TOKEN = 'nope'
OAUTH_TOKEN_SECRET = 'nope'
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
peopleWhoCare = twitter.get_list_members(slug='iraq-car-bomb-admin-list',owner_screen_name='weaware')
alertedtweets = getAlertedTweets()
for p in peopleWhoCare['users']:
timeline = twitter.get_user_timeline(screen_name=p['screen_name'], count=200, exclude_replies=True)
retweets = list()
for t in timeline:
try:
if t['retweeted_status'] is not None:
retweets.append(t)
except KeyError:
print "Not a retweet"
for r in retweets:
if long(r['retweeted_status']['id']) in alertedtweets:
request = urllib2.Request(r['rewteeted_status']['entities']['urls'][0]['expanded_url'])
示例8: TwythonEndpointsTestCase
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_list_members [as 别名]
#.........这里部分代码省略.........
@unittest.skip('skipping non-updated test')
def test_get_list_statuses(self):
"""Test timeline of tweets authored by members of the
specified list succeeds"""
self.api.get_list_statuses(slug=test_list_slug,
owner_screen_name=test_list_owner_screen_name)
@unittest.skip('skipping non-updated test')
def test_create_update_destroy_list_add_remove_list_members(self):
"""Test create a list, adding and removing members then
deleting the list succeeds"""
the_list = self.api.create_list(name='Stuff %s' % int(time.time()))
list_id = the_list['id_str']
self.api.update_list(list_id=list_id, name='Stuff Renamed \
%s' % int(time.time()))
screen_names = ['johncena', 'xbox']
# Multi add/delete members
self.api.create_list_members(list_id=list_id,
screen_name=screen_names)
self.api.delete_list_members(list_id=list_id,
screen_name=screen_names)
# Single add/delete member
self.api.add_list_member(list_id=list_id, screen_name='justinbieber')
self.api.delete_list_member(list_id=list_id,
screen_name='justinbieber')
self.api.delete_list(list_id=list_id)
@unittest.skip('skipping non-updated test')
def test_get_list_memberships(self):
"""Test list of memberhips the authenticated user succeeds"""
self.api.get_list_memberships()
@unittest.skip('skipping non-updated test')
def test_get_list_subscribers(self):
"""Test list of subscribers of a specific list succeeds"""
self.api.get_list_subscribers(slug=test_list_slug,
owner_screen_name=test_list_owner_screen_name)
@unittest.skip('skipping non-updated test')
def test_subscribe_is_subbed_and_unsubscribe_to_list(self):
"""Test subscribing, is a list sub and unsubbing to list succeeds"""
self.api.subscribe_to_list(slug=test_list_slug,
owner_screen_name=test_list_owner_screen_name)
# Returns 404 if user is not a subscriber
self.api.is_list_subscriber(slug=test_list_slug,
owner_screen_name=test_list_owner_screen_name,
screen_name=screen_name)
self.api.unsubscribe_from_list(slug=test_list_slug,
owner_screen_name=test_list_owner_screen_name)
@unittest.skip('skipping non-updated test')
def test_is_list_member(self):
"""Test returning if specified user is member of a list succeeds"""
# Returns 404 if not list member
self.api.is_list_member(slug=test_list_slug,
owner_screen_name=test_list_owner_screen_name,
screen_name='themattharris')
@unittest.skip('skipping non-updated test')
def test_get_list_members(self):
"""Test listing members of the specified list succeeds"""