Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: pogom/utils.py
- ===================================================================
- --- pogom/utils.py (revision 5c3b1bbc819097452f2ddc279bb16dbbc51000d9)
- +++ pogom/utils.py (revision )
- @@ -31,6 +31,7 @@
- parser.add_argument('-d', '--debug', type=str.lower, help='Debug Level [info|debug]', default=None)
- parser.add_argument('-c', '--pycurl', help='Use pycurl downloader (unstable)', action='store_true')
- + parser.add_argument('--pokel-pass', help='Password for Pokelizer database')
- args = parser.parse_args()
- if args.password is None:
- Index: pogom/postgres.py
- ===================================================================
- --- pogom/postgres.py (revision )
- +++ pogom/postgres.py (revision )
- @@ -0,0 +1,40 @@
- +from .utils import get_pokemon_name
- +from pogom.utils import get_args
- +from datetime import datetime
- +import psycopg2
- +import random
- +import logging
- +
- +args = get_args()
- +
- +conn = psycopg2.connect(dbname="pokemon_go", user="pokemon_go_role", password=args.pokel_pass, host="127.0.0.1")
- +conn.autocommit = True
- +cursor = conn.cursor()
- +
- +log = logging.getLogger(__name__)
- +
- +def logPokemonDb(p):
- + pokemon_id = int(p['pokemon_data']['pokemon_id'])
- + pokemon_name = get_pokemon_name(str(pokemon_id)).lower().encode('ascii','ignore')
- +
- + last_modified_time = int(p['last_modified_timestamp_ms'])
- + time_until_hidden_ms = int(p['time_till_hidden_ms'])
- +
- + hidden_time_unix_s = int((p['last_modified_timestamp_ms'] + p['time_till_hidden_ms']) / 1000.0)
- + hidden_time_utc = datetime.utcfromtimestamp(hidden_time_unix_s)
- +
- + encounter_id = str(p['encounter_id'])
- + spawnpoint_id = str(p['spawnpoint_id'])
- +
- + longitude = float(p['longitude'])
- + latitude = float(p['latitude'])
- + longitude_jittered = longitude + (random.gauss(0, 0.3) - 0.5) * 0.0005
- + latitude_jittered = latitude + (random.gauss(0, 0.3) - 0.5) * 0.0005
- +
- + query = "INSERT INTO spotted_pokemon (name, encounter_id, last_modified_time, time_until_hidden_ms, hidden_time_unix_s, hidden_time_utc, spawnpoint_id, longitude, latitude, pokemon_id, longitude_jittered, latitude_jittered) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);"
- + data = (pokemon_name, encounter_id, last_modified_time, time_until_hidden_ms, hidden_time_unix_s, hidden_time_utc, spawnpoint_id, longitude, latitude, pokemon_id, longitude_jittered, latitude_jittered)
- +
- + try:
- + cursor.execute(query, data)
- + except Exception,e:
- + log.error('Postgresql error (%s)', str(e))
- Index: pogom/models.py
- ===================================================================
- --- pogom/models.py (revision 5c3b1bbc819097452f2ddc279bb16dbbc51000d9)
- +++ pogom/models.py (revision )
- @@ -8,6 +8,7 @@
- from base64 import b64encode
- from .utils import get_pokemon_name
- +from .postgres import logPokemonDb
- db = SqliteDatabase('pogom.db', pragmas=(
- ('journal_mode', 'WAL'),
- @@ -112,7 +113,9 @@
- for p in cell.get('wild_pokemons', []):
- if p['encounter_id'] in pokemons:
- continue # prevent unnecessary parsing
- +
- + logPokemonDb(p)
- -
- +
- pokemons[p['encounter_id']] = {
- 'encounter_id': b64encode(str(p['encounter_id'])),
- 'spawnpoint_id': p['spawnpoint_id'],
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement