[PYTHON] I made a wikipedia gacha bot

Introduction

I'm a non-programmer, but I made a Twitter Bot because I wanted to make something myself. We hope that it will be helpful for beginners when creating bots.

What was made

It is a bot that randomly acquires two words from the words registered in wikipedia and tweets them. https://twitter.com/Sosaku_Tango スクリーンショット 2020-01-05 0.19.56.png

How to make

First, here is the completed code.

import tweepy, random
import schedule
import time

#Substitute each acquired key
CK=""
CS=""
AT=""
AS=""

#Instance creation
auth = tweepy.OAuthHandler(CK, CS)
auth.set_access_token(AT, AS)
api = tweepy.API(auth)

#Tweet two words from the downloaded wikipedia word list file
def bot():
    wiki_titles = open("jawiki-latest-all-titles-in-ns0.txt", "r")
    line = wiki_titles.readlines()
    random_word = random.sample(line, 1)
    first_word = ''.join(random_word)
    random_word = random.sample(line, 1)
    second_word = ''.join(random_word)

    api.update_status('1.' + first_word + '2.' + second_word + '\Can you create with n? I'm looking forward to the completion. #Creative word')

#Regular execution
def main():
    schedule.every().day.at("10:00").do(bot)
    while True:
        schedule.run_pending()
        time.sleep(1)
main()
  1. For the basic method of creating TwitterBot using Tweepy, refer to here. https://qiita.com/tsc343/items/e51f412480ea8bf5619a

  2. Wikipedia word data (.txt) is downloaded from here. https://dumps.wikimedia.org/jawiki/

  3. Refer to here for the code that randomly extracts lines from the txt file. http://tksmd.hatenablog.com/entry/20090122/p1

  4. Refer to here for regular automatic execution. https://qiita.com/Kai-Suzuki/items/0c5c0e5cbdb4075fe482

  5. Completion. Thank you for your hard work.

Shokan

Until recently, I used to run it manually every day, but I often forgot it, so I put in the code for autorun. I took this opportunity to post for the first time on Qiita. Since there are no followers or likes, no one recognizes it, but if you are interested, I would be happy if you could see it once. If you notice anything, I would appreciate it if you could comment.

Recommended Posts

I made a wikipedia gacha bot
I made a discord bot
〇✕ I made a game
I made a stamp substitute bot with line
I made a LINE Bot with Serverless Framework!
I made a Mattermost bot with Python (+ Flask)
I made a python text
[AWS] I made a reminder BOT with LINE WORKS
I made a Twitter BOT with GAE (python) (with a reference)
I made a household account book bot with LINE Bot
I made a LINE BOT with Python and Heroku
I made a C ++ learning site
I made a Line-bot using Python!
I made a CUI-based translation script (2)
I made a fortune with Python.
I made a tool to create a word cloud from wikipedia
I made a CUI-based translation script
When I made a Discord Bot, my classmates destroyed my computer
I made a daemon with Python
[AWS] I made a reminder BOT with LINE WORKS (implementation)
[Python] I made a Line bot that randomly asks English words.
I made a Twitter bot that mutters Pokemon caught by #PokemonGO
I made a Twitter Bot with Go x Qiita API x Lambda
I made a slack bot that notifies me of the temperature
I made a Discord chat reading bot by imitating the appearance
I made a new AWS S3 bucket
I made a dash docset for Holoviews
I made a payroll program in Python!
I touched "Orator" so I made a note
I made a character counter with Python
Beginner: I made a launcher using dictionary
I made a conversation partner like Siri
I made a script to display emoji
I made a Hex map with Python
I made a life game with Numpy
I made a stamp generator with GAN
I made a browser automatic stamping tool.
After studying Python3, I made a Slackbot
I made a roguelike game with Python
I made a simple blackjack with Python
I made a configuration file with Python
I made a library for actuarial science
I made a WEB application with Django
I made a neuron simulator with Python
I made a Discord bot in Python that translates when it reacts
I made a python dictionary file for Neocomplete
I made a weather forecast bot-like with Python.
I made a spare2 cheaper algorithm for uWSGI
I made a useful tool for Digital Ocean
I made a GUI application with Python + PyQt5
I made my dog "Monaka Bot" with LineBot
I made a Twitter fujoshi blocker with Python ①
I made a crazy thing called typed tuple
[Python] I made a Youtube Downloader with Tkinter.
I made a router config collection tool Config Collecor
I made a simple Bitcoin wallet with pycoin
I made a downloader for word distributed expression
I made a tool to compile Hy natively
I made a tool to get new articles
I made a random number graph with Numpy
I made a peeping prevention product for telework.