| 1 |
"""Picture of the Day Python model for the Météo-France REST API.""" |
| 2 |
|
| 3 |
from typing import TypedDict |
| 4 |
|
| 5 |
|
| 6 |
class PictureOfTheDayData(TypedDict): |
| 7 |
"""Describing the data structure of ImageJour object.""" |
| 8 |
|
| 9 |
image_url: str |
| 10 |
description: str |
| 11 |
|
| 12 |
|
| 13 |
class PictureOfTheDay: |
| 14 |
"""Class to access the results of a `ImageJour/last` REST API request. |
| 15 |
|
| 16 |
Attributes: |
| 17 |
image_url: A string corresponding to the picture of the day URL. |
| 18 |
image_hd_url: A string corresponding to the URL for the HD version of the |
| 19 |
picture of the day. |
| 20 |
description: A string with the description of the picture of the day. |
| 21 |
""" |
| 22 |
|
| 23 |
def __init__(self, raw_data: PictureOfTheDayData) -> None: |
| 24 |
"""Initialize a PictureOfTheDay object. |
| 25 |
|
| 26 |
Args: |
| 27 |
raw_data: A dictionary representing the JSON response from 'ImageJour/last' |
| 28 |
REST API request. The structure is described by the PictureOfTheDayData |
| 29 |
class. |
| 30 |
""" |
| 31 |
self.raw_data = raw_data |
| 32 |
|
| 33 |
@property |
| 34 |
def image_url(self) -> str: |
| 35 |
"""Return the image URL of the picture of the day.""" |
| 36 |
return self.raw_data["image_url"] |
| 37 |
|
| 38 |
@property |
| 39 |
def description(self) -> str: |
| 40 |
"""Return the description of the picture of the day.""" |
| 41 |
return self.raw_data["description"] |