{"id":28158041,"url":"https://github.com/fourex/alerts_in_ua.py","last_synced_at":"2025-05-15T09:17:37.717Z","repository":{"id":65767592,"uuid":"599314805","full_name":"FOUREX/alerts_in_ua.py","owner":"FOUREX","description":"Бібліотека для використання API сайту alerts.in.ua","archived":false,"fork":false,"pushed_at":"2024-02-10T15:40:35.000Z","size":1313,"stargazers_count":7,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"yep","last_synced_at":"2025-05-15T09:16:04.472Z","etag":null,"topics":["lib","python-3","python-library"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FOUREX.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-02-08T22:09:30.000Z","updated_at":"2024-10-24T11:09:21.000Z","dependencies_parsed_at":"2024-02-09T02:23:09.263Z","dependency_job_id":"2c9ed33a-fbaf-4481-953e-c9c22b3d0a05","html_url":"https://github.com/FOUREX/alerts_in_ua.py","commit_stats":{"total_commits":48,"total_committers":1,"mean_commits":48.0,"dds":0.0,"last_synced_commit":"b0c0892b3adcf60b5da589c8ea20e191fee41a7c"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FOUREX%2Falerts_in_ua.py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FOUREX%2Falerts_in_ua.py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FOUREX%2Falerts_in_ua.py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FOUREX%2Falerts_in_ua.py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FOUREX","download_url":"https://codeload.github.com/FOUREX/alerts_in_ua.py/tar.gz/refs/heads/yep","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254310474,"owners_count":22049470,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lib","python-3","python-library"],"created_at":"2025-05-15T09:15:58.145Z","updated_at":"2025-05-15T09:17:37.711Z","avatar_url":"https://github.com/FOUREX.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Alerts_in_ua.py\n\nБібліотека для користування API сайту [alerts.in.ua](https://alerts.in.ua).\n**Бібліотека досі в розробці, якщо ви знайшли помилку або у вас є ідея щодо бібліотеки,\nвертайтесь до розробника!** Telegram: [@FOUREX_dot_py](https://t.me/FOUREX_dot_py).\n\nРозробники сайту [alerts.in.ua](https://alerts.in.ua/) випустили\n[офіційну бібліотеку](https://github.com/alerts-ua/alerts-in-ua-py).\n\n## Встановлення\n\n```shell\npip install alerts-in-ua.py\n```\n\n## Приклад використання:\n\n```python\nfrom alerts_in_ua.alerts_client import AlertsClient  # Імпортуємо клієнт\n\nalerts_client = AlertsClient(\"token\")  # Ініціалізуємо клієнт\n\n\ndef main():\n    locations = alerts_client.get_active()  # Отримуємо список місць з тривогою\n\n    # Фільтруємо список місць залишаючи місця з ПОВІТРЯНОЮ тривогою\n    air_raid_locations = locations.filter(alert_type=\"air_raid\")\n\n    for location in air_raid_locations:\n        # Виводимо назву та час початку тривоги кожного місця зі списку\n        print(location.location_title, location.started_at)\n\n\nif __name__ == \"__main__\":\n    main()\n```\n\n## Приклад використання асинхронного клієнта:\nРекомендовано використовувати для ботів\n\n```python\nimport asyncio\n\nfrom alerts_in_ua.async_alerts_client import AsyncAlertsClient\n\nalerts_client = AsyncAlertsClient(\"token\")  # Ініціалізуємо клієнт\n\n\nasync def main():\n    locations = await alerts_client.get_active()  # Отримуємо список місць з тривогою\n\n    # Фільтруємо список місць залишаючи місця з ПОВІТРЯНОЮ тривогою\n    air_raid_locations = locations.filter(alert_type=\"air_raid\")\n\n    for location in air_raid_locations:\n        # Виводимо назву та час початку тривоги кожного місця зі списку\n        print(location.location_title, location.started_at)\n\n\nif __name__ == \"__main__\":\n    loop = asyncio.new_event_loop()\n    loop.run_until_complete(main())\n```\n\n## Приклад використання рендера мапи тривог:\nДля телеграм боту написаного з допомогою бібліотеки [aiogram](https://github.com/aiogram/aiogram)\n```python\nfrom aiogram import Bot, Dispatcher, executor\nfrom aiogram.types import Message\n\nfrom alerts_in_ua.async_alerts_client import AsyncAlertsClient\n\n\nbot = Bot(\"telegram_bot_token\")\ndp = Dispatcher(bot)\n\nalerts_client = AsyncAlertsClient(\"api_alerts_in_ua_token\")\n\n\n@dp.message_handler(commands=[\"alerts\"])\nasync def yep(message: Message):\n    locations = await alerts_client.get_active()\n    alerts_map = locations.render_map()\n    message_text = \"\\n\".join(locations.location_title)\n\n    await message.reply_photo(alerts_map, message_text)\n\n\nif __name__ == \"__main__\":\n    executor.start_polling(dispatcher=dp)\n```\n\nРезультат:\n\n![map_render_result.png](assets/map_render_result.png)\n\n## Використання фільтрів:\nСпосіб 1\n```python\nlocations = alerts_client.get_active()\n\nair_raid = locations.filter(alert_type=\"air_raid\")\noblast = locations.filter(location_type=\"oblast\")\nair_raid_and_oblast = locations.filter(alert_type=\"air_raid\", location_type=\"oblast\")\n\nprint(air_raid)  # Місця лише з повітряною тривогою\nprint(oblast)  # Лише області\nprint(air_raid_and_oblast)  # Лише області з повітряною тривогою\n```\nСпосіб 2\n```python\nlocations = alerts_client.get_active()\n\nair_raid_filter = {\"alert_type\": \"air_raid\"}\noblast_filter = {\"location_type\": \"oblast\"}\nair_raid_and_oblast_filter = {\"alert_type\": \"air_raid\", \"location_type\": \"oblast\"}\n\nair_raid = locations.filter(**air_raid_filter)\noblast = locations.filter(**oblast_filter)\nair_raid_and_oblast = locations.filter(**air_raid_and_oblast_filter)\n\nprint(air_raid)  # Місця лише з повітряною тривогою\nprint(oblast)  # Лише області\nprint(air_raid_and_oblast)  # Лише області з повітряною тривогою\n```\n\n## Отримання значень атрибутів місць через список місць:\n```python\nlocations = alerts_client.get_active()\n\nprint(list(zip(locations.location_title, locations.location_uid)))\n# [('Луганська область', '16'), ('Автономна Республіка Крим', '29'), ('Нікопольська територіальна громада', '351'), ('м. Нікополь', '5351')]\n```\n\n## Перевірка наявності місця в списку:\nЗа його UID (location_uid) або назвою (location_title)\n\n```python\nlocations = alerts_client.get_active()\nprint(\"Автономна Республіка Крим\" in locations)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffourex%2Falerts_in_ua.py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffourex%2Falerts_in_ua.py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffourex%2Falerts_in_ua.py/lists"}