@@ -300,14 +300,74 @@ def generate_recent_updates(repo_dir, output_json_path="static/recent_updates.js
300300
301301 # Sort by cert_date descending
302302
303+ # Sort initially by date to ensure we pick latest from each language
303304 def get_date (x ):
304305 try :
305306 return x .get ('cert_date' , '' )
306307 except :
307308 return ''
308309
309310 new_films .sort (key = get_date , reverse = True )
310- recent_updates = new_films [:limit ]
311+
312+ # Deduplicate same movie across different languages (keep most recent version)
313+ seen_movie_names = {}
314+ deduplicated_films = []
315+
316+ for film in new_films :
317+ movie_name = film .get ('movie_name' , '' ).strip ().lower ()
318+ if not movie_name :
319+ continue
320+
321+ if movie_name not in seen_movie_names :
322+ seen_movie_names [movie_name ] = film
323+ deduplicated_films .append (film )
324+
325+ new_films = deduplicated_films
326+
327+ # Priority Diversity Selection
328+ # User requested to prioritize: English, Hindi, Telugu, Kannada, Malayalam (and Tamil implicitly as major)
329+ PRIORITY_LANGS = {'English' , 'Hindi' , 'Telugu' , 'Kannada' , 'Malayalam' , 'Tamil' }
330+
331+ priority_groups = {lang : [] for lang in PRIORITY_LANGS }
332+ other_films = []
333+
334+ for film in new_films :
335+ # Simple normalization
336+ lang_raw = film .get ('language' , '' ).strip ()
337+ # Handle cases like "Hindi (3D)" or leading/trailing spaces
338+ lang_base = lang_raw .split ('(' )[0 ].strip ()
339+
340+ if lang_base in PRIORITY_LANGS :
341+ priority_groups [lang_base ].append (film )
342+ else :
343+ other_films .append (film )
344+
345+ # Round-Robin Selection from Priority Groups
346+ selected_films = []
347+
348+ # While we have space and priority films available
349+ while len (selected_films ) < limit :
350+ added_in_round = False
351+ for lang in sorted (PRIORITY_LANGS ): # Deterministic order
352+ if priority_groups [lang ]:
353+ selected_films .append (priority_groups [lang ].pop (0 ))
354+ added_in_round = True
355+ if len (selected_films ) >= limit :
356+ break
357+
358+ if not added_in_round :
359+ # Exhausted all priority films
360+ break
361+
362+ # Fill remaining slots with Other films (sorted by date)
363+ if len (selected_films ) < limit :
364+ remaining_slots = limit - len (selected_films )
365+ # others are already sorted by date due to initial sort
366+ selected_films .extend (other_films [:remaining_slots ])
367+
368+ # Re-sort final diverse selection by date
369+ selected_films .sort (key = get_date , reverse = True )
370+ recent_updates = selected_films
311371
312372 os .makedirs (os .path .dirname (output_json_path ), exist_ok = True )
313373 with open (output_json_path , 'w' ) as f :
@@ -432,7 +492,7 @@ def generate_rss_feed(films, output_path="static/rss.xml"):
432492 except Exception as e :
433493 print (f"Error saving RSS feed: { e } " )
434494
435- def fetch_remote_data (output_path = "src/lib/data/data.csv" , limit = 20 ):
495+ def fetch_remote_data (output_path = "src/lib/data/data.csv" , limit = 50 ):
436496 """Fetch latest data from remote source by cloning the repo."""
437497 os .makedirs (os .path .dirname (output_path ), exist_ok = True )
438498
0 commit comments