Store indices of flights, not just count to make sure all landed flights are notified. Fixes #136

This commit is contained in:
Ville Ranki 2021-04-14 23:02:50 +03:00
parent 2cf1f75ec9
commit ef061deaa1
1 changed files with 7 additions and 4 deletions

View File

@ -17,6 +17,7 @@ class FlightBook:
'Helicopter', 'Parachute', 'Drop plane', 'Hang glider', \ 'Helicopter', 'Parachute', 'Drop plane', 'Hang glider', \
'Paraglider', 'Powered', 'Jet', 'UFO', 'Balloon', \ 'Paraglider', 'Powered', 'Jet', 'UFO', 'Balloon', \
'Airship', 'UAV', '?', 'Static object' ] 'Airship', 'UAV', '?', 'Static object' ]
self.logged_flights = dict() # station -> [index of flight]
def get_flights(self, icao): def get_flights(self, icao):
response = urllib.request.urlopen(self.base_url + "/logbook/" + icao) response = urllib.request.urlopen(self.base_url + "/logbook/" + icao)
@ -82,7 +83,7 @@ class MatrixModule(BotModule):
flights = data['flights'] flights = data['flights']
if len(flights) == 0 or (not station in self.logged_flights): if len(flights) == 0 or (not station in self.logged_flights):
self.logged_flights[station] = 0 self.logged_flights[station] = []
#print('Reset flight count for station ' + station) #print('Reset flight count for station ' + station)
# else: # else:
# print(f'Got {len(flights)} flights at {station}') # print(f'Got {len(flights)} flights at {station}')
@ -92,10 +93,11 @@ class MatrixModule(BotModule):
if flight["towing"]: if flight["towing"]:
continue continue
if flight["stop"]: if flight["stop"]:
if flightindex >= self.logged_flights[station]: if not flightindex in self.logged_flights[station]:
if not self.first_poll: if not self.first_poll:
await bot.send_text(bot.get_room_by_id(roomid), self.fb.flight2string(flight, data)) await bot.send_text(bot.get_room_by_id(roomid), self.fb.flight2string(flight, data))
self.logged_flights[station] = flightindex + 1 self.logged_flights[station].append(flightindex)
# print(f'Logged flights at {station} now {self.logged_flights[station]}')
flightindex = flightindex + 1 flightindex = flightindex + 1
self.first_poll = False self.first_poll = False
@ -116,6 +118,7 @@ class MatrixModule(BotModule):
await bot.send_text(room, f'Cleared OGN station for this room') await bot.send_text(room, f'Cleared OGN station for this room')
elif args[1] == 'status': elif args[1] == 'status':
print(self.logged_flights)
bot.must_be_admin(room, event) bot.must_be_admin(room, event)
await bot.send_text(room, f'OGN station for this room: {self.station_rooms.get(room.room_id)}, live updates enabled: {room.room_id in self.live_rooms}') await bot.send_text(room, f'OGN station for this room: {self.station_rooms.get(room.room_id)}, live updates enabled: {room.room_id in self.live_rooms}')