Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #workshop, simulation, reading
- from pathlib import Path
- import csv
- user_data_workshop = {}
- user_data_simulation = {}
- user_data_reading = {}
- workshop_file = Path('./user_data_workshop.csv')
- simulation_file = Path('./user_data_simulation.csv')
- reading_file = Path('./user_data_reading.csv')
- if workshop_file.is_file():
- with open('user_data_workshop.csv') as csvfile:
- readcsv = csv.reader(csvfile, delimiter=',')
- for row in readcsv:
- if(len(row) is not 0):
- user_data_workshop[row[0]] = {'name': row[1].split(' ')[0], 'lastname': row[1].split(' ')[1]}
- csvfile.close()
- if simulation_file.is_file():
- with open('user_data_simulation.csv') as csvfile:
- readcsv = csv.reader(csvfile, delimiter=',')
- for row in readcsv:
- if(len(row) is not 0):
- user_data_simulation[row[0]] = {'name': row[1].split(' ')[0], 'lastname': row[1].split(' ')[1]}
- csvfile.close()
- if reading_file.is_file():
- with open('user_data_reading.csv') as csvfile:
- readcsv = csv.reader(csvfile, delimiter=',')
- for row in readcsv:
- if(len(row) is not 0):
- user_data_reading[row[0]] = {'name': row[1].split(' ')[0], 'lastname': row[1].split(' ')[1]}
- csvfile.close()
- l_w = len(user_data_workshop)
- l_s = len(user_data_simulation)
- l_r = len(user_data_reading)
- event_choice = int(input("Which event do you want to make reservation for (workshop(1)/simulation(2)/reading(3))?: "))
- count = int(input("How many reservations do you want to make?: "))
- for i in range(count):
- print("Enter the details for Person {}: ".format(i+1))
- name = input("Name: ")
- lastname = input("Lastname: ")
- if event_choice == 1:
- user_data_workshop[l_w+i+1] = {'name': name, 'lastname': lastname}
- elif event_choice == 2:
- user_data_simulation[l_s+i+1] = {'name': name, 'lastname': lastname}
- elif event_choice == 3:
- user_data_reading[l_r+i+1] = {'name': name, 'lastname': lastname}
- else:
- print("Invalid option.")
- with open('user_data_workshop.csv', 'w') as csv_file:
- writer = csv.writer(csv_file)
- for key, value in user_data_workshop.items():
- writer.writerow([key, value['name']+' '+value['lastname']])
- csv_file.close()
- with open('user_data_simulation.csv', 'w') as csv_file:
- writer = csv.writer(csv_file)
- for key, value in user_data_simulation.items():
- writer.writerow([key, value['name']+' '+value['lastname']])
- csv_file.close()
- with open('user_data_reading.csv', 'w') as csv_file:
- writer = csv.writer(csv_file)
- for key, value in user_data_reading.items():
- writer.writerow([key, value['name']+' '+value['lastname']])
- csv_file.close()
Add Comment
Please, Sign In to add comment