[PYTHON] I made a script to say hello at my Koshien

I tried to automate a certain task in a browser game called "My Koshien" using Python. I don't use Python at all, so it's a beginner level code. Please note.

What is my Koshien

It is a high school baseball simulation game. Although it is a baseball game, the actual game is played by the CPU, and the player is mainly instructed as a manager. Points are required for this instruction, and among some points there is ** Passion PT **, which can be increased by greeting other schools (other players).

This time, I created a script to automate this greeting, so I would like to introduce it.

Library

The following Python libraries are used for automation.

To use Selenium, you need to download the Chrome Driver separately.

script

orekou.py


import random, urllib, requests
from bs4 import BeautifulSoup

def getSchoolURL():
    #Randomly select a district
    area_num = random.randint(1, 49)

    #Get school link information in a list
    html = urllib.request.urlopen("http://orekou.net/profile/school_list/" + str(area_num)).read()
    soup = BeautifulSoup(html)
    link_elem = soup.select(".sub_content a")

    #Randomly select one from the schools on the list
    school_num = random.randint(1, len(link_elem))
    school_url = "http://orekou.net" + link_elem[school_num-1].get("href")
    
    return school_url

greet.py


from selenium import webdriver
from selenium.webdriver.common.keys import Keys

import orekou

#Load an existing profile and generate a Chrome driver
options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=C:\\Users\\<username>\\AppData\\Local\\Google\\Chrome\\User Data")
chrome = webdriver.Chrome("./chromedriver_win32/chromedriver.exe", options=options)

#Open Chrome browser
chrome.execute_script("window.open('', '_brank');")

#Say hello to 100 randomly selected schools
for index in range(100):
    chrome.get(orekou.getSchoolURL())
    chrome.switch_to.window(chrome.window_handles[0])
    chrome.execute_script("document.getElementsByTagName('input')[2].click();")

chrome.quit()

Since you need to log in to the browser game, we have included a process to get an existing profile. The part above is different for each user, so please change it yourself. Since you can earn points by greeting ** up to ** 100 times **, the loop is repeated the same number of times.

result

It takes about 3 seconds to say hello to one school, so it takes ** about 5 minutes ** to finish 100 schools. Much faster than doing it manually!

Actually ...

If you apply for a practice match at another school, you can earn points more efficiently than greeting. .. .. I want to earn more points! !! If you are a crazy person, please try using the script.

Recommended Posts

I made a script to say hello at my Koshien
I made a script to display emoji
I made a script to put a snippet in README.md
I made a CUI-based translation script (2)
I made a CUI-based translation script
I changed my job to a machine learning engineer at AtCoder Jobs
[To Twitter gentlemen] I wrote a script to convert .jpg-large to .jpg at once.
I made a script in python to convert .md files to Scrapbox format
I made a tool to compile Hy natively
I wrote a script to upload a WordPress plugin
I made a tool to get new articles
I made a script to record the active window using win32gui of Python
〇✕ I made a game
I made my goimports
I made a library to separate Japanese sentences nicely
I made a Python module to translate comment outs
I made a code to convert illustration2vec to keras model
A story that I was addicted to at np.where
I made a command to markdown the table clipboard
I made a python library to do rolling rank
I made a script in Python to convert a text file for JSON (for vscode user snippet)
I made a tool to get the answer links of OpenAI Gym all at once
I made a package to filter time series with python
I made a box to rest before Pepper gets tired
I made my own language. (1)
I made a tool to create a word cloud from wikipedia
I made a function to check the model of DCGAN
I wrote a script to get a popular site in Japan
I wrote a script to combine the divided ts files
I made my own language (2)
I made my own AML
I made a surveillance camera with my first Raspberry PI.
When I made a Discord Bot, my classmates destroyed my computer
I made a discord bot
I made my own OSS because I wanted to contribute to it
[Titan Craft] I made a tool to summon a giant to Minecraft
I made you to execute a command from a web browser
I made a program to solve (hint) Saizeriya's spot the difference
I made a library to easily read config files with Python
I installed Taiga.IO on CentOS7 (I made a script while I was there)
Python> I made a test code for my own external file
I made a web server with Raspberry Pi to watch anime
I wanted to convert my face photo into a Yuyushiki style.
I wrote a script to get you started with AtCoder fast!
Don't you want to say that you made a face recognition program?
I just wrote a script to build Android on another machine
I wrote a function to load a Git extension script in Python
I stopped my instance at a specific time using AWS Lambda
I wrote a script to extract a web page link in Python
I made a library that adds docstring to a Python stub file.
I made a command to display a colorful calendar in the terminal
I wrote a script to help goodnotes5 and Anki work together
I made a C ++ learning site
I made a Line-bot using Python!
I made a wikipedia gacha bot
I made my own Python library
I made a daemon with Python
I made a POST script to create an issue on Github and register it in the Project
I started to work at different times, so I made a bot that tells me the time to leave
I made a Docker container to use JUMAN ++, KNP, python (for pyKNP).
I made a plugin to generate Markdown table from csv in Vim