Skip to content

Commit c404133

Browse files
committed
- Prevents crashing the program if icon fails to load correctly
- Runs the program with the default icon instead
1 parent 1245e79 commit c404133

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

NSE_Option_Chain_Analyzer.py

Lines changed: 30 additions & 11 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, 10)
30+
beta: Tuple[bool, int] = (True, 11)
3131

3232
def __init__(self, window: Tk) -> None:
3333
self.intervals: List[int] = [1, 2, 3, 5, 10, 15]
@@ -114,17 +114,36 @@ def get_icon(self) -> None:
114114
self.load_nse_icon = True
115115
except AttributeError:
116116
if self.load_nse_icon:
117-
icon_png_raw: requests.Response = requests.get(self.url_icon_png, headers=self.headers, stream=True)
118-
with open('.NSE-OCA.png', 'wb') as f:
119-
for chunk in icon_png_raw.iter_content(1024):
120-
f.write(chunk)
121-
self.icon_png_path = '.NSE-OCA.png'
122-
if is_windows_10:
123-
icon_ico_raw: requests.Response = requests.get(self.url_icon_ico, headers=self.headers, stream=True)
124-
with open('.NSE-OCA.ico', 'wb') as f:
125-
for chunk in icon_ico_raw.iter_content(1024):
117+
try:
118+
icon_png_raw: Optional[requests.Response] = requests.get(self.url_icon_png, headers=self.headers,
119+
stream=True)
120+
if icon_png_raw is None:
121+
self.load_nse_icon = False
122+
return
123+
with open('.NSE-OCA.png', 'wb') as f:
124+
for chunk in icon_png_raw.iter_content(1024):
126125
f.write(chunk)
127-
self.icon_ico_path = '.NSE-OCA.ico'
126+
self.icon_png_path = '.NSE-OCA.png'
127+
PhotoImage(file=self.icon_png_path)
128+
except Exception as err:
129+
print(err, sys.exc_info()[0], "17")
130+
self.load_nse_icon = False
131+
return
132+
if is_windows_10:
133+
try:
134+
icon_ico_raw: Optional[requests.Response] = requests.get(self.url_icon_ico,
135+
headers=self.headers, stream=True)
136+
if icon_ico_raw is None:
137+
self.icon_ico_path = None
138+
return
139+
with open('.NSE-OCA.ico', 'wb') as f:
140+
for chunk in icon_ico_raw.iter_content(1024):
141+
f.write(chunk)
142+
self.icon_ico_path = '.NSE-OCA.ico'
143+
except Exception as err:
144+
print(err, sys.exc_info()[0], "18")
145+
self.icon_ico_path = None
146+
return
128147

129148
def check_for_updates(self, auto: bool = True) -> None:
130149
release_data: requests.Response = requests.get(

0 commit comments

Comments
 (0)