paradocks

PrimeDice Python API [in development]

Apr 7th, 2015
536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.26 KB | None | 0 0
  1. #######################################################################
  2. # Python 2.7.9 recommended. Earlier versions throw SSL errors.        #  
  3. # Requests is not a built in module.                                  #
  4. # You can download it from: https://github.com/kennethreitz/requests  #
  5. # OR 'git clone git://github.com/kennethreitz/requests.git'           #
  6. # OR just 'pip install requests'                                      #
  7. #######################################################################
  8.  
  9. import threading, os, getpass, requests
  10. from random import randint
  11. clear = lambda: os.system('cls')
  12.  
  13. apiBase = 'https://api.primedice.com/api/'
  14. apiLogin = 'login' ## POST
  15. apiUserInfo = '/users/1?access_token=' ## GET
  16. chatInfo = '/messages' ## GET
  17.  
  18. ## Do Login
  19. def login():
  20.     global clear, username
  21.     username = raw_input('Username: ')
  22.     password = getpass.getpass()
  23.     otp = raw_input('2FA code. If none hit enter: ')
  24.     if len(otp) < 2:
  25.         payload = {
  26.             'username': username,
  27.             'password': password
  28.         }
  29.     else:
  30.         payload = {
  31.             'username': username,
  32.             'password': password,
  33.             'otp': otp
  34.         }
  35.     auth = requests.post(apiBase + apiLogin, data=payload).json()['access_token']
  36.     clear()
  37.     return auth
  38.  
  39. token = login()
  40.  
  41. ## Decimal Formatter
  42. def satoshi(num):
  43.     return "%0.8f" % (num/1e8)
  44.  
  45. ## Get User Info
  46. def userInfo():
  47.     global token
  48.     userInfo = requests.get(apiBase+apiUserInfo+token).json()['user']
  49.     print \
  50.     '####################################' + '\n' + \
  51.     '#            User Info             #' + '\n' + \
  52.     '####################################' + '\n\n' + \
  53.     '   Username: ' + username + '\n' + \
  54.     '   User ID: '  + str(userInfo['userid']) + '\n' + \
  55.     '   Balance: ' + satoshi(userInfo['balance']) + '\n' + \
  56.     '   Total Bets: ' + str(userInfo['bets']) + '\n' + \
  57.     '   Total Wins: ' + str(userInfo['wins']) + '\n' + \
  58.     '   Total Losses: ' + str(userInfo['losses']) + '\n' + \
  59.     '   Total Wagered: ' + satoshi(userInfo['wagered']) + '\n' + \
  60.     '   Profit: '  + satoshi(userInfo['profit']) + '\n\n' + \
  61.     '####################################' + '\n' + \
  62.     '#          Deposit Address         #' + '\n' + \
  63.     '####################################' + '\n\n' + \
  64.     ' ' + userInfo['address'] + '\n\n' + \
  65.     '####################################'
  66.  
  67.    
  68. userInfo()
Advertisement
Add Comment
Please, Sign In to add comment