asked on
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()
data = []
airline_spans = resp.html.find('.SearchResultFlightListRow')
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:
print (flight)
status = "IDEL"
print (status)
flightno, From, to, scheduled, estimated, gate = 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} ')
elif len(flight) == 5:
flightno, From, to, scheduled, estimated = flight
origin = str(From)
flight_id = str('na')
airline = str('na')
destination = str (to)
flightNumbers = str(flightno)
scheduledTime = str(scheduled)
estimatedTime = str(estimated)
scheduledDate = str('na')
latestTime = str(estimated)
status = str(status)
gate = str(gate)
print (From, flight_id, flightNumbers, airline, destination, scheduledTime, scheduledDate, latestTime, status, gate)
sql = "INSERT INTO flightinfo (origin, id, airline, destinations, flightNumbers, scheduledTime, estimatedTime, scheduledDate, latestTime, status, gate) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s. %s)"
val = (origin, flight_id, airline, destination, flightNumbers, scheduledTime, estimatedTime, scheduledDate, latestTime, status, gate)
data.append(val)
# doing a batch insert
mycursor.executemany(sql, data)
mydb.commit()
print(mycursor.rowcount, "was inserted.")
ASKER
ASKER
ASKER
ASKER
SQL (Structured Query Language) is designed to be used in conjunction with relational database products as of a means of working with sets of data. SQL consists of data definition, data manipulation, and procedural elements. Its scope includes data insert, query, update and delete, schema creation and modification, and data access control.
TRUSTED BY
val = "{},{},{},{}....".format(o
data.append(val)