@@ -127,13 +127,18 @@ async def process(self, posts_data, cutoff_date):
127127
128128 # 2. Upload all images for each post (with carousel support)
129129 all_image_tasks = []
130+
131+ async def _upload_image_bounded (url ):
132+ async with self .semaphore :
133+ return await self ._upload_image (url )
134+
130135 for post in valid_posts :
131136 ig_handle = post .get ("ownerUsername" )
132137 shortcode = post .get ("url" , "" ).strip ("/" ).split ("/" )[- 1 ]
133138 logger .info (f"[{ ig_handle } ] [{ shortcode } ] Uploading images..." )
134139 image_urls = _get_all_images (post )
135140 post ["all_image_urls" ] = image_urls
136- all_image_tasks .append ([self . _upload_image (img_url ) for img_url in image_urls ])
141+ all_image_tasks .append ([_upload_image_bounded (img_url ) for img_url in image_urls ])
137142
138143 flat_tasks = [task for sublist in all_image_tasks for task in sublist ]
139144 flat_results = await asyncio .gather (* flat_tasks , return_exceptions = True )
@@ -216,15 +221,23 @@ async def process(self, posts_data, cutoff_date):
216221
217222 club_type = await self ._get_club_type (ig_handle )
218223 try :
219- success = await self ._save_event (event_data , ig_handle , source_url , club_type )
224+ result = await self ._save_event (event_data , ig_handle , source_url , club_type )
220225 except Exception as e :
221226 append_event_to_csv (event_data , ig_handle , source_url , added_to_db = "error" , club_type = club_type )
222227 logger .error (f"[{ ig_handle } ] [{ shortcode } ] Error saving event: { e } " )
223228 continue
224- if success :
229+
230+ if result is True :
225231 append_event_to_csv (event_data , ig_handle , source_url , added_to_db = "success" , club_type = club_type )
226232 logger .info (f"[{ ig_handle } ] [{ shortcode } ] Saved event: '{ event_data .get ('title' , '' )} '" )
227233 saved_count += 1
234+ elif result == "updated" :
235+ append_event_to_csv (event_data , ig_handle , source_url , added_to_db = "updated" , club_type = club_type )
236+ logger .info (f"[{ ig_handle } ] [{ shortcode } ] Updated event: '{ event_data .get ('title' , '' )} '" )
237+ saved_count += 1
238+ elif result == "duplicate" :
239+ append_event_to_csv (event_data , ig_handle , source_url , added_to_db = "duplicate_post" , club_type = club_type )
240+ logger .info (f"[{ ig_handle } ] [{ shortcode } ] Duplicate event (no changes): '{ event_data .get ('title' , '' )} '" )
228241
229242 logger .info (f"Processing complete. Saved { saved_count } new events." )
230243 return saved_count
0 commit comments