@@ -182,13 +182,26 @@ def get_most_popular_video_ids(channel_url, n=9):
182
182
def get_donation_count_fm ():
183
183
URL = "https://www.idonate.ie/fundraiser/MediaProductionSociety12"
184
184
headers = {'User-Agent' : "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0" }
185
- r = requests .get (url = URL , headers = headers )
186
- soup = BeautifulSoup (r .content , 'html5lib' )
187
- current_donation = soup .find ('div' , attrs = {'class' :'ifs-right-fundraisers-head' })
188
- donation_target = soup .find ('div' , attrs = {'class' :'support-cause' })
189
- current_donation_amount = int (str (current_donation ).split ()[3 ].split ("€" )[1 ].split ("<" )[0 ].replace ("," ,"" ))
190
- goal_amount = int (str (donation_target ).split ("€" )[1 ].split ("<" )[0 ].replace ("," ,"" ))
191
- return current_donation_amount , goal_amount
185
+
186
+ try :
187
+ r = requests .get (url = URL , headers = headers , timeout = 10 )
188
+ r .raise_for_status ()
189
+
190
+ soup = BeautifulSoup (r .content , 'html5lib' )
191
+
192
+ current_donation = soup .find ('div' , attrs = {'class' : 'ifs-right-fundraisers-head' })
193
+ donation_target = soup .find ('div' , attrs = {'class' : 'support-cause' })
194
+
195
+ if current_donation is None or donation_target is None :
196
+ raise ValueError ("Necessary data not found on the page." )
197
+
198
+ current_donation_amount = int (str (current_donation ).split ()[3 ].split ("€" )[1 ].split ("<" )[0 ].replace ("," , "" ))
199
+ goal_amount = int (str (donation_target ).split ("€" )[1 ].split ("<" )[0 ].replace ("," , "" ))
200
+
201
+ return current_donation_amount , goal_amount
202
+
203
+ except (requests .RequestException , ValueError , IndexError , AttributeError ) as e :
204
+ return 0 , 0
192
205
193
206
def get_event_data ():
194
207
data = {}
0 commit comments