from requests_html import HTMLSession
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="**",
database="flightdata"
)
mycursor = mydb.cursor()
# create an HTML Session object
session = HTMLSession()
# Use the object above to connect to needed webpage
resp = session.get("
https://www.adelaideairport.com.au/flight-information/flight-search/?flt_no=&carrier=All&city=&dte=Current&leg=Departures")
# Run JavaScript code on webpage
resp.html.render()
airline_spans = resp.html.find('.SearchRes
ultFlightL
istRow')
print (airline_spans)
airline_list = [span.text.split('\n') for span in airline_spans]
for flight in airline_list:
if len(flight) == 7:
flightno, From, to, scheduled, estimated, gate, status = flight
print ("This is a " + estimated)
if estimated == "":
print (" currently no dely ")
print ("This is a " + estimated)
estimated = 'IDEL'
print (f'Flight no {flightno} from {From} to {to} is scheduled to depart at {scheduled} from gate {gate} and flight status is {status}')
elif len(flight) == 6:
flightno, From, to, scheduled, estimated, gate = flight
status = 'IDEL'
print ("This is a " + estimated)
if estimated == "":
print (" currently no dely ")
print ("This is a " + estimated)
estimated = 'IDEL'
print (f'Flight no {flightno} from {From} to {to} is scheduled to depart at {scheduled} from gate {gate} ')
elif len(flight) == 5:
flightno, From, to, scheduled, estimated = flight
gate = 'IDEL'
status = 'IDEL'
print ("This is a " + estimated)
if estimated == "":
print (" currently no dely ")
print ("This is a " + estimated)
estimated = 'IDEL'
print (f'Flight no {flightno} from {From} to {to} is scheduled to depart at {scheduled} from gate ')
sql = "INSERT INTO flightinfo (origin, airline, destinations, flightNumbers, scheduledTime, estimatedTime, status) VALUES (str(From), str(to), str(flightno), str(scheduled), str(estimated), str(status), str(gate)"
val = (str(From), str(to), str(flightno), str(scheduled), str(estimated), str(status), str(gate))
#data.append(val)
print (val)
# doing a batch insert
#mycursor.executemany(sql,
val)
mycursor.executemany(sql,(
))
mydb.commit()
print(mycursor.rowcount, "was inserted.")