Mute Twitter trends and have a comfortable Twitter life! !!

Isn't TL noisy?

Hi, this is Lily Mameoka. long time no see. I've always thought about it, but ** TL, isn't it noisy? ** ** When some animation is being broadcast (such as Sunday morning), when a major convenience store is campaigning, when a social network game is campaigning, when a millionaire or Youtuber is doing a gift campaign, ○ I don't know ... It's nice that TL is usually lively, but it's unpleasant that TL is noisy with the ** tweets that are useless to the viewer ** mentioned earlier. ~~ Filling the TL with a tweet that doesn't matter and fucking. ~~ Also, even though I came to Twitter to escape from reality, it's annoying to hear the ** THE ☆ secular ** words that weekly magazines handle ...

** I want to mute the trend word from one end ** and regain a peaceful TL ~~~~~~~~~~~~~~~! !! !! !!

Get trends

First, get the trend word. However, processing from all the trendwords mutes a significant amount of users (sorry for that), so I'd like to get only the ones with the hashtag!

get_trends.py


#!/usr/bin/env python
# -*- coding:utf-8 -*-

import tweepy

CONSUMER_KEY=''
CONSUMER_SECRET=''
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
ACCESS_TOKEN = ''
ACCESS_TOKEN_SECRET = ''
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)

def get_trends(api):
    trend = api.trends_place(23424856)[0]
    trends = trend['trends']
    print(u"Trends:")
    for i in range(len(trends)):
        print(u"\t{0}".format(trends[i]["name"]))

if __name__ == '__main__':
    api = tweepy.API(auth)
    get_trends(api)

When I do this ...

Trends:
	#Characters who want to see their swimsuits this summer
	#Kinnikuman animated
	#Predictive conversion from her reveals rear charge
	#What you want at Dosupara Spring Sale
	#Small class
	#Cash benefits
	#Well, Mr. Dai
	#Musica Piccolyno
	#Eight-chan's Tanjo Day Party
	#Diagnosis of your uncle
	#Kanjani 8TV
	#Kazumi Mobame
	#Layer the swimsuit on top of each other
	#Gracro capture question
	#Let's dance at home

Oh! It came out ~ ~ ~. This time we are focusing on Japanese trends, so the location ID is 23424856. When I looked it up, it seems that Tokyo is 1118370.

To a peaceful TL! !!

Well, the main subject.

I think **! ** The Twitter API does not support keyword mute. https://stackoverflow.com/questions/55916527/is-there-a-way-to-create-and-destroy-muted-words-using-the-twitter-api Hmm. it can not be helped. ** Mute the person who tweeted the word ☆ ** There is no choice but to make some sacrifices for the peace of my TL! Please forgive me ♡

trend_blocker.py


#!/usr/bin/env python
# -*- coding:utf-8 -*-

import tweepy

CONSUMER_KEY=''
CONSUMER_SECRET=''
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
ACCESS_TOKEN = ''
ACCESS_TOKEN_SECRET = ''
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)

mute_words = []

def get_trends(api):
    trend = api.trends_place(23424856)[0]
    trends = trend['trends']
    for i in range(len(trends)):
        if trends[i]["name"].startswith("#"):
            mute_words.append(trends[i]["name"])
    
def mute():
    api = tweepy.API(auth)
    get_trends(api)
    count = 1 #Enter the number of mutes you like in each word
    for mute_word in mute_words:
        print(mute_word)
        search_res = api.search(q = mute_word,count = count)
        for res in search_res:
            print(res.user.screen_name)
            api.create_mute(res.user.screen_name)
            print("--------------------------------------")

if __name__ == '__main__':
    mute()

Alright! !! !! Now you have a peaceful TL! That's great! ~~ Immediately, I will escape from reality with a comfortable TL ~ ~ ~ ~ ~ ~ ~ ~! !! ~~

Reference material

http://docs.tweepy.org/en/latest/index.html

Recommended Posts

Mute Twitter trends and have a comfortable Twitter life! !!
Live a typingless Twitter life with Alexa
Create a bot that boosts Twitter trends
Comfortable document life with Docutils and Ruby
Use a scripting language for a comfortable C ++ life
Get Twitter Trends