I've been trying to extract news using CODEBK, but it many cases it fails to retrieve all the requested data. Can you do this using excel add-on to ensure the full retrieval of requested data?
It could look like this:
import time … for storyId in storyIds: get_news_content(storyId ) time.sleep(1) # Pauses execution for 1 seconds
Or,
import time story_cache = {} def get_news_content(story_id): if pd.isna(story_id): return None if story_id not in story_cache: try: time.sleep(1) # Pauses execution for 1 seconds story_cache[story_id] = ld.news.get_story( story_id=story_id, format=ld.news.Format.TEXT ) except Exception as e: print(f"Error retrieving story {story_id}: {e}") story_cache[story_id] = None return story_cache[story_id] news_comi["News_Content"] = news_comi["storyId"].apply(get_news_content)
@Mohamed_Magdy2026
Thank you for reaching out to us.
The webnews doesn't return a story. It returns the webURL, as mentioned in this discussion.
Based on the error (Error Code 500), the issue is likely occurring in the backend service rather than in the library or your code. You may want to introduce a delay (e.g., using sleep) between each request and implement retry logic to handle transient failures. Additionally, consider running the process in your local JupyterLab environment to verify whether the issue persists.
Which Excel add-on are you referring to?
Hello @Mohamed_Magdy2026
I can get story of the following story_ids
You may add a delay between each news request and implement the retry logic as my colleague suggested.
I asked for the Workspace Excel add-in as an option to solve the issue, in case data retrieval through CODEBK continues to be problematic.
However, since you mentioned that introducing a delay could resolve the issue, could you please provide the code needed to implement this solution?
The code with the retry logic should look like this:
import time story_cache = {} def get_news_content(story_id): if pd.isna(story_id): return None if story_id not in story_cache: max_retries = 3 for attempt in range(max_retries): try: story_cache[story_id] = ld.news.get_story( story_id=story_id, format=ld.news.Format.TEXT ) time.sleep(1) # pause after successful call break # success, exit loop except Exception as e: print(f"Attempt {attempt + 1} failed for {story_id}: {e}") time.sleep(1) # pause after failed call as well if attempt == max_retries - 1: print(f"Error retrieving story {story_id} after {max_retries} attempts") story_cache[story_id] = None return story_cache[story_id] news_comi["News_Content"] = news_comi["storyId"].apply(get_news_content)