Skip to content

hut_services

Modules:

Classes:

Functions:

  • file_cache

    Chaches function, if 'forever' is True, cache will never expire (and 'expire_in_seconds' will be ignored).

Attributes:

Attributes

clear_file_cache module-attribute

clear_file_cache = clear

Cleares cache.

HutSourceSchema module-attribute

Hut source schema, used for typing. With pydantic BaseModel and SourcePrpertiesSchema.

SERVICES module-attribute

SERVICES: dict[str, BaseService[HutSourceSchema]] = {
    "osm": OsmService(),
    "refuges": RefugesInfoService(),
    "wikidata": WikidataService(),
}

Classes

AnswerEnum

Anser enum.

'yesish' and 'noish' means it is likely to be 'yes' or 'no'. 'maybe' means is is either 'yes' or 'no'.

Attributes:

Attributes

yes class-attribute instance-attribute
yes = 'yes'
yesish class-attribute instance-attribute
yesish = 'yesish'
maybe class-attribute instance-attribute
maybe = 'maybe'
noish class-attribute instance-attribute
noish = 'noish'
no class-attribute instance-attribute
no = 'no'
unknown class-attribute instance-attribute
unknown = 'unknown'

AuthorSchema

Author information.

Attributes:

  • name (str) –

    Name of the author.

  • url (None | HttpUrl) –

    URL of the author.

Attributes:

Attributes

model_config class-attribute instance-attribute
model_config = ConfigDict(
    from_attributes=True, extra="allow"
)
name instance-attribute
name: str
url class-attribute instance-attribute
url: None | HttpUrl = None

BaseHutConverterSchema

Base class used for a converter schema.

Attributes:

All attributes as in HutSchema either as attribute or pydantic computed_field.

Examples:

See hut_services.osm.schema.OsmHut0Convert.

Classes:

Methods:

Attributes:

Attributes

source_data class-attribute instance-attribute
source_data: TSourceData = Field(..., exclude=True)
include_photos class-attribute instance-attribute
include_photos: bool = True
slug property
slug: str
name property
source property
source: SourceSchema | None
author property
author: AuthorSchema | None
source_name property
source_name: str
location property
description property
description: TranslationSchema
notes property
notes: list[TranslationSchema]
owner property
owner: OwnerSchema | None
url property
url: str
contacts property
contacts: list[ContactSchema]
country_code property
country_code: str | None
comment property
comment: str
capacity property
capacity: CapacitySchema
hut_type property
hut_type: HutTypeSchema
photos property
photos: list[PhotoSchema]
open_monthly property
open_monthly: OpenMonthlySchema
is_active property
is_active: bool
is_public property
is_public: bool
extras property
extras: dict[str, Any]

Classes

FieldNotImplementedError
FieldNotImplementedError(
    obj: BaseHutConverterSchema, field: str
)

Field is not implemented.

Parameters:

Functions

Functions

get_hut
get_hut() -> HutSchema

Convert to hut.

Returns:

BaseHutSourceSchema

Base class for a hut source.

Attributes:

  • source_name (str) –

    Name of the source (e.g. osm, wikipedia, ...).

  • name (str) –

    Original hut name.

  • location (LocationEleSchema | None) –

    Location of the hut.

  • source_id (str) –

    Originial source id of the hut.

  • source_data (TSourceData_co | None) –

    Source data for this hut.

  • source_properties (TProperties_co | None) –

    Additinal source data properties.

  • version (int) –

    Version of the service when this entry was created.

  • created (datetime) –

    Created.

Examples:

class MyHutSource(BaseHutSourceSchema[MyHutSchema, SourcePropertiesSchema]):
    source_name: str = "my"

Or with different properties: hut_services.osm.schema.OsmHutSource.

Methods:

  • __str__
  • show

    Returns a formatted string with the hut information which can be printed.

Attributes:

Attributes

model_config class-attribute instance-attribute
model_config = ConfigDict(coerce_numbers_to_str=True)
source_name class-attribute instance-attribute
source_name: str = Field(
    "unknown",
    description="Name of the source (e.g. osm, wikipedia, ...).",
)
name class-attribute instance-attribute
name: str = Field(..., description='Original hut name.')
location class-attribute instance-attribute
location: LocationEleSchema | None = Field(
    None, description="Location of the hut."
)
source_id class-attribute instance-attribute
source_id: str = Field(
    ..., description="Originial source id of the hut."
)
source_data class-attribute instance-attribute
source_data: TSourceData_co | None = Field(
    None, description="Source data for this hut."
)
source_properties class-attribute instance-attribute
source_properties: TProperties_co | None = Field(
    None, description="Additinal source data properties."
)
version class-attribute instance-attribute
version: int = Field(
    default=0,
    description="Version of the service when this entry was created.",
)
created class-attribute instance-attribute
created: datetime = Field(
    default_factory=now,
    description="Version of the service when this entry was created.",
)
source_properties_schema property
source_properties_schema: dict

Returns JSON schema for the 'source_properties' fields.

Returns:

  • dict

    JSON schema.

Functions

__str__
__str__() -> str
show
show(
    source_id: bool = True,
    location: bool = True,
    elevation: bool = True,
    source_name: bool = True,
    version: bool = False,
    created: bool = False,
) -> str

Returns a formatted string with the hut information which can be printed.

Parameters:

  • source_id
    (bool, default: True ) –

    Show source ID.

  • location
    (bool, default: True ) –

    Show location.

  • elevation
    (bool, default: True ) –

    Show elevation.

  • source_name
    (bool, default: True ) –

    Show source name.

  • version
    (bool, default: False ) –

    Show verions.

  • created
    (bool, default: False ) –

    Show created date.

Returns:

  • str

    Formatted string.

CapacitySchema

Hut capacities.

Hint

For unattended accomodations the opened attribute should be used.

Attributes:

  • open

    Capacity when the hut is open

  • closed

    Capacity when the hut is closed (shelter, winterroom, ...)

Attributes:

Attributes

model_config class-attribute instance-attribute
model_config = ConfigDict(
    from_attributes=True, extra="allow"
)
if_open class-attribute instance-attribute
if_open: NaturalInt | None = Field(
    None,
    alias="open",
    description="Capacity when the hut is open",
)
if_closed class-attribute instance-attribute
if_closed: NaturalInt | None = Field(
    None,
    alias="closed",
    description="Capacity when the hut is closed (shelter, winterroom, ...)",
)

ContactSchema

Schema for a contact.

Attributes:

  • name (str) –

    Contact name (persion or organization), can also be empty.

  • email (str) –

    E-mail address.

  • phone (str) –

    Phone number.

  • mobile (str) –

    Mobule phone number.

  • function (str) –

    Function, e.g. hut warden.

  • url (str) –

    Additional url for this contact (not the hut website).

  • address (str) –

    Address (street, city).

  • note (TranslationSchema) –

    Additional note/information.

  • is_active (bool) –

    Contact is active.

  • is_public (bool) –

    Show contact public.

Methods:

Attributes:

Attributes

model_config class-attribute instance-attribute
model_config = ConfigDict(
    from_attributes=True, extra="allow"
)
name class-attribute instance-attribute
name: str = Field('', max_length=70)
email class-attribute instance-attribute
email: str = Field('', max_length=70)
phone class-attribute instance-attribute
phone: str = Field('', max_length=30)
mobile class-attribute instance-attribute
mobile: str = Field('', max_length=30)
function class-attribute instance-attribute
function: str = Field('', max_length=20)
url class-attribute instance-attribute
url: str = Field('', max_length=200)
address class-attribute instance-attribute
address: str = Field('', max_length=200)
note class-attribute instance-attribute
note: TranslationSchema = Field(
    default_factory=TranslationSchema
)
is_active class-attribute instance-attribute
is_active: bool = True
is_public class-attribute instance-attribute
is_public: bool = False

Functions

extract_phone_numbers classmethod
extract_phone_numbers(
    numbers_string: str, region: str | None
) -> list[str]

Extracts phone numbers from a string and returns them formatted with international code. Uses the phonenumbers package.

Parameters:

  • numbers_string
    (str) –

    A string with phone numbers in it.

  • region
    (str | None) –

    Country code.

Returns:

  • list[str]

    A list with formatted phone numbers.

number_to_phone_or_mobile classmethod
number_to_phone_or_mobile(
    numbers: str | Sequence[str],
    region: str | None,
    formatted: bool = False,
) -> PhoneMobile

Given a phone number it returns it eihter as phone or mobile number. Uses the phonenumbers package.

Parameters:

  • numbers
    (str | Sequence[str]) –

    List or string of phone numbers, they are extraced and the two assigned to phone and mobile.

  • region
    (str | None) –

    Country code.

  • formatted
    (bool, default: False ) –

    Phone list is alreaad formatted

