From 53c13f923c1f4fe900abb5b7f021393d642dd95c Mon Sep 17 00:00:00 2001 From: lungsangg Date: Fri, 9 Feb 2024 14:22:12 +0530 Subject: [PATCH 1/3] get_method_added_to_daydata --- sefaria/helper/community_page.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sefaria/helper/community_page.py b/sefaria/helper/community_page.py index d7d600dcfc..8b002ad5b6 100644 --- a/sefaria/helper/community_page.py +++ b/sefaria/helper/community_page.py @@ -153,7 +153,7 @@ def get_featured_item(data, date): def get_todays_data(data, date): todays_data = None for day_data in data: - if day_data["Date"] == date: + if day_data.get("Date") == date: todays_data = day_data break return todays_data From b136e0a5715b941bde9f3d96d427e52df0962639 Mon Sep 17 00:00:00 2001 From: lungsangg Date: Fri, 9 Feb 2024 14:38:52 +0530 Subject: [PATCH 2/3] get_method_removed --- sefaria/helper/community_page.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sefaria/helper/community_page.py b/sefaria/helper/community_page.py index 8b002ad5b6..d7d600dcfc 100644 --- a/sefaria/helper/community_page.py +++ b/sefaria/helper/community_page.py @@ -153,7 +153,7 @@ def get_featured_item(data, date): def get_todays_data(data, date): todays_data = None for day_data in data: - if day_data.get("Date") == date: + if day_data["Date"] == date: todays_data = day_data break return todays_data From 256a3102350289b8e760507bfa6b789385b18ae0 Mon Sep 17 00:00:00 2001 From: lungsangg Date: Fri, 9 Feb 2024 15:17:52 +0530 Subject: [PATCH 3/3] stop_iteration_issue_solved_without_data --- sefaria/helper/community_page.py | 63 +++++++++++++++++--------------- sefaria/utils/calendars.py | 12 ++++-- 2 files changed, 42 insertions(+), 33 deletions(-) diff --git a/sefaria/helper/community_page.py b/sefaria/helper/community_page.py index d7d600dcfc..5c153985aa 100644 --- a/sefaria/helper/community_page.py +++ b/sefaria/helper/community_page.py @@ -101,38 +101,41 @@ def get_community_page_items(date=None, language="english", diaspora=True, refre def get_parashah_item(data, date=None, diaspora=True, interface_lang="english"): - todays_data = get_todays_data(data, date) # First we want the row in the sheet representing today. Always. - weekend_reading = get_parasha(datetime.strptime(date, "%m/%d/%y"), diaspora=diaspora) # What is this week's torah reading on Saturday. Can be a special reading for Holiday. - parashah_name = weekend_reading["parasha"] - parashah_topic = get_topic_by_parasha(parashah_name) + todays_data = get_todays_data(data, date) # First we want the row in the sheet representing today. Always. + weekend_reading = get_parasha(datetime.strptime(date, "%m/%d/%y"), diaspora=diaspora) # What is this week's torah reading on Saturday. Can be a special reading for Holiday. - if not todays_data or not (todays_data["Sheet URL"]): - sheet = None - else: - sheet = sheet_with_customization(todays_data) - if sheet: - if parashah_topic and todays_data["Parashah"] in [parashah_topic.parasha] + parashah_topic.get_titles(): # We have a matched official parasha to the day's entry in the sheet - parashah_name = parashah_topic.parasha - sheet["heading"] = { - "en": "This Week's Torah Portion: " + parashah_name, - "he": "פרשת השבוע: " + hebrew_parasha_name(parashah_name) - } - else: - # We have a sheet row where the title doesn't match a known parasha. It might be a mid week holiday reading (doesnt appear in our parshiot db). - # Since this sheet column can now essentially be a custom block title, we dont know how to translate automatically, so - # this will also mostly rely on the fact that the Hebrew only shows up in Hebrew interface and Heb comms team can enter custom Hebrew to begin with. - sheet["heading"] = { - "en": "Torah Reading For: " + todays_data["Parashah"], - "he": "קריאת התורה ל:" + todays_data["Parashah"] - } - - if not parashah_topic and not sheet: - return None + if weekend_reading is not None: + parashah_name = weekend_reading["parasha"] + parashah_topic = get_topic_by_parasha(parashah_name) + else: + # Handle the case where weekend_reading is None + # For example, return None or set default values for parashah_name and parashah_topic + return None # Or other appropriate handling - return { - "topic": parashah_topic.contents() if parashah_topic else None, - "sheet": sheet - } + if not todays_data or not (todays_data["Sheet URL"]): + sheet = None + else: + sheet = sheet_with_customization(todays_data) + if sheet: + if parashah_topic and todays_data["Parashah"] in [parashah_topic.parasha] + parashah_topic.get_titles(): + parashah_name = parashah_topic.parasha + sheet["heading"] = { + "en": "This Week's Torah Portion: " + parashah_name, + "he": "פרשת השבוע: " + hebrew_parasha_name(parashah_name) + } + else: + sheet["heading"] = { + "en": "Torah Reading For: " + todays_data["Parashah"], + "he": "קריאת התורה ל:" + todays_data["Parashah"] + } + + if not parashah_topic and not sheet: + return None + + return { + "topic": parashah_topic.contents() if parashah_topic else None, + "sheet": sheet + } def get_featured_item(data, date): diff --git a/sefaria/utils/calendars.py b/sefaria/utils/calendars.py index 8f416a3683..289640435a 100644 --- a/sefaria/utils/calendars.py +++ b/sefaria/utils/calendars.py @@ -322,8 +322,14 @@ def get_parasha(datetime_obj, diaspora=True, parasha=None): if parasha is not None: # regex search for potential double parasha. there can be dash before or after name query["parasha"] = re.compile('(?:(?<=^)|(?<=-)){}(?=-|$)'.format(parasha)) - p = db.parshiot.find(query, limit=1).sort([("date", 1)]) - p = next(p) + + p = db.parshiot.find(query).sort([("date", 1)]).limit(1) + + try: + p = next(p) + except StopIteration: + p = None # or handle the empty case appropriately + return p @@ -469,4 +475,4 @@ def verify_parashah_topics_exist(): print("Missing parashah topic for: {}".format(parashah)) if not missing: - print("All parashahs in the parshiot collection have corresponding topics.") + print("All parashahs in the parshiot collection have corresponding topics.") \ No newline at end of file