本文整理汇总了Python中twython.Twython.create_list_members方法的典型用法代码示例。如果您正苦于以下问题:Python Twython.create_list_members方法的具体用法?Python Twython.create_list_members怎么用?Python Twython.create_list_members使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twython.Twython
的用法示例。
在下文中一共展示了Twython.create_list_members方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import create_list_members [as 别名]
def main():
if 3 != len(sys.argv):
sys.stderr.write("""usage: %s <LIST> <FILE>
LIST : The name of the list you want to import members into.
FILE : A file with newline separated screen names.
""" % os.path.basename(sys.argv[0]))
exit(1)
with open('config.json', 'rb') as handle:
config = json.loads(handle.read())
list_name = sys.argv[1]
csv = sys.argv[2]
users = get_users(csv)
api = None
me = None
print "==> Loading %d users into \"%s\"" % (len(users), list_name)
if 'access' not in config or 'key' not in config['access'] or 'secret' not in config['access']:
config = authorize(config)
while True:
try:
api = Twython(config['consumer']['key'], config['consumer']['secret'],
config['access']['key'], config['access']['secret'])
me = api.verify_credentials()
break
except:
print "==> Existing tokens failed, re-authorizing"
config = authorize(config)
the_list = None
for obj in api.show_lists(user_id=me["id_str"]):
if obj["name"] == list_name:
the_list = obj
break
if not the_list:
print "==> List doesn't exist, creating it"
the_list = api.create_list(name=list_name)
offset = 0
while offset < len(users):
print "==> Sending #%d through #%d" % (offset, offset+100)
api.create_list_members(list_id=the_list["id_str"], screen_name=users[offset:offset+100])
offset += 100
print "==> Done!"
示例2: TwythonAPITestCase
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import create_list_members [as 别名]
#.........这里部分代码省略.........
'''Test getting status of suggested users succeeds'''
self.api.get_user_suggestions_statuses_by_slug(slug='funny')
# Favorites
def test_get_favorites(self):
'''Test getting list of favorites for the authenticated
user succeeds'''
self.api.get_favorites()
def test_create_and_destroy_favorite(self):
'''Test creating and destroying a favorite on a tweet succeeds'''
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):
示例3: Twython
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import create_list_members [as 别名]
Authored on 6 Aug 2013, M.Alam
"""
from twython import Twython, TwythonError
APP_KEY = ""
APP_SECRET = ""
OAUTH_TOKEN = ""
OAUTH_TOKEN_SECRET = ""
# Requires Authentication as of Twitter API v1.1
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
#Comma separated list of screen_names
screen_names=['']
#If not creating a list, obtain list_id for existing list
#qaclist_id=[]
'''try:
create_list=twitter.create_list(name='')
qaclist_id=create_list['id_str']
except TwythonError as e:
print e'''
#the above should be commented out if you are simply updating list members.
try:
update_list = twitter.create_list_members(list_id=,screen_name=screen_names)
except TwythonError as e:
print e
示例4: TwitterHelper
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import create_list_members [as 别名]
#.........这里部分代码省略.........
def delete_saved_searches(self):
searches = self.twitter.get_saved_searches()
for srch in searches:
self.twitter.destroy_saved_search(id=srch["id_str"])
def search(self, text, result_type="popular"):
query = quote_plus(text)
return self.twitter.search(q=query, result_type=result_type)["statuses"]
@retry(**retry_args)
def favourite(self, id_str):
try:
self.twitter.create_favorite(id=id_str)
self.identity.statistics.record_favourite()
except TwythonError as ex:
if "You have already favourited this tweet" in str(ex):
logger.warning(ex)
else:
raise
@retry(**retry_args)
def retweet(self, id_str):
try:
self.twitter.retweet(id=id_str)
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)
示例5: TwythonAPITestCase
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import create_list_members [as 别名]
#.........这里部分代码省略.........
self.api.get_user_suggestions_statuses_by_slug(slug='funny')
# Favorites
def test_get_favorites(self):
"""Test getting list of favorites for the authenticated
user succeeds"""
self.api.get_favorites()
def test_create_and_destroy_favorite(self):
"""Test creating and destroying a favorite on a tweet succeeds"""
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')
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):
示例6: print
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import create_list_members [as 别名]
if lt == 1:
try:
data = twitter.add_list_member(slug=listid, owner_screen_name=owner,
screen_name=target)
except TwythonError as e:
print(e)
data = None
if data is not None:
datacheck = True
else:
datacheck = False
elif lt >= 2 and lt <= 100:
targets = ", ".join(targety)
try:
data = twitter.create_list_members(slug=listid,
owner_screen_name=owner,
user_id=targets)
except TwythonError as e:
print(e)
data = None
if data is not None:
datacheck = True
else:
datacheck = False
elif lt > 100:
t0 = lt / 100
t1 = math.floor(t0)
t2 = t1 * 100
t3 = lt - t2
for i in range(t1):
targets = ", ".join(targety[(i * 100):((i + 1) * 100)])
示例7: TwythonEndpointsTestCase
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import create_list_members [as 别名]
#.........这里部分代码省略.........
self.api.get_favorites()
@unittest.skip('skipping non-updated test')
def test_create_and_destroy_favorite(self):
"""Test creating and destroying a favorite on a tweet succeeds"""
self.api.create_favorite(id=test_tweet_id)
self.api.destroy_favorite(id=test_tweet_id)
# Lists
@unittest.skip('skipping non-updated test')
def test_show_lists(self):
"""Test show lists for specified user"""
self.api.show_lists(screen_name='twitter')
@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,