This repository has been archived by the owner on Nov 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdrinkSSH.py
63 lines (55 loc) · 1.79 KB
/
drinkSSH.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import drinkAPI
import getpass
import os
import time
SYSTEM_NAMES = {'Drink':'d', 'Little Drink':'ld','Snack':'s'}
def machineMenu():
system = None
while system == None:
system = selectMachine()
if system == "q":
quit()
return system
def selectMachine():
for i,systemName in zip(range(len(SYSTEM_NAMES)),SYSTEM_NAMES.keys()):
print str(i)+'. '+systemName
selection = ""
selection = raw_input('Please select a machine or enter "q" to quit:\t')
if selection.lower() == "q":
return "q"
selection = int(selection)
if selection in range(len(SYSTEM_NAMES.keys())):
return drinkAPI.System(SYSTEM_NAMES.keys()[selection], SYSTEM_NAMES.values()[selection])
def selectItem(system):
print system
selection = raw_input('Please select an item or enter "q" to go back:\t')
if selection.lower() == "q":
return "q"
if int(selection) in range(1,len(system.inventory)+1):
return system.inventory[((int)(selection)-1)]
else:
print "Bad selection..."
return selectItem(system)
csh_net = drinkAPI.Network('csh.rit.edu')
user = drinkAPI.User(getpass.getuser())
machineSelect = True
while machineSelect:
system=machineMenu()
if system == "q":
continue
else:
machineSelect=False
user.connect_to_system(system,csh_net)
print "You currently have " + str(user.get_credits_balance()) + " creditz!"
choice = selectItem(system)
if choice == "q":
user.disconnect()
machineSelect=True
continue
elif user.get_credits_balance() > choice.price:
delay = int(raw_input("Time delay (0-100):\t"))
time.sleep(float(delay))
user.purchase(choice,delay)
machineSelect = False
else:
print "Not enough Creditz!"