[PYTHON] I don't like to be frustrated with the release of Pokemon Go, so I made a script to detect the release and tweet it

result...

I detected the release on Twitter before the notification of my script came, and I ended up tweeting manually as usual. I tried running both my method and haminiku's method, but neither of them came to detect the release. Sorry ...

(It's not that it can't be detected completely, and now that it's ranked high in the search, it's gotcha firmly.)

Trigger

Looking at Twitter, it feels like it's about to be released in Japan, and various information is complicated and I have to search the App Store every time and repeat things that I do not want to do, which makes me angry. I was wondering if I could notify with a script.

Postscript: This article If released, link to my Twitter account (@touyoubuntu) I try to tweet. By all means! (Currently, I'm drinking sweat in the darkness of pyenv) β†’ Completed!

It took a while for the application to take effect, so it was difficult to check the test tweets, but it seems to be okay. Specifically, the following function is called at Gotcha below.

tweet.py


def tweet():
    twitter = OAuth1Session(CONSUMER_KEY, client_secret=CONSUMER_SECRET, resource_owner_key=ACCESS_TOKEN, resource_owner_secret=ACCESS_TOKEN_SECRET)
    params = {"status": "It seems that Pokemon Go has finally been released in Japan! http://itunes.apple.com/jp/app/pokemon-go/id1094591345?mt=8"}
    req = twitter.post("https://api.twitter.com/1.1/statuses/update.json", params=params)
    print req.status_code

How it works

Basically, iTunes Search API is used. I know that the developer is Niantic, Inc., so I copied the sellerName of Ingress and used it.

I search pokemon go once every 30 seconds (I'm scared because I haven't read the terms well) and look for Niantic, Inc. products in it.

pokemon_go_alert.py


import urllib
import urllib2
import json
import time

url = 'https://itunes.apple.com/search?term=pokemon+go&country=jp&media=software&entity=software&lang=ja_jp'

def func():
    while True:
        try:
            r = urllib2.urlopen(url)
            root = json.loads(r.read())
            for data in root['results']:
                if u'Niantic, Inc.' in data[u'sellerName']:
                    print "Gotcha!"
                    tweet()
                    return
            print "has not been released yet in Japan"
        finally:
            r.close()
        time.sleep(30.0)

func()

I didn't make it the main method. This will terminate the script if it displays has not been released yet or Gotcha! Every 30 seconds.

If you change this Gotcha part to tweet on Twitter and make the interval a little shorter, the fastest detection of Pokemon Go release is not a dream.

Summary

I wrote Python for the first time in a while. I think it was regrettable that there was no sellerUrl, which is said to be found in the iTunes API, in terms of improving accuracy.

Feel free to comment if you have any problems or suggestions for further improvements.

I wonder if Pokemon Go is still ...

reference

-Summary of how to use iTunes API -Get and parse json with python urllib2 -Create a delay-like waiting time with python -I was worried about Python's judgment of "whether the character string contains XX"

Postscript

There was a person doing the same thing by embedding the process of making a call lol [Stada] Script that will call you when Pokemon GO is released

People who let Slack be notified in Ruby Searching for Pokemon Go on iTunes is too painful, so I prepared crontab

It's really interesting that everyone makes articles at the same time lol

Recommended Posts

I don't like to be frustrated with the release of Pokemon Go, so I made a script to detect the release and tweet it
I made a function to crop the image of python openCV, so please use it.
I made a GAN with Keras, so I made a video of the learning process.
Script to tweet with multiples of 3 and numbers with 3 !!
I made a tool to notify Slack of Connpass events and made it Terraform
I made a script to record the active window using win32gui of Python
In IPython, when I tried to see the value, it was a generator, so I came up with it when I was frustrated.
I wanted to know the number of lines in multiple files, so I tried to get it with a command
I tried to make something like a chatbot with the Seq2Seq model of TensorFlow
How to test the current time with Go (I made a very thin library)
I made a function to check the model of DCGAN
I made a server with Python socket and ssl and tried to access it from a browser
I converted the time to an integer, factored it into prime factors, and made a bot to tweet the result (xkcd material)
I don't have a sense of "quiz asking investment sense", so I tried to solve it with brute force (Python Monte Carlo simulation)
I tried to expand the database so that it can be used with PES analysis software
Find the white Christmas rate by prefecture with Python and map it to a map of Japan
[Introduction to StyleGAN] I played with "The Life of a Man" ♬
I made a Nyanko tweet form with Python, Flask and Heroku
I made a segment tree with python, so I will introduce it
I made a chatbot with Tensor2Tensor and this time it worked
I tried to make a mechanism of exclusive control with Go
I made a LINE bot that tells me the type and strength of Pokemon in the Galar region with Heroku + Flask + PostgreSQL (Heroku Postgres)
I tried to take the difference of Config before and after work with pyATS / Genie self-made script
I ran GhostScript with python, split the PDF into pages, and converted it to a JPEG image.
I made an npm package to get the ID of the IC card with Raspberry Pi and PaSoRi
Upload data to s3 of aws with a command and update it, and delete the used data (on the way)
I don't want to admit it ... The dynamical representation of Neural Networks
[Django] I made a field to enter the date with 4 digit numbers
I made a kitchen timer to be displayed on the status bar!
[Introduction to docker / docker-compose] The new corona made my house longer, and I wanted to switch, but I couldn't buy it because of the reseller, so I made something that could be Mario.
I made a program to check the size of a file in Python
I made a mistake in fetching the hierarchy with MultiIndex of pandas
I made a function to see the movement of a two-dimensional array (Python)
I made a script to display emoji
I wanted to use the find module of Ansible2, but it took some time, so make a note
What I investigated in the process of expressing (schematicizing) containers in a nested frame with Jupyter and making it
[Python] Wouldn't it be the best and highest if you could grasp the characteristics of a company with nlplot?
Story of making a virtual planetarium [Until a beginner makes a model with a script and manages to put it together]
The tree.plot_tree of scikit-learn was very easy and convenient, so I tried to summarize how to use it easily.
Work memorandum (pymongo) Part 3. I don't want to look it up again, so make a note of it (aggregate)
I generated a lot of images like Google Calendar favicon with Python and incorporated it into Vue's project
I made a system that automatically decides whether to run tomorrow with Python and adds it to Google Calendar.
Function to extract the maximum and minimum values ​​in a slice with Go
I made a tool to estimate the execution time of cron (+ PyPI debut)
I made you to express the end of the IP address with L Chika
I want to write an element to a file with numpy and check it.
Specify the start and end positions of files to be included with qiitap
I made a system with Raspberry Pi that regularly measures the discomfort index of the room and sends a LINE notification if it is a dangerous value
I managed to do it because the custom of attaching a zip with a password to an email and saying "I will send you the password separately" is troublesome.
I made a tool to automatically back up the metadata of the Salesforce organization
I didn't understand the Resize of TensorFlow so I tried to summarize it visually.
I tried to create a model with the sample of Amazon SageMaker Autopilot
I set up TensowFlow and was addicted to it, so make a note
I'm tired of Python, so I tried to analyze the data with nehan (I want to go live even with corona sickness-Part 2)
I'm tired of Python, so I tried to analyze the data with nehan (I want to go live even with corona sickness-Part 1)
I made a twitter app that decodes the characters of Pricone with heroku (failure)
GradCAM with 22 lines of code. tf_explain may be easy to use, I recommend it!
I tried to scrape YouTube, but I can use the API, so don't do it.
I tried to notify the update of "Become a novelist" using "IFTTT" and "Become a novelist API"
I made a program to convert images into ASCII art with Python and OpenCV
It would be wise to write like boolean and "A" or "B" [Python] [But]