Skip to content

Commit 2cc3421

Browse files
committed
- Prevents crashing the program if it fails to check for updates
1 parent abfa9de commit 2cc3421

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

NSE_Option_Chain_Analyzer.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# noinspection PyAttributeOutsideInit
2828
class Nse:
2929
version: str = '5.2'
30-
beta: Tuple[bool, int] = (True, 14)
30+
beta: Tuple[bool, int] = (True, 15)
3131

3232
def __init__(self, window: Tk) -> None:
3333
self.intervals: List[int] = [1, 2, 3, 5, 10, 15]
@@ -50,6 +50,8 @@ def __init__(self, window: Tk) -> None:
5050
"Python-NSE-Option-Chain-Analyzer/master/nse_logo.png"
5151
self.url_icon_ico: str = "https://raw.githubusercontent.com/VarunS2002/" \
5252
"Python-NSE-Option-Chain-Analyzer/master/nse_logo.ico"
53+
self.url_update: str = "https://api.github.com/repos/VarunS2002/" \
54+
"Python-NSE-Option-Chain-Analyzer/releases/latest"
5355
self.headers: Dict[str, str] = {
5456
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, '
5557
'like Gecko) Chrome/80.0.3987.149 Safari/537.36',
@@ -159,10 +161,17 @@ def get_icon(self) -> None:
159161
return
160162

161163
def check_for_updates(self, auto: bool = True) -> None:
162-
release_data: requests.Response = requests.get(
163-
"https://api.github.com/repos/VarunS2002/Python-NSE-Option-Chain-Analyzer/releases/latest",
164-
headers=self.headers, timeout=5)
165-
latest_version: str = release_data.json()['tag_name']
164+
try:
165+
release_data: requests.Response = requests.get(self.url_update, headers=self.headers, timeout=5)
166+
latest_version: str = release_data.json()['tag_name']
167+
float(latest_version)
168+
except Exception as err:
169+
print(err, sys.exc_info()[0], "21")
170+
if not auto:
171+
self.info.attributes('-topmost', False)
172+
messagebox.showerror(title="Error", message="Failed to check for updates.")
173+
self.info.attributes('-topmost', True)
174+
return
166175

167176
if float(latest_version) > float(Nse.version):
168177
self.info.attributes('-topmost', False) if not auto else None

0 commit comments

Comments
 (0)