-
-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #159 from Dineshkarthik/feature-check-for-new-rele…
…ases Check for new releases
- Loading branch information
Showing
4 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""Utility module to check for new release of telegram-media-downloader""" | ||
import http.client | ||
import json | ||
|
||
from rich.console import Console | ||
from rich.markdown import Markdown | ||
|
||
from . import __version__ | ||
|
||
# pylint: disable = C0301 | ||
def check_for_updates() -> None: | ||
"""Checks for new releases. | ||
Using Github API checks for new release and prints information of new release if available. | ||
""" | ||
try: | ||
headers: dict = { | ||
"Content-Type": "application/json", | ||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36", | ||
} | ||
conn = http.client.HTTPSConnection("api.github.com") | ||
conn.request( | ||
method="GET", | ||
url="/repos/Dineshkarthik/telegram_media_downloader/releases/latest", | ||
headers=headers, | ||
) | ||
res = conn.getresponse() | ||
latest_release: dict = json.loads(res.read().decode("utf-8")) | ||
if f"v{__version__}" != latest_release["tag_name"]: | ||
update_message: str = ( | ||
f"## New versionof Telegram-Media-Downloader is available - {latest_release['name']}\n" | ||
f"You are using an outdated version v{__version__} please pull in the changes using `git pull` or download the latest release.\n\n" | ||
f"Find more details about the latest release here - {latest_release['html_url']}" | ||
) | ||
console = Console() | ||
console.print(Markdown(update_message)) | ||
except Exception: | ||
pass |