Touch around the twitter list with tweepy

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

Preparation

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.

Touch the list with tweepy

Immediately, I will touch around the list of twitter which is the main subject of this time.

Create / delete list

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 list

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.

Get users in the list

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)

in conclusion

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

Touch around the twitter list with tweepy
Specifying the date with the Twitter API
Play around with the pythonista3 ui module
Tweet from python with Twitter Developer + Tweepy
Search for Twitter keywords with tweepy and write the results to Excel
Tweet regularly with the Go language Twitter API
Hit the Twitter API after Oauth authentication with Django
I tried to touch the CSV file with Python
Crawl the URL contained in the twitter tweet with python
[Boto3] Search for Cognito users with the List Users API
Read the linked list in csv format with graph-tool
Predict the gender of Twitter users with machine learning
Twitter OAuth with Django
Get Tweets with Tweepy
Initialize list with python
Read the URL list with Robot Framework and surround the screenshots
Create a list in Python with all followers on twitter
[python] Decompose the acquired Twitter timeline into morphemes with MeCab
Let's touch the API of Netatmo Weather Station with Python. #Python #Netatmo
Streamline information gathering with the Twitter API and Slack bots
Create a Twitter BOT with the GoogleAppEngine SDK for Python
Touch NoSQL with Python using the Oracle NoSQL Database Cloud Simulator