2024-04-28 15:19:47 +02:00

60 lines
1.8 KiB
Python

# 01.03.2023
import os
import requests
import time
# Internal utilities
from .version import __version__
from Src.Util.console import console
# Variable
repo_name = "StreamingCommunity_api"
repo_user = "ghost6446"
main = os.path.abspath(os.path.dirname(__file__))
def update():
"""
Check for updates on GitHub and display relevant information.
"""
console.print("[green]Checking GitHub version [white]...")
# Make the GitHub API requests and handle potential errors
try:
response_reposity = requests.get(f"https://api.github.com/repos/{repo_user}/{repo_name}").json()
response_releases = requests.get(f"https://api.github.com/repos/{repo_user}/{repo_name}/releases").json()
except requests.RequestException as e:
console.print(f"[red]Error accessing GitHub API: {e}")
return
# Get start of the reposity
stargazers_count = response_reposity['stargazers_count']
# Find info about latest versione deploy and the donwload count
last_version = response_releases[0]['name']
down_count = response_releases[0]['assets'][0]['download_count']
# Calculate percentual of start base on download count
if down_count > 0 and stargazers_count > 0:
percentual_stars = round(stargazers_count / down_count * 100, 2)
else:
percentual_stars = 0
# Check installed version
if __version__ != last_version:
console.print(f"[red]Version: [yellow]{last_version}")
else:
console.print(f"[red]Everything up to date")
print("\n")
console.print(f"[red]{repo_name} was downloaded [yellow]{down_count} [red]times, but only [yellow]{percentual_stars}% [red]of You(!!) have starred it.\n\
[cyan]Help the repository grow today, by leaving a [yellow]star [cyan]and [yellow]sharing [cyan]it to others online!")
time.sleep(3)
print("\n")