27
27
# noinspection PyAttributeOutsideInit
28
28
class Nse :
29
29
version : str = '5.2'
30
- beta : Tuple [bool , int ] = (True , 13 )
30
+ beta : Tuple [bool , int ] = (True , 14 )
31
31
32
32
def __init__ (self , window : Tk ) -> None :
33
33
self .intervals : List [int ] = [1 , 2 , 3 , 5 , 10 , 15 ]
@@ -55,7 +55,7 @@ def __init__(self, window: Tk) -> None:
55
55
'like Gecko) Chrome/80.0.3987.149 Safari/537.36' ,
56
56
'accept-language' : 'en,gu;q=0.9,hi;q=0.8' ,
57
57
'accept-encoding' : 'gzip, deflate, br' }
58
- self .get_symbols ()
58
+ self .get_symbols (window )
59
59
self .config_parser : configparser .ConfigParser = configparser .ConfigParser ()
60
60
self .create_config (new = True ) if not os .path .isfile ('NSE-OCA.ini' ) else None
61
61
self .get_config ()
@@ -75,17 +75,29 @@ def __init__(self, window: Tk) -> None:
75
75
self .get_icon ()
76
76
self .login_win (window )
77
77
78
- def get_symbols (self ) -> None :
78
+ def get_symbols (self , window : Tk ) -> None :
79
+ def create_error_window (error_window : Tk ):
80
+ error_window .title ("NSE-Option-Chain-Analyzer" )
81
+ window_width : int = error_window .winfo_reqwidth ()
82
+ window_height : int = error_window .winfo_reqheight ()
83
+ position_right : int = int (error_window .winfo_screenwidth () / 2 - window_width / 2 )
84
+ position_down : int = int (error_window .winfo_screenheight () / 2 - window_height / 2 )
85
+ error_window .geometry ("320x160+{}+{}" .format (position_right , position_down ))
86
+ messagebox .showerror (title = "Error" , message = "Failed to fetch Symbols.\n The program will now exit." )
87
+ error_window .destroy ()
88
+
79
89
try :
80
90
symbols_information : requests .Response = requests .get (self .url_symbols , headers = self .headers )
81
91
except Exception as err :
82
92
print (err , sys .exc_info ()[0 ], "19" )
93
+ create_error_window (window )
83
94
sys .exit ()
84
95
symbols_information_soup : bs4 .BeautifulSoup = bs4 .BeautifulSoup (symbols_information .content , "html.parser" )
85
96
try :
86
97
symbols_table : bs4 .element .Tag = symbols_information_soup .findChildren ('table' )[0 ]
87
98
except IndexError as err :
88
99
print (err , sys .exc_info ()[0 ], "20" )
100
+ create_error_window (window )
89
101
sys .exit ()
90
102
symbols_table_rows : List [bs4 .element .Tag ] = list (symbols_table .findChildren (['th' , 'tr' ]))
91
103
symbols_table_rows_str : List [str ] = ['' for _ in range (len (symbols_table_rows ) - 1 )]
0 commit comments