-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathdata_retrive_utility.py
67 lines (54 loc) · 2.28 KB
/
data_retrive_utility.py
1
2
3
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
from urllib import request
import requests
from typing import List, Dict
from .json_utility import JsonUtility
class DataRetriveUtility:
CONTRIBUTORS_TEXT_URL = "https://raw.githubusercontent.com/Thisal-D/PyTube-Downloader/main/contributors.txt"
VERSION_FILE_URL = "https://raw.githubusercontent.com/Thisal-D/PyTube-Downloader/main/VERSION"
@staticmethod
def get_contributors_data() -> List[Dict]:
"""
Retrieve contributors data from a GitHub repository.
Returns:
list: A list of dictionaries containing contributor information.
"""
contributors = []
try:
data = requests.get(DataRetriveUtility.CONTRIBUTORS_TEXT_URL, timeout=5).text
for contributor_data in data.split("\n"):
try:
profile_url, username = contributor_data.split("@%@")
contributors.append({
"profile_url": profile_url,
"user_name": username,
})
except Exception as error:
print(f"data_retrive_utility.py L54 : {error}")
except Exception as error:
print(f"data_retrive_utility.py L43 : {error}")
return None
return contributors
@staticmethod
def get_latest_version():
"""
Retrieve latest version from a GitHub repository.
Returns:
string: The latest version number.
"""
try:
data = requests.get(DataRetriveUtility.VERSION_FILE_URL, timeout=5).text.strip()
# Extract the version number from the string "VERSION = '2.0.2'"
# Split at "=" and remove extra characters like spaces and quotes
version = data.split('=')[1].strip().strip("'")
except Exception as error:
print(f"data_retrive_utility.py L43 : {error}")
return None
return version
def get_current_version():
"""
Read current version from info.json file.
return:
string: current version
"""
version = JsonUtility.read_from_file("data\\info.json")["version"]
return version