-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdatabase.py
More file actions
25 lines (22 loc) · 1.05 KB
/
database.py
File metadata and controls
25 lines (22 loc) · 1.05 KB
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
import csv
def read_data_from_csv(filename):
data = {}
with open(filename, newline='') as file:
reader = csv.reader(file)
next(reader) # To Skip header row
for row in reader:
data[row[0]] = int(row[1])
return data
def user_input_saver(order_id, Ordername, price_1, user_ip, total_price, us_name, us_state, us_dist, us_city, us_pin):
file_name = 'DataBase.csv'
with open(file_name, mode='a', newline='') as file:
writer = csv.writer(file)
if file.tell() == 0:
writer.writerow(['Order ID', 'Product', 'Price', 'Quantity', 'Amount', 'Customer Name', 'State', 'District', 'City', 'Pincode'])
writer.writerow([order_id, Ordername, price_1, user_ip, total_price, us_name, us_state, us_dist, us_city, us_pin])
def write_data_to_csv(filename, data):
with open(filename, mode='w', newline='') as file:
writer = csv.writer(file)
writer.writerow(['Product', 'Quantity'])
for product, quantity in data.items():
writer.writerow([product, quantity])