Returns:

  • PhoneMobile

    Tuple with phone and mobile number ((phone, mobile)).

HutSchema

Hut schema.

Attributes:

Methods:

Attributes:

Attributes

model_config class-attribute instance-attribute
model_config = ConfigDict(
    from_attributes=True, extra="allow"
)
slug class-attribute instance-attribute
slug: str = Field('', max_length=50)
name class-attribute instance-attribute
name: TranslationSchema = Field(
    ..., description="Original hut name."
)
location class-attribute instance-attribute
location: LocationEleSchema = Field(
    ...,
    description="Location of the hut with optional elevation.",
)
description class-attribute instance-attribute
description: TranslationSchema = Field(
    default_factory=TranslationSchema
)
license class-attribute instance-attribute
license: LicenseSchema | None = Field(
    None,
    description="License for the hut information (mainly descpription)",
)
source class-attribute instance-attribute
source: SourceSchema | None = Field(
    None,
    description="Source origin information (e.g. 'hrs' for alpsonline.org, or 'sac', 'refuges', ...).",
)
author class-attribute instance-attribute
author: AuthorSchema | None = Field(
    None,
    description="Author of the hut information, this is an addition to the source information (e.g. custom author)",
)
notes class-attribute instance-attribute
notes: Sequence[TranslationSchema] = Field(
    ..., description="Additional notes to the hut."
)
owner class-attribute instance-attribute
owner: OwnerSchema | None = Field(None)
url class-attribute instance-attribute
url: str = Field('', max_length=200)
contacts class-attribute instance-attribute
contacts: Sequence[ContactSchema] = Field(
    default_factory=list
)
country_code class-attribute instance-attribute
country_code: str | None = Field(
    None, max_length=2, min_length=2
)
comment class-attribute instance-attribute
comment: str = Field(
    "",
    max_length=20000,
    description="Additional private comment, e.g for review.",
)
capacity instance-attribute
capacity: CapacitySchema
hut_type class-attribute instance-attribute
hut_type: HutTypeSchema = Field(..., alias='type')
photos class-attribute instance-attribute
photos: list[PhotoSchema] = Field(default_factory=list)
open_monthly instance-attribute
open_monthly: OpenMonthlySchema
is_active class-attribute instance-attribute
is_active: bool = Field(default=True)
is_public class-attribute instance-attribute
is_public: bool = Field(default=True)
extras class-attribute instance-attribute
extras: Mapping[str, Any] = Field(
    default_factory=dict,
    description="Additional information as dictionary.",
)

Functions

__str__
__str__() -> str
add_slug
add_slug() -> HutSchema

HutTypeEnum

Enum with hut types.

Attributes:

Attributes

unknown class-attribute instance-attribute
unknown = 'unknown'
closed class-attribute instance-attribute
closed = 'closed'
campgr class-attribute instance-attribute
campgr = 'campgr'
shelter class-attribute instance-attribute
shelter = 'shelter'
camping class-attribute instance-attribute
camping = 'camping'
bivouac class-attribute instance-attribute
bivouac = 'bivouac'
selfhut class-attribute instance-attribute
selfhut = 'selfhut'
hut class-attribute instance-attribute
hut = 'hut'
alp class-attribute instance-attribute
alp = 'alp'
bhotel class-attribute instance-attribute
bhotel = 'bhotel'
hostel class-attribute instance-attribute
hostel = 'hostel'
hotel class-attribute instance-attribute
hotel = 'hotel'
special class-attribute instance-attribute
special = 'special'
resta class-attribute instance-attribute
resta = 'resta'

HutTypeSchema

Hut type schema.

Defines the type of the hut if it is open and closed. E.g. a hut can be a 'selfhut' if it is closed. If a hut is always open do not add anything to closed. If it is specifcally closed, e.g. during winter ass 'closed'.

Attributes:

  • open

    Type when the hut is open

  • closed

    Type when the hut is closed (bivouac, selfhut, closed, ...)

Attributes:

Attributes

model_config class-attribute instance-attribute
model_config = ConfigDict(
    from_attributes=True, extra="allow"
)
if_open class-attribute instance-attribute
if_open: HutTypeEnum = Field(
    unknown,
    alias="open",
    description="Type when the hut is open",
)
if_closed class-attribute instance-attribute
if_closed: HutTypeEnum | None = Field(
    None,
    alias="closed",
    description="Type when the hut is closed (bivouac, selfhut, closed, ...)",
)

LicenseSchema

License information.

