Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import pickle
- #Begin Function List#
- def save(item, name):
- f = file(name+'file', 'w')
- pickle.dump(item, f)
- f.close
- def load(item):
- try:
- f = file(item+'file')
- obj = pickle.load(f)
- return obj
- print 'File loaded successfully.'
- except:
- print 'Failure to load specified file.'
- def Login():
- global User
- global Pass
- User = raw_input('Username: ')
- Pass = raw_input('Password: ')
- if User == 'goduser' and Pass == '':
- Parsing()
- else:
- print 'Login Failure.'
- Login()
- def Addrbk():
- global firstrun
- if firstrun:
- firstrun = 0
- Addressbook = load('Addressbook')
- if not Addressbook:
- Addressbook = {'Spammah01' : 'Spammaster@spamsite.spam',
- 'Spammer02' : 'Spamemails@spamspam.spam'}
- Cmd = raw_input('Command: ')
- if Cmd == 'add':
- name = raw_input('ContactName: ')
- email = raw_input('ContactEmail: ')
- Addressbook[name] = email
- Addrbk()
- if Cmd == 'remove':
- rmve = raw_input('Remove: ')
- del Addressbook[rmve]
- Addrbk()
- if Cmd == 'contacts':
- for k, v in Addressbook.iteritems():
- print 'Contact: "'+k+'" Email: "'+v+'"'
- Addrbk()
- if Cmd == 'menu':
- save(Addressbook, 'Addressbook')
- Parsing()
- if Cmd == 'help':
- Help()
- Addrbk()
- else:
- print 'That is not a recognized command or operation.'
- print 'Please access help.'
- def Dice():
- Quantity = raw_input('Dice to Throw: ')
- Faces = raw_input('Number of Faces: ')
- Modifier = raw_input('Modifier to Throw: ')
- print 'Throwing '+Quantity+'d'+Faces+' + '+Modifier
- try:
- Throw = (random.randrange(1,int(Faces))*int(Quantity))+int(Modifier)
- except:
- print 'Some error/exception occurred.'
- Dice()
- print Throw
- def Execute():
- text = raw_input('>')
- if text == 'menu':
- Parsing()
- try:
- exec(text)
- except:
- print 'Some error/exception occurred.'
- Execute()
- def calc():
- text = raw_input('Evaluate: ')
- if text == 'menu':
- Parsing()
- try:
- print eval(text)
- except:
- 'Some error/exception occurred.'
- calc()
- def Help():
- print '''\
- dice - Roll dice. Only accepts positive integers.
- help - Access this help doc.
- exit - Exit the program.
- exec - Direct Python interpretation.
- + menu - Return to main.
- calc - Evaluate mathematical strings.
- + menu - Return to main.
- addrbook - Access the address book; automatically saves on exit.
- + add - Add a contact. --BROKEN--
- + remove - Remove a contact. --BROKEN--
- + contacts - List all contacts.
- + help - Access this help doc.
- + menu - Return to main.
- '''
- def Parsing():
- global firstrun
- global firstlog
- if firstlog:
- print 'Welcome '+User+'!'
- firstlog = 0
- Comlist = 'help_dice_exit_exec_calc_addrbook'
- Command = raw_input('Please input your command: ')
- if Comlist.find(Command) == -1:
- print 'That is not a recognized command or operation.'
- print 'Please access the help files with the command "help"'
- Parsing()
- if Command == 'help':
- Help()
- Parsing()
- if Command == 'dice':
- Dice()
- Parsing()
- if Command == 'exit':
- exit()
- if Command == 'exec':
- print 'Return to the menu via "menu"'
- Execute()
- if Command == 'calc':
- print 'Return to the menu via "menu"'
- calc()
- if Command == 'addrbook':
- print 'Return to menu via "menu"'
- firstrun = 1
- Addrbk()
- if Command == '':
- print 'That is not a recognized command or operation.'
- print 'Please access the help files with the command "help"'
- Parsing()
- #End Function List#
- firstlog = 1
- Login()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement