Skip to content

Commit

Permalink
Correcting update when pokemon spawns in raid
Browse files Browse the repository at this point in the history
  • Loading branch information
sebast1219 committed Jun 27, 2017
1 parent c843568 commit 1aeba9a
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions monocle/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,13 +558,13 @@ def add_raid_sighting(session, raw_raid):
fort = session.query(Fort) \
.filter(Fort.external_id == raw_raid['external_id']) \
.first()
if fort.id and session.query(exists().where(and_(
RaidSighting.fort_id == fort.id,
RaidSighting.raid_spawn_ms == raw_raid['raid_spawn_ms'],
RaidSighting.pokemon_id != raw_raid['pokemon_id']
))).scalar():
#Update pokemon_id etc.
update_raid(session,fort.id,raw_raid)
raid = session.query(RaidSighting) \
.filter(RaidSighting.raid_seed == raw_raid['raid_seed']) \
.filter(RaidSighting.raid_spawn_ms == raw_raid['raid_spawn_ms']) \
.first()

if raid and raid.pokemon_id == None and raw_raid['pokemon_id'] != None:
update_raid(session,raw_raid)
if fort.id and session.query(exists().where(and_(
RaidSighting.fort_id == fort.id,
RaidSighting.raid_spawn_ms == raw_raid['raid_spawn_ms']
Expand Down Expand Up @@ -890,24 +890,26 @@ def get_all_spawn_coords(session, pokemon_id=None):
points = points.filter(Sighting.expire_timestamp > SINCE_TIME)
return points.all()

def update_raid(session, fort_id, raw):
def update_raid(session, raw):
query = session.execute('''
UPDATE fort_raids
SET
pokemon_id = '{pokemon_id}',
cp = '{cp}',
move_1 = '{move_1}',
move_2 = '{move_2}'
move_2 = '{move_2}',
notifDiscord = NULL
WHERE
fort_id = {fort_id}
raid_seed = {raid_seed}
AND raid_spawn_ms = {raid_spawn_ms}
'''.format(
fort_id=fort_id,
raid_seed=raw['raid_seed'],
raid_spawn_ms=raw['raid_spawn_ms'],
pokemon_id=raw['pokemon_id'],
cp=raw['cp'],
move_1=raw['move_1'],
move_2=raw['move_2'],
))
session.commit()

0 comments on commit 1aeba9a

Please sign in to comment.