Attributes:

  • slug (str) –

    Identifier or slug of the license (e.g. by-sa, cc-0, ...).

  • url (HttpUrl | None) –

    URL of the license.

  • name (str) –

    Fullname of the license.

Attributes:

Attributes

model_config class-attribute instance-attribute
model_config = ConfigDict(
    from_attributes=True, extra="allow"
)
slug instance-attribute
slug: str
url class-attribute instance-attribute
url: HttpUrl | None = None
name class-attribute instance-attribute
name: str = Field('', max_length=300)

OpenMonthlySchema

Shows for every month if it is usally, open, partially open or closed. Can be accessed as index, but it starts with 1 (month_01)!.

Attributes:

  • url (str) –

    URL which shows if it is open or not.

  • month_mm (OpenMonthly) –

    Month (starting with 01).

Methods:

Attributes:

Attributes

model_config class-attribute instance-attribute
model_config = ConfigDict(
    from_attributes=True, extra="allow"
)
url class-attribute instance-attribute
url: str = Field(
    "", description="URL which shows if it is open or not."
)
month_01 class-attribute instance-attribute
month_01: AnswerEnum = unknown
month_02 class-attribute instance-attribute
month_02: AnswerEnum = unknown
month_03 class-attribute instance-attribute
month_03: AnswerEnum = unknown
month_04 class-attribute instance-attribute
month_04: AnswerEnum = unknown
month_05 class-attribute instance-attribute
month_05: AnswerEnum = unknown
month_06 class-attribute instance-attribute
month_06: AnswerEnum = unknown
month_07 class-attribute instance-attribute
month_07: AnswerEnum = unknown
month_08 class-attribute instance-attribute
month_08: AnswerEnum = unknown
month_09 class-attribute instance-attribute
month_09: AnswerEnum = unknown
month_10 class-attribute instance-attribute
month_10: AnswerEnum = unknown
month_11 class-attribute instance-attribute
month_11: AnswerEnum = unknown
month_12 class-attribute instance-attribute
month_12: AnswerEnum = unknown

Functions

__getitem__
__getitem__(month: int) -> AnswerEnum
__setitem__
__setitem__(month: int, value: AnswerEnum) -> None
__iter__
__iter__()
__next__
__next__() -> AnswerEnum
set_month
set_month(month: int, value: AnswerEnum) -> None

OwnerSchema

Schema for the owner.

Attributes:

  • slug (str) –

    Owner slug, if empty it is replaced by slugified name.

  • name (str) –

    Owner name, required.

  • url (str) –

    Owners URL (not the hut website).

  • note (TranslationSchema) –

    Additonal (public) note to the owner.

  • comment (str) –

    Private comment to the owner.

  • contacts (ContactSchema | None) –

    Contacts used for the owner.

Methods:

Attributes:

Attributes

model_config class-attribute instance-attribute
model_config = ConfigDict(
    from_attributes=True, extra="allow"
)
slug class-attribute instance-attribute
slug: str = Field('', max_length=50)
name class-attribute instance-attribute
name: str = Field(..., max_length=100)
url class-attribute instance-attribute
url: str = Field('', max_length=200)
note class-attribute instance-attribute
note: TranslationSchema = Field(
    default_factory=TranslationSchema
)
comment class-attribute instance-attribute
comment: str = ''
contacts class-attribute instance-attribute
contacts: ContactSchema | None = None

Functions

add_slug
add_slug() -> OwnerSchema

PhotoSchema

Schema for a hut photo.

Attributes:

Attributes

model_config class-attribute instance-attribute
model_config = ConfigDict(
    from_attributes=True, extra="allow"
)
licenses instance-attribute
licenses: list[LicenseSchema]
caption class-attribute instance-attribute
caption: TranslationSchema = Field(
    default_factory=TranslationSchema
)
source instance-attribute
source: SourceSchema | None
author instance-attribute
author: AuthorSchema | None
comment class-attribute instance-attribute
comment: str = Field(
    "",
    max_length=20000,
    description="Additional private comment, e.g for review.",
)
raw_url class-attribute instance-attribute
raw_url: HttpUrl = Field(
    ...,
    description="Url to the raw image, this can be used to download or embed the image.",
)
width class-attribute instance-attribute
width: int = Field(
    ..., description="Image width in pixels."
)
height class-attribute instance-attribute
height: int = Field(
    ..., description="Image height in pixels."
)
url class-attribute instance-attribute
url: HttpUrl = Field(
    ...,
    description="Url to the image on the side, this should not be used to include it direclty, rather to just link to it.",
)
capture_date instance-attribute
capture_date: datetime | None
tags class-attribute instance-attribute
tags: set[str] | None = None

PhotoSchemaOld

Photo schema.

Attributes:

Attributes

model_config class-attribute instance-attribute
model_config = ConfigDict(
    from_attributes=True, extra="allow"
)
attribution class-attribute instance-attribute
attribution: str = Field(
    "",
    description="Attribution, resp. copyright information as markdown text",
)
url instance-attribute
url: str
thumb class-attribute instance-attribute
thumb: str = Field(
    "", description="Url to thumbnail (around 400px)."
)
caption class-attribute instance-attribute
caption: TranslationSchema | None = Field(
    None, description="Original hut name."
)
comment class-attribute instance-attribute
comment: str = Field(
    "",
    max_length=20000,
    description="Additional private comment, e.g for review.",
)
is_public class-attribute instance-attribute
is_public: bool = Field(default=True)

SourceDataSchema

SourceData schema

Methods:

Attributes:

Attributes

model_config class-attribute instance-attribute
model_config = ConfigDict(
    from_attributes=True, extra="allow"
)

Functions

get_id
get_id() -> str

Get source id.

get_name
get_name() -> str

Get source hut name.

SourcePropertiesSchema

Properties saved together with the source data.

Examples:

See hut_services.osm.schema.OsmProperties.

SourceSchema

Source information.

Attributes:

  • ident (str) –

    Identifier or slug of the source.

  • name (str) –

    Name of the source, either person or organization (e.g refuges, wikicommon, sac, ...)

  • url (HttpUrl | None) –

    URL of the source.

Attributes:

Attributes

model_config class-attribute instance-attribute
model_config = ConfigDict(
    from_attributes=True, extra="allow"
)
ident class-attribute instance-attribute
ident: str = Field('', max_length=300)
name class-attribute instance-attribute
name: str = Field('', max_length=300)
url class-attribute instance-attribute
url: HttpUrl | None = None

LocationEleSchema

Location with longitude, latitude and (optional) elevation in WSG84.

Attributes:

Methods:

Attributes:

Attributes

lat instance-attribute
lat: Latitude
lon instance-attribute
lon: Longitude
lon_lat property
lon_lat: tuple[Longitude, Latitude]

Tuple with (longitude, latitude).

Returns:

model_config class-attribute instance-attribute
model_config = ConfigDict(from_attributes=True)
ele class-attribute instance-attribute
ele: Elevation | None = None
lon_lat_ele property
lon_lat_ele: tuple[Longitude, Latitude, Elevation]

Tuple with longitude, latitude and elevation. If elevation is not defined it returns 0.

Returns:

geojson property
geojson: Point

Retuns as geojson point.

Functions

check_field_aliases classmethod
check_field_aliases(data: Any) -> Any
from_swiss classmethod
from_swiss(
    ch_lat: float, ch_lon: float, ele: float | None
) -> LocationEleSchema
__str__
__str__() -> str

LocationSchema

Location with longitude, latitude and optional elevation in WSG84.

Attributes:

Methods:

Attributes:

Attributes

model_config class-attribute instance-attribute
model_config = ConfigDict(from_attributes=True)
lat instance-attribute
lat: Latitude
lon instance-attribute
lon: Longitude
lon_lat property
lon_lat: tuple[Longitude, Latitude]

Tuple with (longitude, latitude).

Returns:

geojson property
geojson: Point

Retuns as geojson point.

Functions

check_field_aliases classmethod
check_field_aliases(data: Any) -> Any
from_swiss classmethod
from_swiss(
    ch_lat: float, ch_lon: float, ele: float | None
) -> LocationSchema | LocationEleSchema

Takes LV03 or LV95 (newest) coordiates. More information.

Parameters:

  • ch_lat
    (float) –

    Latitude in swiss format (east).

  • ch_lon
    (float) –

    Longitude in swiss format (north).

  • ele
    (float | None) –

    Elevation in meter.

Returns:

__str__
__str__() -> str

TranslationSchema

Field with different translations.

Attributes:

Attributes:

Attributes

de class-attribute instance-attribute
de: NoneStr = ''
en class-attribute instance-attribute
en: NoneStr = ''
fr class-attribute instance-attribute
fr: NoneStr = ''
it class-attribute instance-attribute
it: NoneStr = ''
i18n property
i18n: str

Returns the first stored translation in the following order: de, en, fr or it.

BaseService

BaseService(
    support_bbox: bool = False,
    support_limit: bool = False,
    support_offset: bool = False,
    support_convert: bool = False,
    support_booking: bool = False,
)

Base service which is inheritated by other services.

Warning

Do not use this directly.

The following attributes are used to define which paramets are supported by a service.

Attributes:

Examples:

Custom service base in BaseService. For this the two schemas MyHutSource and MyInfoHutConvert need to be defined as well.

from typing import Any
from hut_services.core.schema.geo import BBox
from hut_services import BaseService, HutSchema

# TODO: define this somewhere:
from my_service.schema import MyHutSource, MyInfoHutConvert

class MyService(BaseService[MyHutSource]):
    def __init__(self, request_url: str = "http://hut.info"):
        super().__init__(support_bbox=True,
                         support_limit=True,
                         support_offset=True,
                         support_convert=True)
        self.request_url = request_url

    def get_huts_from_source(
        self, bbox: BBox | None = None, limit: int = 1,
        offset: int = 0, **kwargs: Any
    ) -> list[MyHutSource]:
        src_huts = httpx.get(self.request_url)
        return [MyHutSource(**h) for h in src_huts]

    def convert(self, src: MyHutSource) -> HutSchema:
        return MyInfoHutConvert(source=src.source_data).get_hut()

Classes:

Methods:

Attributes:

Attributes

support_bbox class-attribute instance-attribute
support_bbox: bool = support_bbox
support_limit class-attribute instance-attribute
support_limit: bool = support_limit
support_offset class-attribute instance-attribute
support_offset: bool = support_offset
support_convert class-attribute instance-attribute
support_convert: bool = support_convert
support_booking class-attribute instance-attribute
support_booking: bool = support_booking

Classes

MethodNotImplementedError
MethodNotImplementedError(obj: BaseService, method: str)

Method is not implemented exception.

Parameters:

  • obj
    (BaseService) –

    Service object (e.g. MyService).

  • method
    (str) –

    Method which is not implemented.

Functions

Functions

clear_all_cache classmethod
clear_all_cache() -> None

Clears the cache of all services!

get_huts_from_source
get_huts_from_source(
    bbox: BBox | None = None,
    limit: int = 1,
    offset: int = 0,
    **kwargs: Any,
) -> list[THutSourceSchema]

Get all huts from source.

Parameters:

  • bbox
    (BBox | None, default: None ) –

    Boundary box.

  • limit
    (int, default: 1 ) –

    Limit (how many entries to retrieve).

  • offset
    (int, default: 0 ) –

    Offset of the request.

Returns:

  • list[THutSourceSchema]

    Huts from source.

convert
convert(
    src: Mapping | Any, include_photos: bool = True
) -> HutSchema

Convert one hut from source to HutSchema.

Parameters:

  • src
    (Mapping | Any) –

    Source schema.

  • include_photos
    (bool, default: True ) –

    Include photos, some service need additonal requests to get the photos.

Returns:

get_huts
get_huts(
    bbox: BBox | None = None,
    limit: int = 1,
    offset: int = 0,
    include_photos: bool = True,
    **kwargs: Any,
) -> list[HutSchema]

Get all huts form source and converts them. Calls get_huts_from_source() and convert().

Returns:

  • list[HutSchema]

    Converted huts from source.

get_bookings
get_bookings(
    date: datetime | date | Literal["now"] | None = None,
    days: int | None = None,
    source_ids: list[int | str] | None = None,
    lang: str = "de",
    request_interval: float | None = None,
) -> dict[int | str, HutBookingsSchema]

Get bookings for a list of huts.

Parameters:

  • date
    (datetime | date | Literal['now'] | None, default: None ) –

    Start daye for the bookings

  • days
    (int | None, default: None ) –

    Duration in days

  • source_ids
    (list[int | str] | None, default: None ) –

    A list of ids to return (source id, not the hut id), if set to None all are returned

  • lang
    (str, default: 'de' ) –

    Language for the response

  • request_interval
    (float | None, default: None ) –

    Interval between requests (if each huts needs a request)

Returns:

  • dict[int | str, HutBookingsSchema]

    A dictionary with the bookings (key = source id).

GeocodeService

GeocodeService()

Service to get Information from Nominatim.

Note

This is not used to get huts, rather to get additional info (like location) from huts.

Classes:

Methods:

Attributes:

Attributes

support_bbox class-attribute instance-attribute
support_bbox: bool = support_bbox
support_limit class-attribute instance-attribute
support_limit: bool = support_limit
support_offset class-attribute instance-attribute
support_offset: bool = support_offset
support_convert class-attribute instance-attribute
support_convert: bool = support_convert
support_booking class-attribute instance-attribute
support_booking: bool = support_booking
loc_request_url instance-attribute
loc_request_url = (
    "https://nominatim.openstreetmap.org/search"
)
ele_request_url instance-attribute
ele_request_url = (
    "https://api.open-elevation.com/api/v1/lookup"
)
httpx_client instance-attribute
httpx_client = Client()

Classes

MethodNotImplementedError
MethodNotImplementedError(obj: BaseService, method: str)

Method is not implemented exception.

Parameters:

  • obj
    (BaseService) –

    Service object (e.g. MyService).

  • method
    (str) –

    Method which is not implemented.

Functions

Functions

clear_all_cache classmethod
clear_all_cache() -> None

Clears the cache of all services!

get_huts_from_source
get_huts_from_source(
    bbox: BBox | None = None,
    limit: int = 1,
    offset: int = 0,
    **kwargs: Any,
) -> list[THutSourceSchema]

Get all huts from source.

Parameters:

  • bbox
    (BBox | None, default: None ) –

    Boundary box.

  • limit
    (int, default: 1 ) –

    Limit (how many entries to retrieve).

  • offset
    (int, default: 0 ) –

    Offset of the request.

Returns:

  • list[THutSourceSchema]

    Huts from source.

get_huts
get_huts(
    bbox: BBox | None = None,
    limit: int = 1,
    offset: int = 0,
    include_photos: bool = True,
    **kwargs: Any,
) -> list[HutSchema]

Get all huts form source and converts them. Calls get_huts_from_source() and convert().

Returns:

  • list[HutSchema]

    Converted huts from source.

get_bookings
get_bookings(
    date: datetime | date | Literal["now"] | None = None,
    days: int | None = None,
    source_ids: list[int | str] | None = None,
    lang: str = "de",
    request_interval: float | None = None,
) -> dict[int | str, HutBookingsSchema]

Get bookings for a list of huts.

Parameters:

  • date
    (datetime | date | Literal['now'] | None, default: None ) –

    Start daye for the bookings

  • days
    (int | None, default: None ) –

    Duration in days

  • source_ids
    (list[int | str] | None, default: None ) –

    A list of ids to return (source id, not the hut id), if set to None all are returned

  • lang
    (str, default: 'de' ) –

    Language for the response

  • request_interval
    (float | None, default: None ) –

    Interval between requests (if each huts needs a request)

Returns:

  • dict[int | str, HutBookingsSchema]

    A dictionary with the bookings (key = source id).

get_location_by_name
get_location_by_name(
    name: str, client: Client | None = None
) -> LocationEleSchema | None

Get location (coordinates) from a name (uses 'https://nominatim.openstreetmap.org).

get_elevations
get_elevations(
    locations: Sequence[LocationSchema | LocationEleSchema],
    client: Client | None = None,
) -> list[LocationEleSchema]

Get elevations from a list of locations (coordinates) (uses 'https://open-elevation.com).

get_elevation
get_elevation(
    location: LocationSchema | LocationEleSchema,
    client: Client | None = None,
) -> LocationEleSchema

Get elevation from a location (coordinates) (uses 'https://open-elevation.com).

convert
convert(
    src: Mapping | Any, include_photos: bool = True
) -> HutSchema

OsmService

OsmService(
    request_url: str = "https://overpass.osm.ch/api/",
)

Service to get huts from Open Street Map with overpass api.

Note

The methods are descriebed in BaseService.

Classes:

Methods:

Attributes:

Attributes

support_bbox class-attribute instance-attribute
support_bbox: bool = support_bbox
support_limit class-attribute instance-attribute
support_limit: bool = support_limit
support_offset class-attribute instance-attribute
support_offset: bool = support_offset
support_convert class-attribute instance-attribute
support_convert: bool = support_convert
support_booking class-attribute instance-attribute
support_booking: bool = support_booking
request_url instance-attribute
request_url = request_url

Classes

MethodNotImplementedError
MethodNotImplementedError(obj: BaseService, method: str)

Method is not implemented exception.

Parameters:

  • obj
    (BaseService) –

    Service object (e.g. MyService).

  • method
    (str) –

    Method which is not implemented.

Functions

Functions

clear_all_cache classmethod
clear_all_cache() -> None

Clears the cache of all services!

get_huts
get_huts(
    bbox: BBox | None = None,
    limit: int = 1,
    offset: int = 0,
    include_photos: bool = True,
    **kwargs: Any,
) -> list[HutSchema]

Get all huts form source and converts them. Calls get_huts_from_source() and convert().

Returns:

  • list[HutSchema]

    Converted huts from source.

get_bookings
get_bookings(
    date: datetime | date | Literal["now"] | None = None,
    days: int | None = None,
    source_ids: list[int | str] | None = None,
    lang: str = "de",
    request_interval: float | None = None,
) -> dict[int | str, HutBookingsSchema]

Get bookings for a list of huts.

Parameters:

  • date
    (datetime | date | Literal['now'] | None, default: None ) –

    Start daye for the bookings

  • days
    (int | None, default: None ) –

    Duration in days

  • source_ids
    (list[int | str] | None, default: None ) –

    A list of ids to return (source id, not the hut id), if set to None all are returned

  • lang
    (str, default: 'de' ) –

    Language for the response

  • request_interval
    (float | None, default: None ) –

    Interval between requests (if each huts needs a request)

Returns:

  • dict[int | str, HutBookingsSchema]

    A dictionary with the bookings (key = source id).

get_huts_from_source
get_huts_from_source(
    bbox: BBox | None = None,
    limit: int = 1,
    offset: int = 0,
    **kwargs: dict,
) -> list[OsmHutSource]
convert
convert(
    src: Mapping | Any, include_photos: bool = True
) -> HutSchema

RefugesInfoService

RefugesInfoService(
    request_url: str = "https://www.refuges.info/api",
)

Service to get huts from refuges.info with its api.

Note

The methods are descriebed in BaseService.

Classes:

Methods:

Attributes:

Attributes

support_bbox class-attribute instance-attribute
support_bbox: bool = support_bbox
support_limit class-attribute instance-attribute
support_limit: bool = support_limit
support_offset class-attribute instance-attribute
support_offset: bool = support_offset
support_convert class-attribute instance-attribute
support_convert: bool = support_convert
support_booking class-attribute instance-attribute
support_booking: bool = support_booking
request_url instance-attribute
request_url = request_url

Classes

MethodNotImplementedError
MethodNotImplementedError(obj: BaseService, method: str)

Method is not implemented exception.

Parameters:

  • obj
    (BaseService) –

    Service object (e.g. MyService).

  • method
    (str) –

    Method which is not implemented.

Functions

Functions

clear_all_cache classmethod
clear_all_cache() -> None

Clears the cache of all services!

get_huts
get_huts(
    bbox: BBox | None = None,
    limit: int = 1,
    offset: int = 0,
    include_photos: bool = True,
    **kwargs: Any,
) -> list[HutSchema]

Get all huts form source and converts them. Calls get_huts_from_source() and convert().

Returns:

  • list[HutSchema]

    Converted huts from source.

get_bookings
get_bookings(
    date: datetime | date | Literal["now"] | None = None,
    days: int | None = None,
    source_ids: list[int | str] | None = None,
    lang: str = "de",
    request_interval: float | None = None,
) -> dict[int | str, HutBookingsSchema]

Get bookings for a list of huts.

Parameters:

  • date
    (datetime | date | Literal['now'] | None, default: None ) –

    Start daye for the bookings

  • days
    (int | None, default: None ) –

    Duration in days

  • source_ids
    (list[int | str] | None, default: None ) –

    A list of ids to return (source id, not the hut id), if set to None all are returned

  • lang
    (str, default: 'de' ) –

    Language for the response

  • request_interval
    (float | None, default: None ) –

    Interval between requests (if each huts needs a request)

Returns:

  • dict[int | str, HutBookingsSchema]

    A dictionary with the bookings (key = source id).

get_huts_from_source
get_huts_from_source(
    bbox: BBox | None = None,
    limit: int = 1,
    offset: int = 0,
    **kwargs: Any,
) -> list[RefugesInfoHutSource]
convert
convert(
    src: Mapping | Any, include_photos: bool = True
) -> HutSchema

Functions

file_cache

file_cache(
    func: None | Callable = None,
    ignore: Sequence = [],
    expire_in_seconds: int = default_seconds,
    forever: bool = False,
) -> Any

Chaches function, if 'forever' is True, cache will never expire (and 'expire_in_seconds' will be ignored).