Advertisement
Guest User

Python Webshop

a guest
Mar 1st, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.42 KB | None | 0 0
  1. Here is my second try on making a decent command based webstore
  2. #Import csv module
  3. import csv
  4.  
  5. #Putting al my variables on 0
  6.  
  7.  
  8. Quantity_R9_380X = 0
  9. Quantity_R9_390 = 0
  10. Quantity_R9_390X = 0
  11. Quantity_GTX_960 = 0
  12. Quantity_GTX_970 = 0
  13. Quantity_GTX_980 = 0
  14. Quantity_GTX_980_TI = 0
  15. Cost_R9_380X = 0
  16. Cost_R9_390 = 0
  17. Cost_R9_390X = 0
  18. Cost_GTX_960 = 0
  19. Cost_GTX_970 = 0
  20. Cost_GTX_980 = 0
  21. Cost_GTX_980_TI = 0
  22. Add_Product = 0
  23. Add_Product_Choice = 0
  24. TotalCost = 0
  25. ShippingCosts = 0
  26. Remain_For_Shipping = 0
  27. Wrong_Password_Count = 0
  28.  
  29.  
  30. print('Thanks for shopping at our webshop')
  31. print('If you forget what command to use type /help')
  32. print'\n'
  33. print('If you would like to see a list of the products we have in stock type /products')
  34.  
  35. print('To order enter the name listed before the quotation marks')
  36.  
  37. Add_Product = raw_input('Would you like to add a product to your shopping list? ').upper()
  38. #If the customers enters a random string
  39. while Add_Product != '/PRODUCTS' and Add_Product != 'YES' and Add_Product != 'NO' and Add_Product != '/ADMIN':
  40. print('Please type "Yes", "No", or if you want to see the list of products type "/products" ')
  41. Add_Product = raw_input('Would you like to add a product to your shopping list? ').upper()
  42.  
  43. #Going into the admin menu
  44. if Add_Product == '/ADMIN' :
  45. Admin_Username = raw_input('Please enter your username ')
  46. Admin_Password = raw_input('Please enter the admin password ')
  47. while (Admin_Password != 'ThisPasswordIsSafe' or Admin_Username != 'PeterPluim') and Wrong_Password_Count <= 2:
  48. print('Wrong password or username, please try again')
  49. Wrong_Password_Count = Wrong_Password_Count + 1
  50. print Wrong_Password_Count
  51. Admin_Username = raw_input('Please enter your username ')
  52. Admin_Password = raw_input('Please enter the admin password ')
  53. if Wrong_Password_Count > 2 :
  54. print('You have entered a wrong password 3 times, you are not able to login for 24 hours')
  55. if Admin_Password == 'ThisPasswordIsSafe' and Admin_Username == 'PeterPluim':
  56. print('\n')
  57. print('Login succefull')
  58. print('You have the following options')
  59. print('"/revenue" ----> See the total revenue')
  60. print('"/totalshipping" ----> Show the total cost of shipping we have had to pay')
  61. print('"/ShippingDestination" ----> Show how many packages are sent to the homeland and how many to other countries')
  62. CommandExecute = raw_input('Would you like to execute a command? ').upper()
  63. while CommandExecute == 'YES' :
  64. Admin_Choice = raw_input('What command would you like to execute').upper()
  65. if Admin_Choice == '/revenue' :
  66. reader = csv.reader(open("orderlist.csv"), delimiter=';')
  67. data = []
  68. for row in reader:
  69. data.append(row)
  70. print ('$') + data[999][4]
  71. CommandExecute = raw_input('Would you like to execute a command? ').upper()
  72. if Admin_Choice == '/totalshipping' :
  73. reader = csv.reader(open("orderlist.csv"), delimiter=';')
  74. data = []
  75. for row in reader:
  76. data.append(row)
  77. print ('$') + data[999][5]
  78. CommandExecute = raw_input('Would you like to execute a command? ').upper()
  79. #Show the product list
  80. if Add_Product == '/PRODUCTS' :
  81. print'\n'
  82. print('At the moment we have the following product in stock')
  83. print('R9 380X "Amd R9 380X off the brand sapphire" ')
  84. print('R9 390 "Amd R9 390 off the brand XFX" ')
  85. print('R9 390x "AMD R9 390X off the brand MSI"')
  86. print('GTX 960 "Nvidia GTX 960 off the brand MSI" ')
  87. print('GTX 970 "Nvidia GTX 970 off the brand Gigabyte" ')
  88. print('GTX 980 "Nvidia GTX 980 off the brand MSI" ')
  89. print('GTX 980 ti "Nvidia GTX 980 ti off the brand MSI" ')
  90.  
  91. Add_Product = raw_input('Would you like to add a product to your shopping list? ').upper()
  92. while Add_Product == 'YES' :
  93. Add_Product_Choice = raw_input('What product would you like to add? ').upper()
  94. if Add_Product_Choice == 'R9 380X' :
  95. Quantity_R9_380X = raw_input('How many would you like to order? ').upper()
  96. Cost_R9_380X = int(Quantity_R9_380X)*240
  97. TotalCost = TotalCost + int(Cost_R9_380X)
  98. Add_Product = raw_input('Would you like to add a product to your shopping list? ').upper()
  99. with open('orderlist.csv', 'ab') as csvfile:
  100. writer = csv.writer(csvfile, delimiter= ";")
  101. writer.writerow(['R9 380X', Quantity_R9_380X])
  102. elif Add_Product_Choice == 'R9 390':
  103. Quantity_R9_390 = raw_input('How many would you like to order? ').upper()
  104. Cost_R9_390 = int(Quantity_R9_390)*330
  105. TotalCost = TotalCost + int(Cost_R9_390)
  106. Add_Product = raw_input('Would you like to add a product to your shopping list? ').upper()
  107. with open('orderlist.csv', 'ab') as csvfile:
  108. writer = csv.writer(csvfile, delimiter= ";")
  109. writer.writerow(['R9 390', Quantity_R9_390])
  110. elif Add_Product_Choice == 'R9 390X':
  111. Quantity_R9_390X = raw_input('How many would you like to order? ').upper()
  112. Cost_R9_390X = int(Quantity_R9_390X)*430
  113. TotalCost = TotalCost + int(Cost_R9_390X)
  114. Add_Product = raw_input('Would you like to add a product to your shopping list? ').upper()
  115. with open('orderlist.csv', 'ab') as csvfile:
  116. writer = csv.writer(csvfile, delimiter= ";")
  117. writer.writerow(['R9 390X', Quantity_R9_390X])
  118. elif Add_Product_Choice == 'GTX 960':
  119. Quantity_GTX_960 = raw_input('How many would you like to order? ').upper()
  120. Cost_GTX_960 = int(Quantity_GTX_960)*205
  121. TotalCost = TotalCost + int(Cost_GTX_960)
  122. Add_Product = raw_input('Would you like to add a product to your shopping list? ').upper()
  123. with open('orderlist.csv', 'ab') as csvfile:
  124. writer = csv.writer(csvfile, delimiter=";")
  125. writer.writerow(['GTX 960', Quantity_GTX_960])
  126. elif Add_Product_Choice == 'GTX 970':
  127. Quantity_GTX_970 = raw_input('How many would you like to order? ').upper()
  128. Cost_GTX_970 = int(Quantity_GTX_970)*330
  129. TotalCost = TotalCost + int(Cost_GTX_970)
  130. Add_Product = raw_input('Would you like to add a product to your shopping list? ').upper()
  131. with open('orderlist.csv', 'ab') as csvfile:
  132. writer = csv.writer(csvfile, delimiter=";")
  133. writer.writerow(['GTX 970', Quantity_GTX_970])
  134. elif Add_Product_Choice == 'GTX 980':
  135. Quantity_GTX_980 = raw_input('How many would you like to order? ').upper()
  136. Cost_GTX_980 = int(Quantity_GTX_980)*510
  137. TotalCost = TotalCost + int(Cost_GTX_980)
  138. Add_Product = raw_input('Would you like to add a product to your shopping list? ').upper()
  139. with open('orderlist.csv', 'ab') as csvfile:
  140. writer = csv.writer(csvfile, delimiter=";")
  141. writer.writerow(['GTX 980', Quantity_GTX_980])
  142. elif Add_Product_Choice == 'GTX 980 TI':
  143. Quantity_GTX_980_TI = raw_input('How many would you like to order? ').upper()
  144. Cost_GTX_980_TI = int(Quantity_GTX_980_TI)*740
  145. TotalCost = TotalCost + int(Cost_GTX_980_TI)
  146. Add_Product = raw_input('Would you like to add a product to your shopping list? ').upper()
  147. with open('orderlist.csv', 'ab') as csvfile:
  148. writer = csv.writer(csvfile, delimiter=";")
  149. writer.writerow(['GTX 980 ti', Quantity_GTX_980_TI])
  150. else :
  151. print("We don't have this product in stock at the moment")
  152.  
  153.  
  154.  
  155. #Done with product choosing, entering personal information, Calculating shipping costs
  156. #Writing information to csv file
  157. if Add_Product == 'NO':
  158. FirstName = raw_input('What is your first name? ')
  159. SurName = raw_input('What is your surname? ')
  160. Country = raw_input('What country do you live in? ').upper()
  161. Address = raw_input('What is your address? ')
  162.  
  163. #Shipment Netherlands
  164. if Country == 'THE NETHERLANDS' or Country == 'NETHERLANDS' or Country == 'NETHERLAND' or Country == 'HOLLAND':
  165. if TotalCost >= 250 :
  166. ShippingCosts = 0
  167. print("You don't have to pay any shipping fees")
  168. else :
  169. ShippingCosts = 6.95
  170. Remain_For_Shipping = 250 - TotalCost
  171. print('The shipping will cost you $6.95')
  172. print('Order for another $') + str(Remain_For_Shipping) + (' to get free shipping')
  173. else:
  174. if TotalCost >= 250 :
  175. ShippingCosts = 0
  176. print('You dont have to pay any shipping fees')
  177. else:
  178. ShippingCosts = 13.95
  179. Remain_For_Shipping = 250 - TotalCost
  180. print('The shipping will cost you $13.95')
  181. print('Order for another $') + str(Remain_For_Shipping) + (' to get free shipping')
  182. TotalCost = TotalCost + float(ShippingCosts)
  183. TotalProductCost= TotalCost - ShippingCosts
  184. print ('The total amount you have to pay is $') + str(TotalCost)
  185. with open('orderlist.csv', 'ab') as csvfile:
  186. writer = csv.writer(csvfile, delimiter= ";")
  187. writer.writerow([SurName, FirstName, Country, Address, float(TotalProductCost), float(ShippingCosts)])
  188. writer.writerow([' '])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement