Skip to content

Commit

Permalink
Updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
FredHaa committed Jan 3, 2024
1 parent 0565d38 commit de5ad21
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
12 changes: 6 additions & 6 deletions docs/source/mediacatch_s2t.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ mediacatch\_s2t package
Submodules
----------

mediacatch\_s2t.helper module
-----------------------------
mediacatch\_s2t.uploader module
-------------------------------

.. automodule:: mediacatch_s2t.helper
.. automodule:: mediacatch_s2t.uploader
:members:
:undoc-members:
:show-inheritance:

mediacatch\_s2t.uploader module
-------------------------------
mediacatch\_s2t.helper module
-----------------------------

.. automodule:: mediacatch_s2t.uploader
.. automodule:: mediacatch_s2t.helper
:members:
:undoc-members:
:show-inheritance:
Expand Down
30 changes: 30 additions & 0 deletions src/mediacatch_s2t/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@


def read_installed_version() -> str:
"""
Reads and returns the installed version of the specified package.
Returns:
str: The installed version of the package. Returns '0.0.0' if the package is not found.
"""
try:
_version: str = version(_PACKAGE_NAME)
except PackageNotFoundError:
Expand All @@ -20,6 +26,12 @@ def read_installed_version() -> str:


def check_latest_version() -> Union[str, None]:
"""
Checks and returns the latest available version of the specified package from PyPI.
Returns:
Union[str, None]: The latest version available on PyPI. Returns None if there is a request exception or if the version information is not available.
"""
try:
response = requests.get(f"https://pypi.org/pypi/{_PACKAGE_NAME}/json")
latest_version: str = response.json()['info']['version']
Expand All @@ -29,6 +41,12 @@ def check_latest_version() -> Union[str, None]:


def get_last_updated() -> int:
"""
Retrieves the timestamp of the last update from the environment variable.
Returns:
int: The timestamp of the last update. Returns 0 if the environment variable is not set or cannot be converted to an integer.
"""
_last_updated = os.environ.get('MEDIACATCH_S2T_LAST_UPDATE', 0)
try:
last_updated = int(_last_updated)
Expand All @@ -38,12 +56,24 @@ def get_last_updated() -> int:


def set_last_update() -> None:
"""
Updates the environment variable 'MEDIACATCH_S2T_LAST_UPDATE' with the current timestamp.
Returns:
None
"""
timestamp_now: int = int(datetime.now().timestamp())
os.environ['MEDIACATCH_S2T_LAST_UPDATE']: str = str(timestamp_now)
return None


def update_myself() -> bool:
"""
Updates the package if a newer version is available and the last update was longer ago than the specified duration.
Returns:
bool: True if the package was updated, False otherwise.
"""
timestamp_now = int(datetime.now().timestamp())
timestamp_last_updated = get_last_updated()
latest_update_in_seconds = timestamp_now - timestamp_last_updated
Expand Down

0 comments on commit de5ad21

Please sign in to comment.