clash-telegram-bot/coc/base.py

26 lines
796 B
Python
Raw Permalink Normal View History

2022-03-18 22:25:50 +03:00
import json
import requests
from abc import ABC
class Base(ABC):
def __init__(self, api_token:str, clan_tag:str = None) -> None:
self.headers = {
"Content-Type": "application/json",
"Authorization": "Bearer {api_token}".format(api_token=api_token)
}
self.clan_tag = clan_tag
def get(self, url: str, tag: str):
request = requests.get(
url.format(tag.replace("#", "")),
headers=self.headers
)
return json.loads(request.text)
def post(self, url: str, tag: str, payload: dict):
request = requests.post(
url=url.format(tag.replace("#", "")),
headers=self.headers,
data=json.dumps(payload)
)
return json.loads(request.text)