Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. import requests
  2. import json
  3. import time
  4. from tools.api import urls
  5.  
  6.  
  7. class RamblrApi:
  8. debug = False
  9. TOKEN = 'Bearer c3sQUKrD82qjNrK2Ym0KbYjqdceUqt'
  10. CODE_INVALID_RESPONSE = 666
  11. CODE_TIMEOUT = 999
  12. CODE_SUCCESS = 200
  13.  
  14. BOT_BETA = 'beta'
  15. BOT_FREE = 'free'
  16. BOT_PRO = 'pro'
  17.  
  18.  
  19. def __init__(self, bot_id: str):
  20. self.bot_id = bot_id
  21.  
  22.  
  23. def base_request(self, url):
  24. try:
  25. response = requests.get(url,verify=False, headers={"Authorization": self.TOKEN,
  26. 'Content-Type': 'application/x-www-form-urlencoded'})
  27. if response.status_code == self.CODE_SUCCESS:
  28. print(response.text)
  29. json_data = json.loads(response.text)
  30. if json_data and isinstance(json_data, int):
  31. print(url)
  32. print(response)
  33. return self.CODE_INVALID_RESPONSE
  34. return json_data
  35. except requests.ConnectionError or requests.ConnectTimeout:
  36. return self.CODE_TIMEOUT
  37.  
  38. def base_post_request(self, url, data):
  39.  
  40. try:
  41. response = requests.post(url,verify=False, headers={
  42. 'bot_id': self.bot_id}, data=data)
  43. if response.status_code == self.CODE_SUCCESS:
  44. json_data = json.loads(response.text)
  45. if json_data and isinstance(json_data, int):
  46. print(url)
  47. print(response)
  48. return self.CODE_INVALID_RESPONSE
  49. return json_data
  50. except requests.ConnectionError or requests.ConnectTimeout:
  51. return self.CODE_TIMEOUT
  52.  
  53. ############################################
  54. # dailies api
  55. ############################################
  56. def dailies_get(self, user_id: int):
  57. return self.base_request(url=urls.DAILIES + '?user_id={user_id}&bot_id={bot_id}'.format(user_id=user_id, bot_id=self.bot_id))
  58.  
  59. ############################################
  60. # wallet api
  61. ############################################
  62. def wallet(self, user_id: int):
  63. return self.base_request(url=urls.WALLET + '?user_id={user_id}&bot_id={bot_id}'.format(user_id=user_id, bot_id=self.bot_id))
  64.  
  65. def wallet_p2p_give(self, user_id: int, receiver_id: int, amount: int):
  66. data = {
  67. 'user_id': user_id,
  68. 'receiver_id': receiver_id,
  69. 'amount': amount,
  70. 'bot_id': self.bot_id
  71. }
  72. return self.base_post_request(url=urls.WALLET_P2P_GIVE, data=data)
  73.  
  74. def wallet_award_cash(self, user_id: int, amount: int):
  75. data = {
  76. 'user_id': user_id,
  77. 'amount': amount,
  78. 'bot_id': self.bot_id
  79. }
  80. return self.base_post_request(url=urls.WALLET_AWARD_CASH, data=data)
  81.  
  82. def wallet_take_cash(self, user_id: int, amount: int):
  83. data = {
  84. 'user_id': user_id,
  85. 'amount': amount,
  86. 'bot_id': self.bot_id
  87. }
  88. return self.base_post_request(url=urls.WALLET_TAKE_CASH, data=data)
  89.  
  90.  
  91. ############################################
  92. # checklist api
  93. ############################################
  94. def checklist_create(self, user_id: int, title: str):
  95. data = {
  96. 'user_id': user_id,
  97. 'title': title,
  98. 'bot_id': self.bot_id
  99. }
  100. return self.base_post_request(url=urls.checklists, data=data)
  101.  
  102. def checklist_list(self, user_id: int):
  103. return self.base_request(url=urls.checklists + '?user_id={user_id}&bot_id={bot_id}'.format(user_id=user_id, bot_id=self.bot_id))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement