[PYTHON] [Stada] A script that will call you when Pokemon GO is released

Pokemon GO whirlwinds are happening all over the world. I wrote a script for lunch that will call you as soon as the Japanese version of Pokemon GO is released. This is the fastest Pokemon get (・ ㅂ ・) و

スクリーンショット 2016-07-15 15.08.00.png

architecture

Get status by polling itunes page via HTTP communication + Call with Twilio

Survey of the current situation of Pokémon GO

When I checked Niantic's Pokemon Official HP on July 15, the iOS version has not been released, and the Android version has already been released. The Android version is filtered on the software side and it seems that Japanese users cannot play it.

Detected when itunes page opens

appstore.py


# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
import requests


def app_store_is_open(_id):
    """
True if the Japanese App Store is open
    :param _id: str
    :rtype: bool
    """
    headers = {'Content-type': 'application/json; charset=utf-8'}
    url_base = "https://itunes.apple.com/jp/app/apple-store/{}?ct=official&mt=8"
    url = url_base.format(_id)
    response = requests.get(url, headers=headers)
    assert response.status_code == 200  #HTTP Status is 200
    return "Customer reviews" in response.text  #There is a customer review item for open apps

ids = {
    "POKEMON GO": "id1094591345",
    "White cat": "id895687962",
    "Puzzle": "id493470467",
    "Granblue fantasy": "id852882903",
}

for k, v in ids.items():
    print("{}: {}".format(k, app_store_is_open(v)))

Execution result


$ python appstore.py
Granblue fantasy: True
POKEMON GO: False
Puzzle: True
White cat: True

Make a phone call with Twilio

In Japan, we make calls using the Twilio API, a telephone-related venture that is developing in collaboration with AU.

tel.py


# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from twilio.rest import TwilioRestClient

ACCOUNT_SID = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
AUTH_TOKEN = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"

FROM_CALL_NUMBER = "819012341234"
TO_CALL_NUMBER = "819012341234"

client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
call = client.calls.create(to=TO_CALL_NUMBER, from_=FROM_CALL_NUMBER,
                           url="http://foo.com/call.xml")
print call.sid

Execution result


$ python tel.py
CA8b5ea1f08503ee8efc6aXXXXXXXX

I got a call. The phone keeps vibrating for about 30 seconds. upload_thumb.png

Finished product

Combine the two scripts to complete the script that will call you when the App Store version of Pokemon GO is released.

poke_check.py


# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
import requests
from twilio.rest import TwilioRestClient


def app_store_is_open(_id):
    """
True if the Japanese App Store is open
    :param _id: str
    :rtype: bool
    """
    headers = {'Content-type': 'application/json; charset=utf-8'}
    url_base = "https://itunes.apple.com/jp/app/apple-store/{}?ct=official&mt=8"
    url = url_base.format(_id)
    response = requests.get(url, headers=headers)
    assert response.status_code == 200  #HTTP Status is 200
    return "Customer reviews" in response.text


def tel():
    ACCOUNT_SID = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    AUTH_TOKEN = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"

    FROM_CALL_NUMBER = "819012341234"
    TO_CALL_NUMBER = "819012341234"

    client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
    call = client.calls.create(to=TO_CALL_NUMBER, from_=FROM_CALL_NUMBER,
                               url="http://foo.com/call.xml")


def start():
    print("start")
    pokemon_go = "id1094591345"
    if app_store_is_open(pokemon_go):
        print("OPEN")
        tel()
    else:
        print("NOT OPEN")


if __name__ == '__main__':
    start()

Execution result


$ python poke_check.py 
start
NOT OPEN

I hope it opens soon

Postscript

There are people who are doing the same thing ... http://qiita.com/touyoubuntu/items/af5d8e9e69e099945da1

Recommended Posts

[Stada] A script that will call you when Pokemon GO is released
Make a guy who will notify you when Oniken is on sale
It is a piggybacking story about the service that returns "Nyan" when you ping
What's in that variable (when running a Python script)
A shell script that numbers duplicate names when creating files
A memorandum that you will often use in Python's Selenium
Write a script in Shell and Python to notify you in Slack when the process is finished
What is a system call
Determine if standard output is piped when running a Python script