From 45029d45d0383e8c5cb57b6e215ed119927023e6 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 31 May 2021 12:57:36 +0100 Subject: [PATCH] Tomorrow event notification button --- happening.py | 59 +++-------------------------------- translations/ar.json | 1 + translations/ca.json | 1 + translations/cy.json | 1 + translations/de.json | 1 + translations/en.json | 1 + translations/es.json | 1 + translations/fr.json | 1 + translations/ga.json | 1 + translations/hi.json | 1 + translations/it.json | 1 + translations/ja.json | 1 + translations/ku.json | 1 + translations/oc.json | 3 +- translations/pt.json | 1 + translations/ru.json | 1 + translations/zh.json | 1 + webapp_headerbuttons.py | 69 +++++++++++++++++++++-------------------- 18 files changed, 57 insertions(+), 89 deletions(-) diff --git a/happening.py b/happening.py index f582b7abd..90bd96af7 100644 --- a/happening.py +++ b/happening.py @@ -259,13 +259,12 @@ def getTodaysEvents(baseDir: str, nickname: str, domain: str, return events -def todaysEventsCheck(baseDir: str, nickname: str, domain: str) -> bool: - """Are there calendar events today? +def dayEventsCheck(baseDir: str, nickname: str, domain: str, currDate) -> bool: + """Are there calendar events for the given date? """ - now = datetime.now() - year = now.year - monthNumber = now.month - dayNumber = now.day + year = currDate.year + monthNumber = currDate.month + dayNumber = currDate.day calendarFilename = \ baseDir + '/accounts/' + nickname + '@' + domain + \ @@ -309,54 +308,6 @@ def todaysEventsCheck(baseDir: str, nickname: str, domain: str) -> bool: return eventsExist -def thisWeeksEventsCheck(baseDir: str, nickname: str, domain: str) -> bool: - """Are there calendar events this week? - """ - now = datetime.now() - year = now.year - monthNumber = now.month - dayNumber = now.day - - calendarFilename = \ - baseDir + '/accounts/' + nickname + '@' + domain + \ - '/calendar/' + str(year) + '/' + str(monthNumber) + '.txt' - if not os.path.isfile(calendarFilename): - return False - - eventsExist = False - with open(calendarFilename, 'r') as eventsFile: - for postId in eventsFile: - postId = postId.replace('\n', '').replace('\r', '') - postFilename = locatePost(baseDir, nickname, domain, postId) - if not postFilename: - continue - - postJsonObject = loadJson(postFilename) - if not _isHappeningPost(postJsonObject): - continue - - for tag in postJsonObject['object']['tag']: - if not _isHappeningEvent(tag): - continue - # this tag is an event or a place - if tag['type'] != 'Event': - continue - # tag is an event - if not tag.get('startTime'): - continue - eventTime = \ - datetime.strptime(tag['startTime'], - "%Y-%m-%dT%H:%M:%S%z") - if (int(eventTime.strftime("%Y")) == year and - int(eventTime.strftime("%m")) == monthNumber and - (int(eventTime.strftime("%d")) > dayNumber and - int(eventTime.strftime("%d")) <= dayNumber + 6)): - eventsExist = True - break - - return eventsExist - - def getThisWeeksEvents(baseDir: str, nickname: str, domain: str) -> {}: """Retrieves calendar events for this week Returns a dictionary indexed by day number of lists containing diff --git a/translations/ar.json b/translations/ar.json index 0d4c968d2..9cae33396 100644 --- a/translations/ar.json +++ b/translations/ar.json @@ -213,6 +213,7 @@ "Sensitive": "حساس", "Word Replacements": "استبدال الكلمات", "Happening Today": "اليوم", + "Happening Tomorrow": "غدا", "Happening This Week": "هكذا", "Blog": "مدونة", "Blogs": "المدونات", diff --git a/translations/ca.json b/translations/ca.json index 481bc633e..9b7ec31d3 100644 --- a/translations/ca.json +++ b/translations/ca.json @@ -213,6 +213,7 @@ "Sensitive": "Sensible", "Word Replacements": "Substitucions de paraula", "Happening Today": "Avui", + "Happening Tomorrow": "Demà", "Happening This Week": "Aviat", "Blog": "Bloc", "Blogs": "Blocs", diff --git a/translations/cy.json b/translations/cy.json index c5543a1ac..dd289760d 100644 --- a/translations/cy.json +++ b/translations/cy.json @@ -213,6 +213,7 @@ "Sensitive": "Sensitif", "Word Replacements": "Amnewidiadau Geiriau", "Happening Today": "Heddiw", + "Happening Tomorrow": "Yfory", "Happening This Week": "Yn fuan", "Blog": "Blog", "Blogs": "Blogs", diff --git a/translations/de.json b/translations/de.json index e18f86cf0..fd4ad86bb 100644 --- a/translations/de.json +++ b/translations/de.json @@ -213,6 +213,7 @@ "Sensitive": "Empfindlich", "Word Replacements": "Wortersetzungen", "Happening Today": "Heute", + "Happening Tomorrow": "Morgen", "Happening This Week": "Demnächst", "Blog": "Blog", "Blogs": "Blogs", diff --git a/translations/en.json b/translations/en.json index 6e7ac30d8..a076ae7b5 100644 --- a/translations/en.json +++ b/translations/en.json @@ -213,6 +213,7 @@ "Sensitive": "Sensitive", "Word Replacements": "Word Replacements", "Happening Today": "Today", + "Happening Tomorrow": "Tomorrow", "Happening This Week": "Soon", "Blog": "Blog", "Blogs": "Blogs", diff --git a/translations/es.json b/translations/es.json index 7311d5e78..fa727def8 100644 --- a/translations/es.json +++ b/translations/es.json @@ -213,6 +213,7 @@ "Sensitive": "Sensible", "Word Replacements": "Reemplazos de palabras", "Happening Today": "Hoy", + "Happening Tomorrow": "Mañana", "Happening This Week": "Pronto", "Blog": "Blog", "Blogs": "Blogs", diff --git a/translations/fr.json b/translations/fr.json index 605cb43ce..898a108db 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -213,6 +213,7 @@ "Sensitive": "Sensible", "Word Replacements": "Remplacements de mots", "Happening Today": "Aujourd'hui", + "Happening Tomorrow": "Demain", "Happening This Week": "Bientôt", "Blog": "Blog", "Blogs": "Blogs", diff --git a/translations/ga.json b/translations/ga.json index 9df731cb5..4b5cabc0b 100644 --- a/translations/ga.json +++ b/translations/ga.json @@ -213,6 +213,7 @@ "Sensitive": "Íogair", "Word Replacements": "Athchur Focal", "Happening Today": "Inniu", + "Happening Tomorrow": "Amárach", "Happening This Week": "Go gairid", "Blog": "Blag", "Blogs": "Blaganna", diff --git a/translations/hi.json b/translations/hi.json index 824a2c346..b02de9fec 100644 --- a/translations/hi.json +++ b/translations/hi.json @@ -213,6 +213,7 @@ "Sensitive": "संवेदनशील", "Word Replacements": "शब्द प्रतिस्थापन", "Happening Today": "आज", + "Happening Tomorrow": "आने वाला कल", "Happening This Week": "जल्द ही", "Blog": "ब्लॉग", "Blogs": "ब्लॉग", diff --git a/translations/it.json b/translations/it.json index 45e304652..00271b324 100644 --- a/translations/it.json +++ b/translations/it.json @@ -213,6 +213,7 @@ "Sensitive": "Sensibile", "Word Replacements": "Sostituzioni di parole", "Happening Today": "Oggi", + "Happening Tomorrow": "Domani", "Happening This Week": "Presto", "Blog": "Blog", "Blogs": "Blog", diff --git a/translations/ja.json b/translations/ja.json index aba165a20..211b11d31 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -213,6 +213,7 @@ "Sensitive": "敏感", "Word Replacements": "単語の置換", "Happening Today": "今日", + "Happening Tomorrow": "明日", "Happening This Week": "すぐに", "Blog": "ブログ", "Blogs": "ブログ", diff --git a/translations/ku.json b/translations/ku.json index a5e686051..fe44eabcc 100644 --- a/translations/ku.json +++ b/translations/ku.json @@ -213,6 +213,7 @@ "Sensitive": "Pêketî", "Word Replacements": "Veguheztinên Peyvan", "Happening Today": "Îro", + "Happening Tomorrow": "Sibê", "Happening This Week": "Nêzda", "Blog": "Blog", "Blogs": "Blogs", diff --git a/translations/oc.json b/translations/oc.json index a0ab81de1..771d1d201 100644 --- a/translations/oc.json +++ b/translations/oc.json @@ -208,7 +208,8 @@ "Remove Twitter posts": "Remove Twitter posts", "Sensitive": "Sensitive", "Word Replacements": "Word Replacements", - "Happening Today": "Happening Today", + "Happening Today": "Today", + "Happening Tomorrow": "Tomorrow", "Happening This Week": "Soon", "Blog": "Blog", "Blogs": "Blogs", diff --git a/translations/pt.json b/translations/pt.json index 3ce0bc69a..3014a750d 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -213,6 +213,7 @@ "Sensitive": "Sensível", "Word Replacements": "Substituições do Word", "Happening Today": "Hoje", + "Happening Tomorrow": "Amanhã", "Happening This Week": "Em breve", "Blog": "Blog", "Blogs": "Blogs", diff --git a/translations/ru.json b/translations/ru.json index 70ce88f87..08d7e65ed 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -213,6 +213,7 @@ "Sensitive": "чувствительный", "Word Replacements": "Замены слов", "Happening Today": "Cегодня", + "Happening Tomorrow": "Завтра", "Happening This Week": "Скоро", "Blog": "Блог", "Blogs": "Блоги", diff --git a/translations/zh.json b/translations/zh.json index ba268fc9a..4098fe972 100644 --- a/translations/zh.json +++ b/translations/zh.json @@ -213,6 +213,7 @@ "Sensitive": "敏感", "Word Replacements": "单词替换", "Happening Today": "今天", + "Happening Tomorrow": "明天", "Happening This Week": "不久", "Blog": "博客", "Blogs": "网志", diff --git a/webapp_headerbuttons.py b/webapp_headerbuttons.py index 49ab245cd..139691607 100644 --- a/webapp_headerbuttons.py +++ b/webapp_headerbuttons.py @@ -10,8 +10,8 @@ __status__ = "Production" import os import time from datetime import datetime -from happening import todaysEventsCheck -from happening import thisWeeksEventsCheck +from datetime import timedelta +from happening import dayEventsCheck from webapp_utils import htmlHighlightLabel @@ -152,9 +152,10 @@ def headerButtonsTimeline(defaultTimeline: str, # show todays events buttons on the first inbox page happeningStr = '' if boxName == 'inbox' and pageNumber == 1: - if todaysEventsCheck(baseDir, nickname, domain): - now = datetime.now() - + now = datetime.now() + tomorrow = datetime.now() + timedelta(1) + twodays = datetime.now() + timedelta(2) + if dayEventsCheck(baseDir, nickname, domain, now): # happening today button if not iconsAsButtons: happeningStr += \ @@ -171,35 +172,35 @@ def headerButtonsTimeline(defaultTimeline: str, '' - # happening this week button - if thisWeeksEventsCheck(baseDir, nickname, domain): - if not iconsAsButtons: - happeningStr += \ - '' + \ - '' - else: - happeningStr += \ - '' + \ - '' - else: - # happening this week button - if thisWeeksEventsCheck(baseDir, nickname, domain): - if not iconsAsButtons: - happeningStr += \ - '' + \ - '' - else: - happeningStr += \ - '' + \ - '' + elif dayEventsCheck(baseDir, nickname, domain, tomorrow): + # happening tomorrow button + if not iconsAsButtons: + happeningStr += \ + '' + \ + '' + else: + happeningStr += \ + '' + \ + '' + elif dayEventsCheck(baseDir, nickname, domain, twodays): + if not iconsAsButtons: + happeningStr += \ + '' + \ + '' + else: + happeningStr += \ + '' + \ + '' if not featuresHeader: # button for the outbox