# Keksik API wrapper
Обвертка над API [keksik.io](https://keksik.io/api)
<p align="center">
<img alt="PyPI - Downloads" src="https://img.shields.io/pypi/dm/keksik-api">
<img alt="PyPI" src="https://img.shields.io/pypi/v/keksik-api?color=green&label=PyPI">
</p>
# Использование:
```python
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)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/lordralinc/keksik_api",
"name": "keksik-api",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8,<4.0",
"maintainer_email": "",
"keywords": "",
"author": "lordralinc",
"author_email": "lordralinc@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/13/9e/fbbcc7a28ee0b774b90379e95b4a63d8396de8a4cc4313c95dd11254671a/keksik_api-0.2.4.tar.gz",
"platform": null,
"description": "# Keksik API wrapper\n\n\u041e\u0431\u0432\u0435\u0440\u0442\u043a\u0430 \u043d\u0430\u0434 API [keksik.io](https://keksik.io/api)\n\n<p align=\"center\">\n <img alt=\"PyPI - Downloads\" src=\"https://img.shields.io/pypi/dm/keksik-api\">\n <img alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/keksik-api?color=green&label=PyPI\">\n</p>\n\n# \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435:\n```python\nimport os\nfrom keksik_api import KeksikAPI, KeksikAPIException\n\nGROUP_ID = int(os.environ.get('GROUP_ID'))\nACCESS_TOKEN = os.environ.get('ACCESS_TOKEN')\n\n\napi = KeksikAPI(GROUP_ID, ACCESS_TOKEN)\n\nlast_donates = await api.donates.get_last()\nfor item in last_donates.items:\n print(item.id)\n\n# \u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0442\u043e\u043a\u0435\u043d\u0430 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\nawait api.donates.answer(1, \"\u0421\u043f\u0430\u0441\u0438\u0431\u043e :3\", group=GROUP_ID, token=ACCESS_TOKEN)\n\n# \u041e\u0448\u0438\u0431\u043e\u0447\u043a\u0438\ntry:\n await api.donates.answer(-666, '')\nexcept KeksikAPIException as exc:\n print(\"\u041f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430: \", exc.error_code, exc.message)\n\n# \u041a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b\nawait api.request(\"{method}\", dict(data='...'), raise_errors=False)\n\n# Callback\nimport uvicorn\nfrom fastapi import FastAPI\n\nfrom keksik_api.callback import Callback, Router\nfrom keksik_api import schemas\n\nSECRET_KEY = os.environ.get('SECRET_KEY')\nCONFIRMATION_CODE = os.environ.get('CONFIRMATION_CODE')\n\n\nrouter = Router()\n\n@router.on_new_donate()\nasync def on_new_donate_handler(event: schemas.DonateEvent):\n print(\"New donate\", event.donate.id)\n\ncallback = Callback(\n KeksikAPI(GROUP_ID, ACCESS_TOKEN),\n SECRET_KEY,\n CONFIRMATION_CODE,\n router=router\n)\n\n\napp = FastAPI()\n\n@app.post(\"/\")\nasync def app_route(params: dict):\n return await callback.route_web_request(params)\n\n\nif __name__ == \"__main__\":\n uvicorn.run(app)\n```",
"bugtrack_url": null,
"license": "MIT",
"summary": "\u041e\u0431\u0432\u0435\u0440\u0442\u043a\u0430 \u043d\u0430\u0434 API keksik.io",
"version": "0.2.4",
"project_urls": {
"Homepage": "https://github.com/lordralinc/keksik_api",
"Repository": "https://github.com/lordralinc/keksik_api"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7b2c5f52f7aa7dff72c4607414e4151618fa21d7da0fd67c45365845e17b731f",
"md5": "c268f1b77c3c25b187d494cec70f86be",
"sha256": "a36ebae3b890a66b6f2a9d484be6a8f20075c98107a5aa7fecda7a78125a8852"
},
"downloads": -1,
"filename": "keksik_api-0.2.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c268f1b77c3c25b187d494cec70f86be",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<4.0",
"size": 16611,
"upload_time": "2023-07-28T04:59:53",
"upload_time_iso_8601": "2023-07-28T04:59:53.469670Z",
"url": "https://files.pythonhosted.org/packages/7b/2c/5f52f7aa7dff72c4607414e4151618fa21d7da0fd67c45365845e17b731f/keksik_api-0.2.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "139efbbcc7a28ee0b774b90379e95b4a63d8396de8a4cc4313c95dd11254671a",
"md5": "1bde147b90604093bf218f0baf563d0a",
"sha256": "5e727b021d34627d5166486649e18d6c64a44ad94fea28fbd4d73805ee791188"
},
"downloads": -1,
"filename": "keksik_api-0.2.4.tar.gz",
"has_sig": false,
"md5_digest": "1bde147b90604093bf218f0baf563d0a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8,<4.0",
"size": 27096,
"upload_time": "2023-07-28T04:59:55",
"upload_time_iso_8601": "2023-07-28T04:59:55.359773Z",
"url": "https://files.pythonhosted.org/packages/13/9e/fbbcc7a28ee0b774b90379e95b4a63d8396de8a4cc4313c95dd11254671a/keksik_api-0.2.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-28 04:59:55",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "lordralinc",
"github_project": "keksik_api",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "keksik-api"
}