Hellrocker

Untitled

Jan 10th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.00 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. l_w2 = len(user_data_workshop)
  99. l_s2 = len(user_data_simulation)
  100. l_r2 = len(user_data_reading)
  101. if event_choice == 1:
  102. if int(100) - l_w2 != 0:
  103. user_data_workshop[l_w+i+1] = {'name': name, 'middlename': middlename, 'lastname': lastname}
  104. else:
  105. print('full')
  106.  
  107. elif event_choice == 2:
  108. if int(100) - l_s2 != 0:
  109. user_data_workshop[l_w+i+1] = {'name': name, 'middlename': middlename, 'lastname': lastname}
  110. else:
  111. print('full')
  112. user_data_simulation[l_s+i+1] = {'name': name, 'middlename': middlename, 'lastname': lastname}
  113. elif event_choice == 3:
  114. if int(100) - l_r2 != 0:
  115. user_data_workshop[l_w+i+1] = {'name': name, 'middlename': middlename, 'lastname': lastname}
  116. else:
  117. print('full')
  118. user_data_reading[l_r+i+1] = {'name': name, 'middlename': middlename, 'lastname': lastname}
  119. else:
  120. print("Invalid option.")
  121.  
  122.  
  123. with open('user_data_workshop.csv', 'w') as csv_file:
  124. writer = csv.writer(csv_file)
  125. for key, value in user_data_workshop.items():
  126. writer.writerow([key, value['name']+' '+ value['middlename']+' '+value['lastname']])
  127. csv_file.close()
  128.  
  129. with open('user_data_simulation.csv', 'w') as csv_file:
  130. writer = csv.writer(csv_file)
  131. for key, value in user_data_simulation.items():
  132. writer.writerow([key, value['name']+' '+ value['middlename']+' '+value['lastname']])
  133. csv_file.close()
  134.  
  135. with open('user_data_reading.csv', 'w') as csv_file:
  136. writer = csv.writer(csv_file)
  137. for key, value in user_data_reading.items():
  138. writer.writerow([key, value['name']+' '+ value['middlename']+' '+value['lastname']])
  139. csv_file.close()
  140. antwoord = input("Do you make another reservation?")
  141. if choice == 3:
  142. print("mooie keuze")
  143. else:
  144. print("Ongeldige keuze")
Add Comment
Please, Sign In to add comment