2727# noinspection PyAttributeOutsideInit
2828class Nse :
2929 version : str = '5.2'
30- beta : Tuple [bool , int ] = (True , 13 )
30+ beta : Tuple [bool , int ] = (True , 14 )
3131
3232 def __init__ (self , window : Tk ) -> None :
3333 self .intervals : List [int ] = [1 , 2 , 3 , 5 , 10 , 15 ]
@@ -55,7 +55,7 @@ def __init__(self, window: Tk) -> None:
5555 'like Gecko) Chrome/80.0.3987.149 Safari/537.36' ,
5656 'accept-language' : 'en,gu;q=0.9,hi;q=0.8' ,
5757 'accept-encoding' : 'gzip, deflate, br' }
58- self .get_symbols ()
58+ self .get_symbols (window )
5959 self .config_parser : configparser .ConfigParser = configparser .ConfigParser ()
6060 self .create_config (new = True ) if not os .path .isfile ('NSE-OCA.ini' ) else None
6161 self .get_config ()
@@ -75,17 +75,29 @@ def __init__(self, window: Tk) -> None:
7575 self .get_icon ()
7676 self .login_win (window )
7777
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+
7989 try :
8090 symbols_information : requests .Response = requests .get (self .url_symbols , headers = self .headers )
8191 except Exception as err :
8292 print (err , sys .exc_info ()[0 ], "19" )
93+ create_error_window (window )
8394 sys .exit ()
8495 symbols_information_soup : bs4 .BeautifulSoup = bs4 .BeautifulSoup (symbols_information .content , "html.parser" )
8596 try :
8697 symbols_table : bs4 .element .Tag = symbols_information_soup .findChildren ('table' )[0 ]
8798 except IndexError as err :
8899 print (err , sys .exc_info ()[0 ], "20" )
100+ create_error_window (window )
89101 sys .exit ()
90102 symbols_table_rows : List [bs4 .element .Tag ] = list (symbols_table .findChildren (['th' , 'tr' ]))
91103 symbols_table_rows_str : List [str ] = ['' for _ in range (len (symbols_table_rows ) - 1 )]
0 commit comments