hamyar_paygah.services.missions_list_service

Services to get missions list from server.

Attributes

Functions

_fetch_missions_list(server_address, from_date, ...)

Fetch a list of missions for a specific region from the EMS SOAP service.

_get_cache_file_path(region_id, date)

Generate a cache file path for a given region and date.

_save_xml_cache(path, xml_text)

Save XML response as compressed LZMA file.

_load_xml_cache(path)

Load XML response from compressed LZMA cache file.

get_missions_list(server_address, from_date, to_date, ...)

Fetch missions list with caching mechanism.

Module Contents

hamyar_paygah.services.missions_list_service.CACHE_DIR
hamyar_paygah.services.missions_list_service.HTTP_OK_STATUS = 200
async hamyar_paygah.services.missions_list_service._fetch_missions_list(server_address, from_date, to_date, region_id)

Fetch a list of missions for a specific region from the EMS SOAP service.

This function sends an asynchronous SOAP request to the EMS reporting service and retrieves the raw XML response containing mission data for the given date range and region.

The request uses a legacy SOAP endpoint with strict field names. In particular, the XML field named passsword is intentionally misspelled and must not be corrected, as changing it results in a BAD REQUEST response from the server.

Parameters:
  • server_address (str) – Base address of the EMS server (without trailing slash).

  • from_date (datetime.datetime) – Start date of the report range. The time component is automatically set to 00:00:00.

  • to_date (datetime.datetime) – End date of the report range. The time component is automatically set to 23:59:59.

  • region_id (int) – Numeric identifier of the region for which the report is requested.

Returns:

The raw SOAP response body as a string. The returned value is unparsed XML and must be processed by the caller if structured data is required.

Raises:

aiohttp.ClientError – If the HTTP request fails due to a network or connection error.

Return type:

str

hamyar_paygah.services.missions_list_service._get_cache_file_path(region_id, date)

Generate a cache file path for a given region and date.

Parameters:
  • region_id (int) – The ID of the region.

  • date (datetime.datetime) – The date for which to generate the cache path.

Returns:

The path to the cache file.

Return type:

anyio.Path

async hamyar_paygah.services.missions_list_service._save_xml_cache(path, xml_text)

Save XML response as compressed LZMA file.

Parameters:
Return type:

None

async hamyar_paygah.services.missions_list_service._load_xml_cache(path)

Load XML response from compressed LZMA cache file.

Parameters:

path (anyio.Path)

Return type:

str

async hamyar_paygah.services.missions_list_service.get_missions_list(server_address, from_date, to_date, region_id, progress_callback=None)

Fetch missions list with caching mechanism.

This function first checks if a cached response exists for the given region and date range. If a valid cache is found, it loads the XML data from the cache and parses it into a list of Mission objects. If no cache is available, it fetches the data from the server, saves it to the cache, and then parses it.

Parameters:
  • server_address (str) – The base address of the EMS server.

  • from_date (datetime.datetime) – The start date of the missions query.

  • to_date (datetime.datetime) – The end date of the missions query.

  • region_id (int) – The region ID to filter missions by.

  • progress_callback (collections.abc.Callable[[int, int], None] | None) – Optional function that receives two ints:

  • processed_days

  • total_days.

Returns:

A list of Mission objects parsed from the server response

or cache.

Return type:

list[Mission]