Skip to content

Commit

Permalink
Merge pull request #3 from AngeloGiacco/flight
Browse files Browse the repository at this point in the history
Flight
  • Loading branch information
AngeloGiacco authored Mar 30, 2020
2 parents 6f20fe8 + 0758a4d commit ffaa520
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
4 changes: 2 additions & 2 deletions honeybot/plugins/corona.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def scrape(self,country):
data = doc.find_all("td")
if country == "global":
most_affected = [] #each element is an array as follows [country,cases,deaths]
for index in range(0,37,9):
for index in range(0,45,11):
most_affected.append([str(data[index].text),str(data[index+1].text),str(data[index+3].text.strip())])
today = str(datetime.date.today())
msg = "The latest coronavirus pandemic figures as of "+today+" show "+\
Expand Down Expand Up @@ -68,7 +68,7 @@ def scrape(self,country):
}
if country in name_confusion:
country = name_confusion[country]
for index in range(0,len(data)-9,9):
for index in range(0,len(data)-11,11):
name = data[index].text
if data[index].text == country:
today = str(datetime.date.today())
Expand Down
70 changes: 70 additions & 0 deletions honeybot/plugins/flight.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-
"""
[flight.py]
Flight information plugin
[Author]
Angelo Giacco
[About]
returns flight information
[Commands]
>>> .flight <<flight callsign>>
"""

from datetime import datetime
import flightradar24 as fr24

class Plugin:
def __init__(self):
pass

def run(self, incoming, methods, info, bot_info):
try:
if info['command'] == 'PRIVMSG' and info['args'][1].split()[0] == '.flight':

if len(info['args'][1].split()) != 2: #check only callsign provided
methods["send"](info["address"], "Invalid input. Ensure callsign has no spaces. Try .ba778")

else:
fr = fr24.Api()
id = info["args"][1].split()[1]
flight = fr.get_flight(id)

if "errors" in flight: #check for api error
methods["send"](info["address"],"Invalid input! Callsign should not be more than 10 characters!")

else:
count = flight["result"]["response"]["item"]["current"] #get how many flights are recorded with callsign
if count == 0:
methods["send"](info["address"],"There are no flights with a corresponding callsign!")

else:
origin = flight["result"]["response"]["data"][0]["airport"]["origin"]["position"]["region"]["city"]
destination = flight["result"]["response"]["data"][0]["airport"]["destination"]["position"]["region"]["city"]
methods["send"](info["address"],"Flight " + id + " is from "+ origin + " to "+ destination+".")


total = 0
count = 0
for f in flight["result"]["response"]["data"]: #flight["result"]["response"]["data"] will hold a week long history of flights
if f["status"]["live"]:
methods["send"](info["address"],"This flight is currently in the air. The following information is available:")
methods["send"](info["address"],f["status"]["text"])

if f["time"]["other"]["duration"] != None:
total += f["time"]["other"]["duration"]
count += 1

avgDuration = total / count
mins = int(5 * round(float(avgDuration)/5)) #round to nearest five
hours = 0
while avg >= 60:
mins -= 60
hours += 1

methods["send"](info["address"],"The flight has an average duration of "+str(hours)+":"+str(mins)+".")

except Exception as e:
print('woops flight plugin error', e)
1 change: 1 addition & 0 deletions honeybot/settings/PLUGINS.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ debug
diary
dictionary
fact
flight
google
greet
hangman
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ google==2.0.2
beautifulsoup4==4.7.1
deuces==0.2
httplib2==0.13.1
flightradar24==0.2

0 comments on commit ffaa520

Please sign in to comment.