1+ import requests as requests
2+ from termcolor import colored
3+ import webbrowser as webbrowser
4+
5+ from .error import SearchError
6+
7+ class UpdateApplication (object ):
8+ def __init__ (self , current_version ):
9+
10+ """
11+ Check for updates in the application
12+
13+ Check for updates in the application
14+ via github's public api. The application
15+ checks for the latest release and make
16+ sure that the version of the application
17+ is same as the latest release tag
18+
19+ """
20+ self .current_version = current_version
21+ self .release_api_url = "https://api.github.com/repos/IndianOpenSourceFoundation/dynamic-cli/releases/latest"
22+
23+ def check_for_updates (self ):
24+ try :
25+ data = requests .get (self .release_api_url )
26+ data = data .json ()
27+ if 'message' in data :
28+ if data ['message' ] == "Not Found" :
29+ print (colored ("The application do not have any release" , "yellow" ))
30+ return None
31+
32+ if data ["tag_name" ] == self .current_version :
33+ print (colored ("Yeah! You have the latest version" , "green" ))
34+ else :
35+ print (colored (f"New release found - { data .tag_name } " , "red" ))
36+ webbrowser .open (data ["html_url" ])
37+
38+ except Exception as exception :
39+ exception = SearchError (str (exception ), "Try later" )
0 commit comments