Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get api data #2

Merged
merged 9 commits into from
Jun 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Get data from api
  • Loading branch information
GISRedeDev committed Jun 23, 2024
commit 61b799f28871d5332deae4a1965c0e8b59e076dc
7 changes: 7 additions & 0 deletions areasofcontrol/get_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import requests

def get_history() -> list[int]:
url = "https://deepstatemap.live/api/history/"
response = requests.get(url)
ids = [x["id"] for x in response.json()]
return ids
19 changes: 19 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import json
import pytest
from pathlib import Path

BASE_DATA = Path(__file__).parent.joinpath("test_data")


@pytest.fixture
def get_history_mock_data():
mock_history_json = BASE_DATA.joinpath("history.json")
with open(mock_history_json, "r", encoding="utf-8") as f:
yield json.load(f)

@pytest.fixture
def ids_mock_data(get_history_mock_data):
response = get_history_mock_data
ids = [x["id"] for x in response]
yield ids

1 change: 1 addition & 0 deletions tests/test_data/history.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id":1706735973,"description":"Ворог просунувся північніше <a href=\"https://deepstatemap.live/#14/47.7494/36.6659\">Приютного</a>, північніше <a href=\"https://deepstatemap.live/#13/47.8789/37.5024\">Новомихайлівки</a> та східніше <a href=\"https://deepstatemap.live/#13/49.0741/38.0051\">Тернів</a>. Уточнено лінію зіткнення біля <a href=\"https://deepstatemap.live/#14/48.5397/37.9573\">Кліщіївки</a>.","descriptionEn":"The enemy advanced on north of <a href=\"https://deepstatemap.live/en#14/47.7494/36.6659\">Pryutny</a>, on north of <a href=\"https://deepstatemap.live/en#13/47.8789/37.5024\">Novomykhailivka</a> and on east <a href=\"https://deepstatemap.live/en#13/49.0741/38.0051\">Terny</a>. Clarified frontline near <a href=\"https://deepstatemap.live/en#14/48.5397/37.9573\">Klishchiivka</a>.","updatedAt":"2024-01-31T21:19:33.155Z","datetime":"31.01 o 22:19","status":true,"createdAt":"2024-01-31T21:19:33.000Z"},{"id":1706566905,"description":"Ворог просунувся біля <a href=\"https://deepstatemap.live/#14/47.7496/36.6794\">Приютного</a>. Оновлено лінію зіткнення південніше <a href=\"https://deepstatemap.live/#15/48.1136/37.7663\">Авдіївки</a>.","descriptionEn":"The enemy has advanced near <a href=\"https://deepstatemap.live/en#14/47.7496/36.6794\">Pryutne</a>. Updated the frontline on south of <a href=\"https://deepstatemap.live/en#15/48.1136/37.7663\">Avdiivka</a>.","updatedAt":"2024-01-29T22:21:45.880Z","datetime":"29.01 o 23:21","status":true,"createdAt":"2024-01-29T22:21:45.000Z"},{"id":1706480394,"description":"Ворог просунувся в <a href=\"https://deepstatemap.live/#14/48.0759/37.6338\">Первомайському</a>, північніше <a href=\"https://deepstatemap.live/#14/47.8811/37.5200\">Новомихайлівки</a> та північніше <a href=\"https://deepstatemap.live/#14/48.1073/37.7196\">Опитного</a>. Противнику не дали закріпитися в <a href=\"https://deepstatemap.live/#13/49.5995/37.8736\">Табаївці</a>.","descriptionEn":"The enemy has advanced in <a href=\"https://deepstatemap.live/en#14/48.0759/37.6338\">Pervomaiske</a>, on north of <a href=\"https://deepstatemap.live/en#14/47.8811/37.5200\">Novomykhailivka</a> and on north of <a href=\"https://deepstatemap.live/en#14/48.1073/37.7196\">Opytne</a>. The enemy was not allowed to gain a foothold in <a href=\"https://deepstatemap.live/en#13/49.5995/37.8736\">Tabaivka</a>.","updatedAt":"2024-01-28T22:32:45.311Z","datetime":"28.01 o 23:19","status":true,"createdAt":"2024-01-28T22:19:54.000Z"},{"id":1706435881,"description":"Ворог захопив <a href=\"https://deepstatemap.live/#13/49.5905/37.8837\">Табаївку</a>, оновлено район <a href=\"https://deepstatemap.live/#13/49.7730/37.6891\">Синьківки</a>.","descriptionEn":"The enemy captured <a href=\"https://deepstatemap.live/en#13/49.5905/37.8837\">Tabaivka</a>, the district <a href=\"https://deepstatemap.live/#en13/49.7730/37.6891\" was updated \">Synkivka</a>.","updatedAt":"2024-01-28T10:00:07.817Z","datetime":"28.01 o 10:58","status":true,"createdAt":"2024-01-28T09:58:01.000Z"},{"id":1706392086,"description":"Ворог просунувся східніше <a href=\"https://deepstatemap.live/#14/49.6007/37.8902\">Табаївки</a> та на півдні <a href=\"https://deepstatemap.live/#15/48.1107/37.7735\">Авдіївки</a>. Уточнюється лінія зіткнення біля <a href=\"https://deepstatemap.live/#14/49.7653/37.7064\">Синьківки</a>.","descriptionEn":"The enemy advanced to the east <a href=\"https://deepstatemap.live/en#14/49.6007/37.8902\">Tabaivka</a> and to the south <a href=\"https://deepstatemap.live/en#15/48.1107/37.7735\">Avdiivka</a>. The front line near <a href=\"https://deepstatemap.live/en#14/49.7653/37.7064\">Synkivka</a> is being clarified.","updatedAt":"2024-01-27T21:52:31.223Z","datetime":"27.01 o 22:48","status":true,"createdAt":"2024-01-27T21:48:06.000Z"},{"id":1706305150,"description":"Оновлено лінію зіткнення західніше <a href=\"https://deepstatemap.live/#14/47.4629/35.7972\">Роботиного</a> та північніше села <a href=\"https://deepstatemap.live/#15/48.2153/37.6622\">Бердичі</a>.","descriptionEn":"Updated frontline on west of <a href=\"https://deepstatemap.live/en#14/47.4629/35.7972\">Robotyne</a> and north of the village of <a href=\"https://deepstatemap.live/en#15/48.2153/37.6622\">Berdychi</a>.","updatedAt":"2024-01-26T21:51:43.677Z","datetime":"26.01 o 22:39","status":true,"createdAt":"2024-01-26T21:39:10.000Z"},{"id":1706219661,"description":"Сили Оборони України просунулися західніше <a href=\"https://deepstatemap.live/#15/47.4713/35.9420\">Вербового</a>. Східніше <a href=\"https://deepstatemap.live/#14/49.0769/38.0180\">Тернів</a> тривають бої, лінія зіткнення уточнюється.","descriptionEn":"The Defense Forces of Ukraine advanced on west of <a href=\"https://deepstatemap.live/en#15/47.4713/35.9420\">Verbove</a>. On east of the <a href=\"https://deepstatemap.live/en#14/49.0769/38.0180\">Torske</a> fighting continues, the contact line is being refined.","updatedAt":"2024-01-25T22:04:45.841Z","datetime":"25.01 o 22:54","status":true,"createdAt":"2024-01-25T21:54:21.000Z"},{"id":1706132720,"description":"Оновлено лінію зіткнення південніше <a href=\"https://deepstatemap.live/#15/48.1140/37.7650\">Авдіївки</a>.","descriptionEn":"Updated frontline on south of <a href=\"https://deepstatemap.live/en#15/48.1140/37.7650\">Avdiivka</a>.","updatedAt":"2024-01-24T22:01:25.168Z","datetime":"24.01 o 22:45","status":true,"createdAt":"2024-01-24T21:45:20.000Z"},{"id":1706045204,"description":"Уточнено лінію зіткнення.","descriptionEn":"The front line has been clarified.","updatedAt":"2024-01-23T21:28:20.054Z","datetime":"23.01 o 22:26","status":true,"createdAt":"2024-01-23T21:26:44.000Z"},{"id":1705956248,"description":"Оновлено лінію зіткнення біля <a href=\"https://deepstatemap.live/#13/49.5592/37.9311\">Крохмального</a>, <a href=\"https://deepstatemap.live/#14/47.9652/37.4947\">Мар'їнки</a> та <a href=\"https://deepstatemap.live/#14/48.5580/37.9507\">Іванівського</a>.","descriptionEn":"Updated front line near <a href=\"https://deepstatemap.live/en#13/49.5592/37.9311\">Krokhmalne</a>, <a href=\"https://deepstatemap.live/en#14/47.9652/37.4947\">Marinka</a> and <a href=\"https://deepstatemap.live/en#14/48.5580/37.9507\">Ivanivske</a>.</p>","updatedAt":"2024-01-22T22:00:33.396Z","datetime":"22.01 o 21:44","status":true,"createdAt":"2024-01-22T20:44:08.000Z"}]
14 changes: 14 additions & 0 deletions tests/test_get_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from unittest.mock import patch
import pytest

from areasofcontrol.get_data import get_history


@patch('requests.get')
def test_get_history(mock_get, get_history_mock_data):
mock_get.return_value.json.return_value = get_history_mock_data
ids = get_history()
assert len(ids) > 0
assert 1706735973 in ids