importurllib.parseimportrequestsimportmysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="**",database="flightdata")mycursor=mydb.cursor()main_api='https://www.sydneyairport.com.au/_a/flights/?query=&flightType=departure&terminalType=domestic&date=2019-11-10&sortColumn=scheduled_time&ascending=true&showAll=true'address='lhr'url=main_api+urllib.parse.urlencode({address:address})response_data=requests.get(url).json()forelementinresponse_data['flightData']:flight_id=element['id']airline=element['airline']destination=element['destinations']flightNumbers=element['flightNumbers']scheduledTime=element['scheduledTime']estimatedTime=element['estimatedTime']scheduledDate=element['scheduledDate']latestTime=element['latestTime']status=element['status']statusColor=element['statusColor']sql="INSERT INTO flightinfo (id, airline, destinations, flightNumbers, scheduledTime, estimatedTime, scheduledDate, latestTime, status, statusColor) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"#sql = "INSERT INTO flightinfo (flight_id, airline, destination, flightNumbers, scheduledTime, estimatedTime, estimatedTime, scheduledDate, latestTime, status, statusColor ) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s ,%s))"val=[(flight_id,airline," ".join(destination),", ".join(flightNumbers),scheduledTime,estimatedTime,scheduledDate,latestTime,status,statusColor)]mycursor.executemany(sql,val)mydb.commit()print(mycursor.rowcount,"was inserted.")print(airline,destination,flightNumbers,scheduledTime,"Estimated Time:"+" "+estimatedTime,"Scheduled Date:"+" "+scheduledDate,"Latest Time:"+" "+latestTime,"Status:"+" "+status,"Status Color:"+" "+statusColor)