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],'middlename': row[1].split(' ')[1], 'lastname': row[1].split(' ')[2]}
- 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],'middlename': row[1].split(' ')[1], 'lastname': row[1].split(' ')[2]}
- 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],'middlename': row[1].split(' ')[1], 'lastname': row[1].split(' ')[2]}
- csvfile.close()
- antwoord = 'ja'
- while antwoord == 'ja':
- l_w = len(user_data_workshop)
- l_s = len(user_data_simulation)
- l_r = len(user_data_reading)
- choice = int(input("Read (1) or Add (2)?"))
- if choice == 1:
- choice2 = int(input("From which section do you want to see the reservations? (workshop(1)/simulation(2)/reading(3))"))
- if choice2 == 1:
- with open('user_data_workshop.csv', 'r') as csv_file:
- file_contents = csv_file.read()
- print(file_contents.replace(',',' '))
- print("Er zijn nog", int(100) - l_w, "plekken vrij.")
- antwoord = input("Do you want to see another reservation?")
- csv_file.close()
- elif choice2 == 2:
- with open('user_data_simulation.csv', 'r') as csv_file:
- file_contents = csv_file.read()
- print(file_contents.replace(',',' '))
- print("Er zijn nog", int(100) - l_s, "plekken vrij.")
- csv_file.close()
- antwoord = input("Do you want to see another reservation?")
- elif choice2 == 3:
- with open('user_data_reading.csv', 'r') as csv_file:
- file_contents = csv_file.read()
- print(file_contents.replace(',',' '))
- print("Er zijn nog", int(100) - l_r, "plekken vrij.")
- csv_file.close()
- antwoord = input("Do you want to see another reservation?")
- else:
- print("Invalid option.")
- if choice == 2:
- print("Er zijn nog", int(100) - l_w, "plekken vrij bij de workshop, nog",int(100) - l_s,"bij de simulatie en",int(100) - l_r, "bij de lezing")
- 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?: "))
- if event_choice == 1 and int(100) - count - l_w == 0 or 2 and int(100) - count - l_s == 0 or 3 and int(100) - count - l_r == 0:
- antwoord = input("Uw geselecteerde keuze is vol wilt u een andere keuze maken? ")
- else:
- print("Enter the details for Person {}: ")
- name = input("Name: ")
- middlename = input("Middlename: ")
- lastname = input("Lastname: ")
- for i in range(count):
- if event_choice == 1:
- user_data_workshop[l_w+i+1] = {'name': name, 'middlename': middlename, 'lastname': lastname}
- elif event_choice == 2:
- user_data_simulation[l_s+i+1] = {'name': name, 'middlename': middlename, 'lastname': lastname}
- elif event_choice == 3:
- user_data_reading[l_r+i+1] = {'name': name, 'middlename': middlename, '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['middlename']+' '+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['middlename']+' '+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['middlename']+' '+value['lastname']])
- csv_file.close()
- antwoord = input("Do you make another reservation?")
- if choice == 3:
- print("mooie keuze")
- else:
- print("Ongeldige keuze")
Add Comment
Please, Sign In to add comment