Advertisement
Guest User

Untitled

a guest
Jun 8th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.97 KB | None | 0 0
  1. import random
  2. import pickle
  3.  
  4. #Begin Function List#
  5. def save(item, name):
  6.     f = file(name+'file', 'w')
  7.     pickle.dump(item, f)
  8.     f.close
  9.  
  10. def load(item):
  11.     try:
  12.         f = file(item+'file')
  13.         obj = pickle.load(f)
  14.         return obj
  15.         print 'File loaded successfully.'
  16.     except:
  17.         print 'Failure to load specified file.'
  18.  
  19. def Login():
  20.     global User
  21.     global Pass
  22.     User = raw_input('Username: ')
  23.     Pass = raw_input('Password: ')
  24.     if User == 'goduser' and Pass == '':
  25.         Parsing()
  26.     else:
  27.         print 'Login Failure.'
  28.         Login()
  29.  
  30. def Addrbk():
  31.     global firstrun
  32.     if firstrun:
  33.         firstrun = 0
  34.         Addressbook = load('Addressbook')
  35.         if not Addressbook:
  36.             Addressbook = {'Spammah01' : 'Spammaster@spamsite.spam',
  37.                            'Spammer02' : 'Spamemails@spamspam.spam'}
  38.     Cmd = raw_input('Command: ')
  39.  
  40.     if Cmd == 'add':
  41.         name = raw_input('ContactName: ')
  42.         email = raw_input('ContactEmail: ')
  43.         Addressbook[name] = email
  44.         Addrbk()
  45.  
  46.     if Cmd == 'remove':
  47.         rmve = raw_input('Remove: ')
  48.         del Addressbook[rmve]
  49.         Addrbk()
  50.  
  51.     if Cmd == 'contacts':
  52.         for k, v in Addressbook.iteritems():
  53.             print 'Contact: "'+k+'" Email: "'+v+'"'
  54.         Addrbk()
  55.  
  56.     if Cmd == 'menu':
  57.         save(Addressbook, 'Addressbook')
  58.         Parsing()
  59.  
  60.     if Cmd == 'help':
  61.         Help()
  62.         Addrbk()
  63.  
  64.     else:
  65.         print 'That is not a recognized command or operation.'
  66.         print 'Please access help.'
  67.    
  68. def Dice():
  69.     Quantity = raw_input('Dice to Throw: ')
  70.     Faces = raw_input('Number of Faces: ')
  71.     Modifier = raw_input('Modifier to Throw: ')
  72.     print 'Throwing '+Quantity+'d'+Faces+' + '+Modifier
  73.     try:
  74.         Throw = (random.randrange(1,int(Faces))*int(Quantity))+int(Modifier)
  75.     except:
  76.         print 'Some error/exception occurred.'
  77.         Dice()
  78.     print Throw
  79.    
  80. def Execute():
  81.     text = raw_input('>')
  82.     if text == 'menu':
  83.         Parsing()
  84.     try:
  85.         exec(text)
  86.     except:
  87.         print 'Some error/exception occurred.'
  88.     Execute()
  89.    
  90. def calc():
  91.     text = raw_input('Evaluate: ')
  92.     if text == 'menu':
  93.         Parsing()
  94.     try:
  95.         print eval(text)
  96.     except:
  97.         'Some error/exception occurred.'
  98.     calc()
  99.  
  100. def Help():
  101.     print '''\
  102. dice - Roll dice. Only accepts positive integers.
  103. help - Access this help doc.
  104. exit - Exit the program.
  105. exec - Direct Python interpretation.
  106.    + menu - Return to main.
  107. calc - Evaluate mathematical strings.
  108.    + menu - Return to main.
  109. addrbook - Access the address book; automatically saves on exit.
  110.    + add - Add a contact.  --BROKEN--
  111.    + remove - Remove a contact.  --BROKEN--
  112.    + contacts - List all contacts.
  113.    + help - Access this help doc.
  114.    + menu - Return to main.
  115. '''
  116.  
  117. def Parsing():
  118.     global firstrun
  119.     global firstlog
  120.     if firstlog:
  121.         print 'Welcome '+User+'!'
  122.         firstlog = 0
  123.     Comlist = 'help_dice_exit_exec_calc_addrbook'
  124.     Command = raw_input('Please input your command: ')
  125.     if Comlist.find(Command) == -1:
  126.         print 'That is not a recognized command or operation.'
  127.         print 'Please access the help files with the command "help"'
  128.         Parsing()
  129.     if Command == 'help':
  130.         Help()
  131.         Parsing()
  132.     if Command == 'dice':
  133.         Dice()
  134.         Parsing()
  135.     if Command == 'exit':
  136.         exit()
  137.     if Command == 'exec':
  138.         print 'Return to the menu via "menu"'
  139.         Execute()
  140.     if Command == 'calc':
  141.         print 'Return to the menu via "menu"'
  142.         calc()
  143.     if Command == 'addrbook':
  144.         print 'Return to menu via "menu"'
  145.         firstrun = 1
  146.         Addrbk()
  147.     if Command == '':
  148.         print 'That is not a recognized command or operation.'
  149.         print 'Please access the help files with the command "help"'
  150.         Parsing()
  151.  
  152. #End Function List#
  153. firstlog = 1
  154. Login()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement