gancio_requests package

gancio_requests.formatting module

format_event_info(event: dict, instance_url: Optional[str] = None) str

Given the information about an event fetched from the API, formats it in a more readable way.

Parameters
  • event – event information fetched from the API.

  • instance_url (str) – optional, the instance url from which the data was fetched. If this param is specified, then the event url is added to the infos

Type

dict

Returns

the event information.

Return type

str

html2text(html_content: str) str

Transforms a string containing html code and tags in plain text

Parameters

html_content (str) – the html code

Returns

the text inside the html code

Return type

str

gancio_requests.request module

async get_event_description(instance_url: str, event_slug: str, cache: CacheBackend = None) dict

Fetches the html description of an event using the event slug

Parameters
  • instance_url (str) – URL of the Gancio instance where the event is saved

  • event_slug (str) – the slug of the event to fetch

  • cache (CacheBackend) – optional, the cache to use to save/fetch the http requests

Returns

the response status code (key: “status”) and the event html descritpion (key:”html_content”)

Return type

dict

Example

>>> import asyncio
>>> from gancio_requests.request import get_event_description
>>> from aiohttp_client_cache import SQLiteBackend
>>>
>>> url = "https://gancio.cisti.org"
>>> event_slug = "jazz-in-jardino-2"
>>> cache = SQLiteBackend(
...     cache_name = "aio-requests.db"
... )
>>>
>>> result = asyncio.run(get_event_description(url, event_slug, cache))
async get_event_image(instance_url: str, image_name: str, cache: CacheBackend = None) dict

Fetches the image of specified event.

Parameters
  • instance_url (str) – the URL of the Gancio instance where the event is saved

  • image_name (str) – the name and file extension suffix of the image to fetch

  • cache (CacheBackend) – optional, the cache to use to save/fetch the http requests

Returns

the response status code (key: “status”) and the image bytes (key:”content”)

Return type

dict

Example

>>> import asyncio
>>> from gancio_requests.request import get_event_image
>>> from aiohttp_client_cache import SQLiteBackend
>>>
>>> url = "https://gancio.cisti.org"
>>> image_name = "072e0caedb51e352c43813376b59b26d.jpg"
>>> cache = SQLiteBackend(
...     cache_name = "aio-requests.db"
... )
>>>
>>> res = asyncio.run(get_event_image(url, image_name, cache))
async get_events(instance_url: str, params: dict = None, cache: CacheBackend = None) dict

Fetches the events saved on the specified Gancio instance using the specified url parameters. Information about the available URL parameters can be found at https://gancio.org/dev/api

Parameters
  • instance_url (str) – URL of the Gancio instance where the event is saved

  • params (dict) – optional, dictionary specifying for each URL parameter (key) its value (value)

  • cache (CacheBackend) – optional, the cache to use to save/fetch the http requests

Returns

the response status code (key: “status”) and the list of events information (key:”json_content”)

Return type

dict

Example

>>> import asyncio
>>> from gancio_requests.request import get_events
>>> from aiohttp_client_cache import SQLiteBackend
>>>
>>> url = "https://gancio.cisti.org"
>>> # for this example we want to fetch all the events
>>> # starting from 1-1-1970 00:00:00
>>> params = {"start": 0}
>>> cache = SQLiteBackend(
...     cache_name = "aio-requests.db"
... )
>>> result = asyncio.run(get_events(url, params, cache))