Обвертка над API keksik.io
Project description
Keksik API wrapper
Обвертка над API keksik.io
Использование:
import os
from keksik_api import KeksikAPI, KeksikAPIException
GROUP_ID = int(os.environ.get('GROUP_ID'))
ACCESS_TOKEN = os.environ.get('ACCESS_TOKEN')
api = KeksikAPI(GROUP_ID, ACCESS_TOKEN)
last_donates = await api.donates.get_last()
for item in last_donates.items:
print(item.id)
# Передача токена динамически
await api.donates.answer(1, "Спасибо :3", group=GROUP_ID, token=ACCESS_TOKEN)
# Ошибочки
try:
await api.donates.answer(-666, '')
except KeksikAPIException as exc:
print("Произошла ошибка: ", exc.error_code, exc.message)
# Кастомные запросы
await api.request("{method}", dict(data='...'), raise_errors=False)
# Callback
import uvicorn
from fastapi import FastAPI
from keksik_api.callback import Callback, Router
from keksik_api import schemas
SECRET_KEY = os.environ.get('SECRET_KEY')
CONFIRMATION_CODE = os.environ.get('CONFIRMATION_CODE')
router = Router()
@router.on_new_donate()
async def on_new_donate_handler(event: schemas.DonateEvent):
print("New donate", event.donate.id)
callback = Callback(
KeksikAPI(GROUP_ID, ACCESS_TOKEN),
SECRET_KEY,
CONFIRMATION_CODE,
router=router
)
app = FastAPI()
@app.post("/")
async def app_route(params: dict):
return await callback.route_web_request(params)
if __name__ == "__main__":
uvicorn.run(app)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
keksik_api-0.2.2.tar.gz
(27.1 kB
view hashes)
Built Distribution
keksik_api-0.2.2-py3-none-any.whl
(16.6 kB
view hashes)
Close
Hashes for keksik_api-0.2.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c28ee3e22c7f1fabe83aaeb928b1701634c548e49273bc27e126a6892c6bf73 |
|
MD5 | ad9df45569d0c2b1c3cece534c4daa57 |
|
BLAKE2b-256 | f4c3e12cc5bbebddaecd93e6d12e4ce67e67a1fafb6451bd6034665b732a84a1 |