Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- import time
- from tools.api import urls
- class RamblrApi:
- debug = False
- TOKEN = 'Bearer c3sQUKrD82qjNrK2Ym0KbYjqdceUqt'
- CODE_INVALID_RESPONSE = 666
- CODE_TIMEOUT = 999
- CODE_SUCCESS = 200
- BOT_BETA = 'beta'
- BOT_FREE = 'free'
- BOT_PRO = 'pro'
- def __init__(self, bot_id: str):
- self.bot_id = bot_id
- def base_request(self, url):
- try:
- response = requests.get(url,verify=False, headers={"Authorization": self.TOKEN,
- 'Content-Type': 'application/x-www-form-urlencoded'})
- if response.status_code == self.CODE_SUCCESS:
- print(response.text)
- json_data = json.loads(response.text)
- if json_data and isinstance(json_data, int):
- print(url)
- print(response)
- return self.CODE_INVALID_RESPONSE
- return json_data
- except requests.ConnectionError or requests.ConnectTimeout:
- return self.CODE_TIMEOUT
- def base_post_request(self, url, data):
- try:
- response = requests.post(url,verify=False, headers={
- 'bot_id': self.bot_id}, data=data)
- if response.status_code == self.CODE_SUCCESS:
- json_data = json.loads(response.text)
- if json_data and isinstance(json_data, int):
- print(url)
- print(response)
- return self.CODE_INVALID_RESPONSE
- return json_data
- except requests.ConnectionError or requests.ConnectTimeout:
- return self.CODE_TIMEOUT
- ############################################
- # dailies api
- ############################################
- def dailies_get(self, user_id: int):
- 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))
- ############################################
- # wallet api
- ############################################
- def wallet(self, user_id: int):
- 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))
- def wallet_p2p_give(self, user_id: int, receiver_id: int, amount: int):
- data = {
- 'user_id': user_id,
- 'receiver_id': receiver_id,
- 'amount': amount,
- 'bot_id': self.bot_id
- }
- return self.base_post_request(url=urls.WALLET_P2P_GIVE, data=data)
- def wallet_award_cash(self, user_id: int, amount: int):
- data = {
- 'user_id': user_id,
- 'amount': amount,
- 'bot_id': self.bot_id
- }
- return self.base_post_request(url=urls.WALLET_AWARD_CASH, data=data)
- def wallet_take_cash(self, user_id: int, amount: int):
- data = {
- 'user_id': user_id,
- 'amount': amount,
- 'bot_id': self.bot_id
- }
- return self.base_post_request(url=urls.WALLET_TAKE_CASH, data=data)
- ############################################
- # checklist api
- ############################################
- def checklist_create(self, user_id: int, title: str):
- data = {
- 'user_id': user_id,
- 'title': title,
- 'bot_id': self.bot_id
- }
- return self.base_post_request(url=urls.checklists, data=data)
- def checklist_list(self, user_id: int):
- 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