[PYTHON] I made a Twitter bot that mutters Pokemon caught by #PokemonGO

preface

Pokemon GO has finally launched in Japan: tada:

Overseas [Reverse engineering] pokemongo-android-re, [Kneading the internal API] pokemongo-map, Seems to be playing

Perhaps because of that, GitHub has a repository related to Pokemon GO.

... I have no choice but to play around with it!

Alright ** Make a Twitter bot that mutters Pokemon caught in Pokemon GO: exclamation :: exclamation: **

I made it with my thoughts

** Please try at your own risk **

3846masa/Tweet-PokemonGO-Journal

I'll put the code I wrote on GitHub

https://github.com/3846masa/Tweet-PokemonGO-Journal

When you move it, it looks like this

https://twitter.com/EBAGmasa_pokego

tejado/pgoapi

There were various library-like things that could hit the API, Somehow I chose [tejado / pgoapi]

Even Dockerfile is prepared, so you can play easily

policy

When you catch a Pokemon, it will be recorded in the Bouken Note (English name: Journal). In other words, it seems that you only need to get the data of the Boken notebook **

Boken notebook

Unfortunately there was no Journal example in tejado / pgoapi

When I searched for a function, I found [pgoapi.py # L107-L127].

def __getattr__(self, func):
    def function(**kwargs):
    
        if not self._req_method_list:
            self.log.info('Create new request...')
    
        name = func.upper()
        if kwargs:
            self._req_method_list.append( { RequestType.Value(name): kwargs } )
            self.log.info("Adding '%s' to RPC request including arguments", name)
            self.log.debug("Arguments of '%s': \n\r%s", name, kwargs)
        else:
            self._req_method_list.append( RequestType.Value(name) )
            self.log.info("Adding '%s' to RPC request", name)

        return self

    if func.upper() in RequestType.keys():
        return function
    else:
        raise AttributeError

If you follow RequestType.Value, You will reach [AeonLucid / POGOProtos --RequestType.proto]

Pokemon GO communication seems to use Protocol Buffers

Let's capture a packet to see what kind of data is actually flowing

Packet capture

For Android packet capture, refer to [here] android-packet

When I captured it, it looked like this

Looking at it somehow, I'm curious about the number 801.

If you search by [AeonLucid / POGOProtos --RequestType.proto], It seems to be SFIDA_ACTION_LOG

If you compare it with the code of tejado / pgoapi, I think I can get something with ʻapi.sfida_action_log () `

(By the way, POGOProtos in tejado / pgoapi at the moment is old, so let's replace it.)

api.sfida_action_log()

The execution result looks like this

{
  'api_url': ...,
  'auth_ticket': { ... },
  'request_id': ...,
  'responses': {
    'SFIDA_ACTION_LOG': {
      'log_entries': [{
        'catch_pokemon': {
          'combat_points': 156,
          'pokemon_id': 114,
          'result': 1
        },
        'timestamp_ms': 1469169999498
      }, {
        'fort_search': {
          'items': [{
            'count': 3,
            'item_id': 1
          }],
          'result': 1
        },
        'timestamp_ms': 1469233607913
      }],
      'result': 1
    }
  },
  'status_code': 2
}

Probably fort_search is the pocket stop information, catch_pokemon is probably the captured Pokemon information

All you have to do is make a Twitter bot with Zackri: muscle:

in conclusion

These private APIs have a strong impression of tampering with the game, I feel like I can do something interesting in the area of logging.

Of course, ** Don't put a load on the server: no_entry_sign: But ** Isn't it better to just play around with it?

Recommended Posts

I made a Twitter bot that mutters Pokemon caught by #PokemonGO
I made a Twitter BOT with GAE (python) (with a reference)
I made a discord bot
I made a LINE BOT that returns parrots with Go
I made a wikipedia gacha bot
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
Create a bot that boosts Twitter trends
I made a Discord bot in Python that translates when it reacts
I made a bot to post on twitter by web scraping a dynamic site with AWS Lambda (continued)
I made a stamp substitute bot with line
I made a Twitter fujoshi blocker with Python ①
I made a LINE Bot with Serverless Framework!
I made a Mattermost bot with Python (+ Flask)
I made a LINE BOT that returns a terrorist image using the Flickr API
A memo that I stumbled upon when doing a quote RT on Twitter Bot
I made a Line Bot that uses Python to retrieve unread Gmail emails!
I made a LINE Bot that sends recommended images every day on time
[Python] I made a LINE Bot that detects faces and performs mosaic processing.
[Discode Bot] I created a bot that tells me the race value of Pokemon
In Python, I made a LINE Bot that sends pollen information from location information.
I made a twitter app that decodes the characters of Pricone with heroku (failure)
[AWS] I made a reminder BOT with LINE WORKS
I made a LINE BOT with Python and Heroku
I made a system that allows you to tweet just by making a phone call
I made a program to collect images in tweets that I liked on twitter with Python
A story that stumbled when I made a chatbot with Transformer
I made a fucking app that won't let you skip
I made a rigid Pomodoro timer that works with CUI
When I made a Discord Bot, my classmates destroyed my computer
I made a plug-in that can "Daruma-san fell" with Minecraft
I made a neural network generator that runs on FPGA
[AWS] I made a reminder BOT with LINE WORKS (implementation)
I made a python text
I made a Line bot that guesses the gender and age of a person from an image
[Python3] I made a decorator that declares undefined functions and methods.
I made a simple network camera by combining ESP32-CAM and RTSP.
I made a program that solves the spot the difference in seconds
I made a shuffle that can be reset (reverted) with Python
I made a lo command that is more useful than ls
I made a library that adds docstring to a Python stub file.
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 made a program that automatically calculates the zodiac with tkinter
[python] I made a class that can write a file tree quickly
I started to work at different times, so I made a bot that tells me the time to leave
[Python] I made a bot that tells me the current temperature when I enter a place name on LINE
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 daemon with Python
I made a calendar that automatically updates the distribution schedule of Vtuber
[Python] I made a decorator that doesn't seem to have any use.
I made a web application in Python that converts Markdown to HTML
[Python] Created a Twitter bot that generates friend-like tweets using Markov chains
I made a plug-in "EZPrinter" that easily outputs map PDF with QGIS.
[Python] I made a utility that can access dict type like a path
I made a program to notify you by LINE when switches arrive
I made a Chrome extension that displays a graph on an AMeDAS page
I made a simple timer that can be started from the terminal