Hi, this is @yushun_o. The software is available on yushun.me. Please have a look. I've been playing with tweepy recently, but I'm in trouble because there is less Japanese information around the twitter list than I expected, so I've summarized the places I'm likely to use. I will write the environment just in case.
Python 3.5.2
pip install tweepy
Install tweepy with
https://apps.twitter.com/ Get CONSUMER_KEY etc. by "Create New App" here
myauth.py
# -*- coding:utf-8 -*-
import tweepy
CONSUMER_KEY = "xxx"
CONSUMER_SECRET = "xxx"
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
ACCESS_TOKEN = "xxx"
ACCESS_SECRET = "xxx"
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
api = tweepy.API(auth)
You can now call the api at any time with from myauth import api
.
Immediately, I will touch around the list of twitter which is the main subject of this time.
create_destory_list.py
from myauth import api
screen_name="" #List creator@~~of~~
listname="" #List name
api.destroy_list(owner_screen_name=screen_name,slug=listname) #slug...Be careful when the list name is in Japanese*1
api.create_list(name="The name of the list you want to make",mode="public",description="Description") #mode is"public"Or"private"You can choose to make it public or private
get_all_list.py
from myauth import api
screen_name="" #List creator@~~of~~
for twilist in api.lists_all(screen_name=screen_name):
print("slug="+twilist.slug)
print("name="+twilist.name)
The slug and name of each List class are output. I only know how to identify the slug when listing Japanese names. (If you know, please let me know.) When working with lists in tweepy, it is recommended that you name the list in English.
The last way to get the users added to the list. Get it using tweepy's Cursor class.
get_member_of_list.py
from myauth import api
screen_name="" #List creator@~~of~~
listname="" #List name
for member in tweepy.Cursor(api.list_members,slug=listname,owner_screen_name=screen_name).items():
print(member.screen_name)
I think the only thing to note was the slug part. I can't touch everything around the list, so if this article isn't enough, please refer to the head family (github). https://github.com/tweepy/tweepy/blob/master/tweepy/api.py It was a poor article, but ** tweepy is really easy to use **, so please try it out.
Recommended Posts