Hellrocker

Untitled

Jan 10th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.46 KB | None | 0 0
  1. #workshop, simulation, reading
  2.  
  3. from pathlib import Path
  4. import csv
  5.  
  6. user_data_workshop = {}
  7. user_data_simulation = {}
  8. user_data_reading = {}
  9.  
  10. workshop_file = Path('./user_data_workshop.csv')
  11. simulation_file = Path('./user_data_simulation.csv')
  12. reading_file = Path('./user_data_reading.csv')
  13.  
  14.  
  15. if workshop_file.is_file():
  16. with open('user_data_workshop.csv') as csvfile:
  17. readcsv = csv.reader(csvfile, delimiter=',')
  18. for row in readcsv:
  19. if(len(row) is not 0):
  20. user_data_workshop[row[0]] = {'name': row[1].split(',')[0],'middlename': row[1].split(' ')[1], 'lastname': row[1].split(' ')[2]}
  21. csvfile.close()
  22.  
  23. if simulation_file.is_file():
  24. with open('user_data_simulation.csv') as csvfile:
  25. readcsv = csv.reader(csvfile, delimiter=',')
  26. for row in readcsv:
  27. if(len(row) is not 0):
  28. user_data_simulation[row[0]] = {'name': row[1].split(' ')[0],'middlename': row[1].split(' ')[1], 'lastname': row[1].split(' ')[2]}
  29. csvfile.close()
  30.  
  31. if reading_file.is_file():
  32. with open('user_data_reading.csv') as csvfile:
  33. readcsv = csv.reader(csvfile, delimiter=',')
  34. for row in readcsv:
  35. if(len(row) is not 0):
  36. user_data_reading[row[0]] = {'name': row[1].split(' ')[0],'middlename': row[1].split(' ')[1], 'lastname': row[1].split(' ')[2]}
  37. csvfile.close()
  38. antwoord = 'ja'
  39. while antwoord == 'ja':
  40.  
  41. l_w = len(user_data_workshop)
  42. l_s = len(user_data_simulation)
  43. l_r = len(user_data_reading)
  44.  
  45.  
  46. choice = int(input("Read (1) or Add (2)?"))
  47.  
  48. if choice == 1:
  49.  
  50. choice2 = int(input("From which section do you want to see the reservations? (workshop(1)/simulation(2)/reading(3))"))
  51.  
  52. if choice2 == 1:
  53. with open('user_data_workshop.csv', 'r') as csv_file:
  54. file_contents = csv_file.read()
  55. print(file_contents.replace(',',' '))
  56. print("Er zijn nog", int(100) - l_w, "plekken vrij.")
  57. antwoord = input("Do you want to see another reservation?")
  58. csv_file.close()
  59.  
  60.  
  61.  
  62. elif choice2 == 2:
  63. with open('user_data_simulation.csv', 'r') as csv_file:
  64. file_contents = csv_file.read()
  65. print(file_contents.replace(',',' '))
  66. print("Er zijn nog", int(100) - l_s, "plekken vrij.")
  67. csv_file.close()
  68.  
  69. antwoord = input("Do you want to see another reservation?")
  70.  
  71. elif choice2 == 3:
  72. with open('user_data_reading.csv', 'r') as csv_file:
  73. file_contents = csv_file.read()
  74. print(file_contents.replace(',',' '))
  75. print("Er zijn nog", int(100) - l_r, "plekken vrij.")
  76. csv_file.close()
  77.  
  78. antwoord = input("Do you want to see another reservation?")
  79.  
  80. else:
  81. print("Invalid option.")
  82.  
  83. if choice == 2:
  84. 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")
  85. event_choice = int(input("Which event do you want to make reservation for (workshop(1)/simulation(2)/reading(3))?: "))
  86. count = int(input("How many reservations do you want to make?: "))
  87.  
  88. 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:
  89. antwoord = input("Uw geselecteerde keuze is vol wilt u een andere keuze maken? ")
  90.  
  91. else:
  92. print("Enter the details for Person {}: ")
  93. name = input("Name: ")
  94. middlename = input("Middlename: ")
  95. lastname = input("Lastname: ")
  96.  
  97. for i in range(count):
  98. if event_choice == 1:
  99. user_data_workshop[l_w+i+1] = {'name': name, 'middlename': middlename, 'lastname': lastname}
  100. elif event_choice == 2:
  101. user_data_simulation[l_s+i+1] = {'name': name, 'middlename': middlename, 'lastname': lastname}
  102. elif event_choice == 3:
  103. user_data_reading[l_r+i+1] = {'name': name, 'middlename': middlename, 'lastname': lastname}
  104. else:
  105. print("Invalid option.")
  106.  
  107.  
  108. with open('user_data_workshop.csv', 'w') as csv_file:
  109. writer = csv.writer(csv_file)
  110. for key, value in user_data_workshop.items():
  111. writer.writerow([key, value['name']+' '+ value['middlename']+' '+value['lastname']])
  112. csv_file.close()
  113.  
  114. with open('user_data_simulation.csv', 'w') as csv_file:
  115. writer = csv.writer(csv_file)
  116. for key, value in user_data_simulation.items():
  117. writer.writerow([key, value['name']+' '+ value['middlename']+' '+value['lastname']])
  118. csv_file.close()
  119.  
  120. with open('user_data_reading.csv', 'w') as csv_file:
  121. writer = csv.writer(csv_file)
  122. for key, value in user_data_reading.items():
  123. writer.writerow([key, value['name']+' '+ value['middlename']+' '+value['lastname']])
  124. csv_file.close()
  125. antwoord = input("Do you make another reservation?")
  126. if choice == 3:
  127. print("mooie keuze")
  128. else:
  129. print("Ongeldige keuze")
Add Comment
Please, Sign In to add comment