@@ -64,19 +64,27 @@ def delete_file(file):
6464
6565
6666# fetch the latest academic calendar from the iitkgp website
67- def get_latest_calendar ():
67+ def get_latest_calendar (is_web = False ):
6868 filename = get_latest_calendar_name ()
6969 url = 'https://www.iitkgp.ac.in/assets/pdf/' + filename
7070
71- ## delete any old academic calander pdf if exists
72- if (is_file_present (filename )):
71+ if is_web and is_file_present (filename ):
72+ return True
73+
74+ # delete any old academic calendar pdf if exists
75+ if is_file_present (filename ):
7376 delete_file (filename )
7477
75- with open (filename , "wb" ) as file :
76- response = requests .get (url )
77- file .write (response .content )
78+ try :
79+ with open (filename , "wb" ) as file :
80+ response = requests .get (url )
81+ response .raise_for_status ()
82+ file .write (response .content )
83+ except Exception as e :
84+ print (f"Error downloading calendar: { e } " )
85+ return False
7886
79- if ( is_file_present (filename ) ):
87+ if is_file_present (filename ):
8088 return True
8189 return False
8290
@@ -153,8 +161,8 @@ def clean_temp_files():
153161 continue
154162
155163
156- def get_academic_calendar () -> list [DataEntry ]:
157- get_latest_calendar ()
164+ def get_academic_calendar (is_web = False ) -> list [DataEntry ]:
165+ get_latest_calendar (is_web )
158166 export_json ()
159167
160168 all_dates = merge_json ()
0 commit comments