Skip to content

Commit 8953712

Browse files
Merge pull request #74 from pranavbaburaj/master
Updating the application #74
2 parents 73eb14a + 5ee6554 commit 8953712

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

main.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import argparse
44
from src.arguments.search import Search
55

6-
version = "0.1"
6+
7+
version = "0.1.0"
78

89
parser = argparse.ArgumentParser()
910
parser.add_argument("-st",
@@ -21,6 +22,7 @@
2122
version=f"Dynamic-CLI version {version}",
2223
action='version')
2324

25+
2426
parser.add_argument(
2527
"-n",
2628
"--new",
@@ -34,6 +36,11 @@
3436
help="Save answer to a file",
3537
action="store_true")
3638

39+
parser.add_argument("-u",
40+
"--update",
41+
help="Check updates for the application",
42+
action="store_true")
43+
3744
ARGV = parser.parse_args()
3845

3946
search_flag = Search(ARGV)

src/arguments/search.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
from .error import SearchError
88
from .utility import Utility
99
from .save import SaveSearchResults
10+
from .update import UpdateApplication
1011

11-
12+
version = "0.1.0"
1213
class Prompt():
1314
def __init__(self, message):
1415
self.message = message
@@ -39,6 +40,9 @@ def search_args(self):
3940
webbrowser.open(f"{url}?title={self.arguments.new}")
4041
else:
4142
webbrowser.open(url)
43+
elif self.arguments.update:
44+
update = UpdateApplication(version)
45+
update.check_for_updates()
4246

4347
def search_for_results(self, save=False):
4448
queries = ["What do you want to search", "Tags"]

src/arguments/update.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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

Comments
 (0)