Skip to content

Commit a7e0c34

Browse files
author
yasht01
committed
Fix merge conflicts
2 parents f335f2d + 8953712 commit a7e0c34

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-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",
@@ -39,6 +41,11 @@
3941
help="Set a custom API key",
4042
action="store_true")
4143

44+
parser.add_argument("-u",
45+
"--update",
46+
help="Check updates for the application",
47+
action="store_true")
48+
4249
ARGV = parser.parse_args()
4350

4451
search_flag = Search(ARGV)

src/arguments/search.py

Lines changed: 8 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,8 +40,14 @@ def search_args(self):
3940
webbrowser.open(f"{url}?title={self.arguments.new}")
4041
else:
4142
webbrowser.open(url)
43+
<<<<<<< HEAD
4244
elif self.arguments.custom:
4345
self.utility_object.setCustomKey()
46+
=======
47+
elif self.arguments.update:
48+
update = UpdateApplication(version)
49+
update.check_for_updates()
50+
>>>>>>> 8953712129b15eb66ca2240c2e01e01e3bcfd7ee
4451

4552
def search_for_results(self, save=False):
4653
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)