Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Here is my second try on making a decent command based webstore
- #Import csv module
- import csv
- #Putting al my variables on 0
- Quantity_R9_380X = 0
- Quantity_R9_390 = 0
- Quantity_R9_390X = 0
- Quantity_GTX_960 = 0
- Quantity_GTX_970 = 0
- Quantity_GTX_980 = 0
- Quantity_GTX_980_TI = 0
- Cost_R9_380X = 0
- Cost_R9_390 = 0
- Cost_R9_390X = 0
- Cost_GTX_960 = 0
- Cost_GTX_970 = 0
- Cost_GTX_980 = 0
- Cost_GTX_980_TI = 0
- Add_Product = 0
- Add_Product_Choice = 0
- TotalCost = 0
- ShippingCosts = 0
- Remain_For_Shipping = 0
- Wrong_Password_Count = 0
- print('Thanks for shopping at our webshop')
- print('If you forget what command to use type /help')
- print'\n'
- print('If you would like to see a list of the products we have in stock type /products')
- print('To order enter the name listed before the quotation marks')
- Add_Product = raw_input('Would you like to add a product to your shopping list? ').upper()
- #If the customers enters a random string
- while Add_Product != '/PRODUCTS' and Add_Product != 'YES' and Add_Product != 'NO' and Add_Product != '/ADMIN':
- print('Please type "Yes", "No", or if you want to see the list of products type "/products" ')
- Add_Product = raw_input('Would you like to add a product to your shopping list? ').upper()
- #Going into the admin menu
- if Add_Product == '/ADMIN' :
- Admin_Username = raw_input('Please enter your username ')
- Admin_Password = raw_input('Please enter the admin password ')
- while (Admin_Password != 'ThisPasswordIsSafe' or Admin_Username != 'PeterPluim') and Wrong_Password_Count <= 2:
- print('Wrong password or username, please try again')
- Wrong_Password_Count = Wrong_Password_Count + 1
- print Wrong_Password_Count
- Admin_Username = raw_input('Please enter your username ')
- Admin_Password = raw_input('Please enter the admin password ')
- if Wrong_Password_Count > 2 :
- print('You have entered a wrong password 3 times, you are not able to login for 24 hours')
- if Admin_Password == 'ThisPasswordIsSafe' and Admin_Username == 'PeterPluim':
- print('\n')
- print('Login succefull')
- print('You have the following options')
- print('"/revenue" ----> See the total revenue')
- print('"/totalshipping" ----> Show the total cost of shipping we have had to pay')
- print('"/ShippingDestination" ----> Show how many packages are sent to the homeland and how many to other countries')
- CommandExecute = raw_input('Would you like to execute a command? ').upper()
- while CommandExecute == 'YES' :
- Admin_Choice = raw_input('What command would you like to execute').upper()
- if Admin_Choice == '/revenue' :
- reader = csv.reader(open("orderlist.csv"), delimiter=';')
- data = []
- for row in reader:
- data.append(row)
- print ('$') + data[999][4]
- CommandExecute = raw_input('Would you like to execute a command? ').upper()
- if Admin_Choice == '/totalshipping' :
- reader = csv.reader(open("orderlist.csv"), delimiter=';')
- data = []
- for row in reader:
- data.append(row)
- print ('$') + data[999][5]
- CommandExecute = raw_input('Would you like to execute a command? ').upper()
- #Show the product list
- if Add_Product == '/PRODUCTS' :
- print'\n'
- print('At the moment we have the following product in stock')
- print('R9 380X "Amd R9 380X off the brand sapphire" ')
- print('R9 390 "Amd R9 390 off the brand XFX" ')
- print('R9 390x "AMD R9 390X off the brand MSI"')
- print('GTX 960 "Nvidia GTX 960 off the brand MSI" ')
- print('GTX 970 "Nvidia GTX 970 off the brand Gigabyte" ')
- print('GTX 980 "Nvidia GTX 980 off the brand MSI" ')
- print('GTX 980 ti "Nvidia GTX 980 ti off the brand MSI" ')
- Add_Product = raw_input('Would you like to add a product to your shopping list? ').upper()
- while Add_Product == 'YES' :
- Add_Product_Choice = raw_input('What product would you like to add? ').upper()
- if Add_Product_Choice == 'R9 380X' :
- Quantity_R9_380X = raw_input('How many would you like to order? ').upper()
- Cost_R9_380X = int(Quantity_R9_380X)*240
- TotalCost = TotalCost + int(Cost_R9_380X)
- Add_Product = raw_input('Would you like to add a product to your shopping list? ').upper()
- with open('orderlist.csv', 'ab') as csvfile:
- writer = csv.writer(csvfile, delimiter= ";")
- writer.writerow(['R9 380X', Quantity_R9_380X])
- elif Add_Product_Choice == 'R9 390':
- Quantity_R9_390 = raw_input('How many would you like to order? ').upper()
- Cost_R9_390 = int(Quantity_R9_390)*330
- TotalCost = TotalCost + int(Cost_R9_390)
- Add_Product = raw_input('Would you like to add a product to your shopping list? ').upper()
- with open('orderlist.csv', 'ab') as csvfile:
- writer = csv.writer(csvfile, delimiter= ";")
- writer.writerow(['R9 390', Quantity_R9_390])
- elif Add_Product_Choice == 'R9 390X':
- Quantity_R9_390X = raw_input('How many would you like to order? ').upper()
- Cost_R9_390X = int(Quantity_R9_390X)*430
- TotalCost = TotalCost + int(Cost_R9_390X)
- Add_Product = raw_input('Would you like to add a product to your shopping list? ').upper()
- with open('orderlist.csv', 'ab') as csvfile:
- writer = csv.writer(csvfile, delimiter= ";")
- writer.writerow(['R9 390X', Quantity_R9_390X])
- elif Add_Product_Choice == 'GTX 960':
- Quantity_GTX_960 = raw_input('How many would you like to order? ').upper()
- Cost_GTX_960 = int(Quantity_GTX_960)*205
- TotalCost = TotalCost + int(Cost_GTX_960)
- Add_Product = raw_input('Would you like to add a product to your shopping list? ').upper()
- with open('orderlist.csv', 'ab') as csvfile:
- writer = csv.writer(csvfile, delimiter=";")
- writer.writerow(['GTX 960', Quantity_GTX_960])
- elif Add_Product_Choice == 'GTX 970':
- Quantity_GTX_970 = raw_input('How many would you like to order? ').upper()
- Cost_GTX_970 = int(Quantity_GTX_970)*330
- TotalCost = TotalCost + int(Cost_GTX_970)
- Add_Product = raw_input('Would you like to add a product to your shopping list? ').upper()
- with open('orderlist.csv', 'ab') as csvfile:
- writer = csv.writer(csvfile, delimiter=";")
- writer.writerow(['GTX 970', Quantity_GTX_970])
- elif Add_Product_Choice == 'GTX 980':
- Quantity_GTX_980 = raw_input('How many would you like to order? ').upper()
- Cost_GTX_980 = int(Quantity_GTX_980)*510
- TotalCost = TotalCost + int(Cost_GTX_980)
- Add_Product = raw_input('Would you like to add a product to your shopping list? ').upper()
- with open('orderlist.csv', 'ab') as csvfile:
- writer = csv.writer(csvfile, delimiter=";")
- writer.writerow(['GTX 980', Quantity_GTX_980])
- elif Add_Product_Choice == 'GTX 980 TI':
- Quantity_GTX_980_TI = raw_input('How many would you like to order? ').upper()
- Cost_GTX_980_TI = int(Quantity_GTX_980_TI)*740
- TotalCost = TotalCost + int(Cost_GTX_980_TI)
- Add_Product = raw_input('Would you like to add a product to your shopping list? ').upper()
- with open('orderlist.csv', 'ab') as csvfile:
- writer = csv.writer(csvfile, delimiter=";")
- writer.writerow(['GTX 980 ti', Quantity_GTX_980_TI])
- else :
- print("We don't have this product in stock at the moment")
- #Done with product choosing, entering personal information, Calculating shipping costs
- #Writing information to csv file
- if Add_Product == 'NO':
- FirstName = raw_input('What is your first name? ')
- SurName = raw_input('What is your surname? ')
- Country = raw_input('What country do you live in? ').upper()
- Address = raw_input('What is your address? ')
- #Shipment Netherlands
- if Country == 'THE NETHERLANDS' or Country == 'NETHERLANDS' or Country == 'NETHERLAND' or Country == 'HOLLAND':
- if TotalCost >= 250 :
- ShippingCosts = 0
- print("You don't have to pay any shipping fees")
- else :
- ShippingCosts = 6.95
- Remain_For_Shipping = 250 - TotalCost
- print('The shipping will cost you $6.95')
- print('Order for another $') + str(Remain_For_Shipping) + (' to get free shipping')
- else:
- if TotalCost >= 250 :
- ShippingCosts = 0
- print('You dont have to pay any shipping fees')
- else:
- ShippingCosts = 13.95
- Remain_For_Shipping = 250 - TotalCost
- print('The shipping will cost you $13.95')
- print('Order for another $') + str(Remain_For_Shipping) + (' to get free shipping')
- TotalCost = TotalCost + float(ShippingCosts)
- TotalProductCost= TotalCost - ShippingCosts
- print ('The total amount you have to pay is $') + str(TotalCost)
- with open('orderlist.csv', 'ab') as csvfile:
- writer = csv.writer(csvfile, delimiter= ";")
- writer.writerow([SurName, FirstName, Country, Address, float(TotalProductCost), float(ShippingCosts)])
- writer.writerow([' '])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement