Skip to content

Location

Module for location class.

Location

Location Class.

Class representing location data.

Source code in report_generator/location_formatter/location.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class Location:
    """Location Class.

    Class representing location data.

    """

    def __init__(
        self,
        continent: str = "NoContinent",
        country: str = "NoCountry",
        region: str = "NoRegion",
        latitude: float = None,
        longitude: float = None,
        country_code="",
        country_full_name: str = "",
    ) -> None:
        """Class init.

        Init method for Location class

        Args:
            continent: continent name string
            country: country name string
            region: region name string
            latitiude: latitude float
            longitude: longitude float
            country_code: 2 letter country code string
            country_full_name: official full name of country string

        """
        self.country = country
        self.continent = continent
        self.region = region
        self.latitude = latitude
        self.longitude = longitude
        self.country_code = country_code
        self.country_full_name = country_full_name

    def get_location_obj(self) -> dict:
        """Get location object.

        Creates a python object based on location data.

        Returns:
            location_obj: python object representing location information.

        """
        return {
            "region": self.region,
            "country": self.country,
            "country_code": self.country_code,
            "continent": self.continent,
            "latitude": self.latitude,
            "longitude": self.longitude,
            "country_full_name": self.country_full_name,
        }

    def __str__(self):
        """Get string magic method."""
        data = [
            self.continent.title(),
            self.country.title(),
            self.region.title(),
            str(self.latitude),
            str(self.longitude),
            self.country_code.upper(),
        ]
        return "_".join(data)

__init__(continent='NoContinent', country='NoCountry', region='NoRegion', latitude=None, longitude=None, country_code='', country_full_name='')

Class init.

Init method for Location class

Parameters:

Name Type Description Default
continent str

continent name string

'NoContinent'
country str

country name string

'NoCountry'
region str

region name string

'NoRegion'
latitiude

latitude float

required
longitude float

longitude float

None
country_code

2 letter country code string

''
country_full_name str

official full name of country string

''
Source code in report_generator/location_formatter/location.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
def __init__(
    self,
    continent: str = "NoContinent",
    country: str = "NoCountry",
    region: str = "NoRegion",
    latitude: float = None,
    longitude: float = None,
    country_code="",
    country_full_name: str = "",
) -> None:
    """Class init.

    Init method for Location class

    Args:
        continent: continent name string
        country: country name string
        region: region name string
        latitiude: latitude float
        longitude: longitude float
        country_code: 2 letter country code string
        country_full_name: official full name of country string

    """
    self.country = country
    self.continent = continent
    self.region = region
    self.latitude = latitude
    self.longitude = longitude
    self.country_code = country_code
    self.country_full_name = country_full_name

__str__()

Get string magic method.

Source code in report_generator/location_formatter/location.py
62
63
64
65
66
67
68
69
70
71
72
def __str__(self):
    """Get string magic method."""
    data = [
        self.continent.title(),
        self.country.title(),
        self.region.title(),
        str(self.latitude),
        str(self.longitude),
        self.country_code.upper(),
    ]
    return "_".join(data)

get_location_obj()

Get location object.

Creates a python object based on location data.

Returns:

Name Type Description
location_obj dict

python object representing location information.

Source code in report_generator/location_formatter/location.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def get_location_obj(self) -> dict:
    """Get location object.

    Creates a python object based on location data.

    Returns:
        location_obj: python object representing location information.

    """
    return {
        "region": self.region,
        "country": self.country,
        "country_code": self.country_code,
        "continent": self.continent,
        "latitude": self.latitude,
        "longitude": self.longitude,
        "country_full_name": self.country_full_name,
    }