I made a Twitter fujoshi blocker with Python ①

Overview

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.

Twitter authentication

[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.

coding

With reference to here, I twisted and coded a fujoshi-like word.

logic

  1. This time, I want to make watching the road race comfortable, so first, search Twitter with "Yowamushi Pedal".
  2. Check the name and profile of the Tweet owner for the tweet that was caught.
  3. Block if your name or profile contains a "fujoshi-like word".

code

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)

Future improvements

  1. Convert to code that runs blockers on a regular basis on some server
  2. Create a UI to enter keywords to repel
  3. Providing as a service that runs on a browser

Finally

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

I made a Twitter fujoshi blocker with Python ①
I made a fortune with Python.
I made a daemon with Python
I made a Twitter BOT with GAE (python) (with a reference)
I made a character counter with Python
I made a Hex map with Python
I made a roguelike game with Python
I made a simple blackjack with Python
I made a configuration file with Python
I made a neuron simulator with Python
I made a competitive programming glossary with Python
I made a weather forecast bot-like with Python.
[Python] I made a Youtube Downloader with Tkinter.
I made a bin picking game with Python
I made a Mattermost bot with Python (+ Flask)
I made blackjack with python!
I made a python text
I made blackjack with Python.
I made wordcloud with Python.
I made a Christmas tree lighting game with Python
I made a net news notification app with Python
I made a Python3 environment on Ubuntu with direnv.
I made a LINE BOT with Python and Heroku
I made a simple typing game with tkinter in Python
I made a simple book application with python + Flask ~ Introduction ~
I made a puzzle game (like) with Tkinter in Python
I made a payroll program in Python!
I drew a heatmap with seaborn [Python]
I tried a functional language with Python
What I did with a Python array
I made a life game with Numpy
I made a stamp generator with GAN
After studying Python3, I made a Slackbot
Let's make a Twitter Bot with Python!
I made a WEB application with Django
I made a simple circuit with Python (AND, OR, NOR, etc.)
I made a package that can compare morphological analyzers with Python
I made a Nyanko tweet form with Python, Flask and Heroku
I made a lot of files for RDP connection with Python
I made a Twitter Bot with Go x Qiita API x Lambda
[Python] I made an image viewer with a simple sorting function.
I made a shuffle that can be reset (reverted) with Python
I made a poker game server chat-holdem using websocket with python
I made a segment tree with python, so I will introduce it
I made a program to collect images in tweets that I liked on twitter with Python
I made a stamp substitute bot with line
I made a python dictionary file for Neocomplete
〇✕ I made a game
Make a Twitter trend bot with heroku + Python
I made a tool to automatically browse multiple sites with Selenium (Python)
I want to make a game with Python
Procedure for creating a LineBot made with Python
I made a simple Bitcoin wallet with pycoin
I made a LINE Bot with Serverless Framework!
I tried to discriminate a 6-digit number with a number discrimination application made with python
Steps to create a Twitter bot with python
I made a tool that makes decompression a little easier with CLI (Python3)
I made a random number graph with Numpy
I want to write to a file with Python
I made a Caesar cryptographic program in Python.
I made a Python Qiita API wrapper "qiipy"