-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmanual-insert.py
45 lines (37 loc) · 1.41 KB
/
manual-insert.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import mysql.connector
import datetime
import csv
mydb = mysql.connector.connect(
host='localhost',
user='USERNAME',
password='PASSWORD',
database='google_flight'
)
mycursor = mydb.cursor()
# Uncomment these lines if this is the first time you upload the database
# companies = [("Vietnam Airlines", "VN"),
# ("Bamboo Airways", "QH"),
# ("Vietravel Airlines", "VU"),
# ("VietJet Air", "VJ"),
# ("Pacific Airlines", "BL")]
# for company in companies:
# sql = "INSERT INTO companies (name, code_name) values (%s, %s)"
# val = company
# mycursor.execute(sql, val)
# mydb.commit()
# Back-up add files from local CSV files
# current_date = datetime.datetime.now().strftime("%Y-%m-%d")
# with open('/Users/marcusle02/Documents/Learning/google_flight_etl/RT Flight Data/flight_data_2023-12-28.csv', 'r') as file:
# csv_data = csv.reader(file)
# next(csv_data) # Skip the header row
# for row in csv_data:
# # SQL query to insert data
# sql = """INSERT INTO flights (departure, arrival, date_leave, date_return,
# depart_time, arrive_time, company, price, scraping_date)
# VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)"""
# mycursor.execute(sql, row)
# # Commit the transaction
# mydb.commit()
# Close the cursor and connection
mycursor.close()
mydb.close()