I love road racing, so I've been suffering from the phenomenon that Fujoshi's Tweet gets caught just by following the official tag "#TDF" on Twitter for the past few years. TDF is over, but before Buerta, I wrote the code to block Fujoshi in Python, so I will share it.
[Here](http://website-planner.com/twitter%E3%82%A2%E3%83%97%E3%83%AA%E3%82%B1%E3%83%BC%E3%82% B7% E3% 83% A7% E3% 83% B3% E3% 81% AE% E4% BD% 9C% E6% 88% 90% EF% BC% 88consumer-key% E3% 80% 81consumer-secret% E3% 80% 81access-token% E3% 80% 81access-token-secret /), get Consumer key, Consumer secret, Access token, Access token secret.
With reference to here, I twisted and coded a fujoshi-like word.
Cramming code.
config.py
CONSUMER_KEY = "XXXX"
CONSUMER_SECRET = "XXXX"
ACCESS_TOKEN = "XXXX"
ACCESS_TOKEN_SECRET = "XXXX"
main.py
# -*- coding: utf-8 -*-
import json, config
from requests_oauthlib import OAuth1Session
CK = config.CONSUMER_KEY
CS = config.CONSUMER_SECRET
AT = config.ACCESS_TOKEN
ATS = config.ACCESS_TOKEN_SECRET
twitter = OAuth1Session(CK, CS, AT, ATS)
url = "https://api.twitter.com/1.1/search/tweets.json"
url_block = "https://api.twitter.com/1.1/blocks/create.json"
url_prof = "https://api.twitter.com/1.1/users/show.json"
NG_WORDS = 'BL', 'Rotten', 'Kitchen', 'CP', 'Kos', 'cos', 'Goods', 'bot', 'Adult'
params = {'q':'Yowamushi Pedal','count': 10, 'result_type' : 'recent'}
req = twitter.get(url, params = params)
if req.status_code == 200:
search_timeline = json.loads(req.text)
print(req.text)
for tweet in search_timeline['statuses']:
name = tweet['user']['name']
screen_name = tweet['user']['screen_name']
description = tweet['user']['description']
L = name+description
print(L)
if any(ng_word in L for ng_word in NG_WORDS):
print("Rotten")
print('----------------------------------------------------')
params2 = {'screen_name': screen_name}
twitter.post(url_block, params = params2)
else:
print("not rotten")
print('----------------------------------------------------')
else:
print("ERROR: %d" % req.status_code)
I would like to upload it here as soon as it can be improved. (So the title has ①) Those who help us are welcome. Thank you.
Recommended Posts