Tomorrow event notification button

main
Bob Mottram 2021-05-31 12:57:36 +01:00
parent eeb2f98329
commit 45029d45d0
18 changed files with 57 additions and 89 deletions

View File

@ -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

View File

@ -213,6 +213,7 @@
"Sensitive": "حساس",
"Word Replacements": "استبدال الكلمات",
"Happening Today": "اليوم",
"Happening Tomorrow": "غدا",
"Happening This Week": "هكذا",
"Blog": "مدونة",
"Blogs": "المدونات",

View File

@ -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",

View File

@ -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",

View File

@ -213,6 +213,7 @@
"Sensitive": "Empfindlich",
"Word Replacements": "Wortersetzungen",
"Happening Today": "Heute",
"Happening Tomorrow": "Morgen",
"Happening This Week": "Demnächst",
"Blog": "Blog",
"Blogs": "Blogs",

View File

@ -213,6 +213,7 @@
"Sensitive": "Sensitive",
"Word Replacements": "Word Replacements",
"Happening Today": "Today",
"Happening Tomorrow": "Tomorrow",
"Happening This Week": "Soon",
"Blog": "Blog",
"Blogs": "Blogs",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -213,6 +213,7 @@
"Sensitive": "संवेदनशील",
"Word Replacements": "शब्द प्रतिस्थापन",
"Happening Today": "आज",
"Happening Tomorrow": "आने वाला कल",
"Happening This Week": "जल्द ही",
"Blog": "ब्लॉग",
"Blogs": "ब्लॉग",

View File

@ -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",

View File

@ -213,6 +213,7 @@
"Sensitive": "敏感",
"Word Replacements": "単語の置換",
"Happening Today": "今日",
"Happening Tomorrow": "明日",
"Happening This Week": "すぐに",
"Blog": "ブログ",
"Blogs": "ブログ",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -213,6 +213,7 @@
"Sensitive": "чувствительный",
"Word Replacements": "Замены слов",
"Happening Today": "Cегодня",
"Happening Tomorrow": "Завтра",
"Happening This Week": "Скоро",
"Blog": "Блог",
"Blogs": "Блоги",

View File

@ -213,6 +213,7 @@
"Sensitive": "敏感",
"Word Replacements": "单词替换",
"Happening Today": "今天",
"Happening Tomorrow": "明天",
"Happening This Week": "不久",
"Blog": "博客",
"Blogs": "网志",

View File

@ -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,
'<button class="button">' + \
translate['Happening Today'] + '</button></a>'
# happening this week button
if thisWeeksEventsCheck(baseDir, nickname, domain):
if not iconsAsButtons:
happeningStr += \
'<a href="' + usersPath + \
'/calendar" tabindex="-1">' + \
'<button class="buttonevent">' + \
translate['Happening This Week'] + '</button></a>'
else:
happeningStr += \
'<a href="' + usersPath + \
'/calendar" tabindex="-1">' + \
'<button class="button">' + \
translate['Happening This Week'] + '</button></a>'
else:
# happening this week button
if thisWeeksEventsCheck(baseDir, nickname, domain):
if not iconsAsButtons:
happeningStr += \
'<a href="' + usersPath + \
'/calendar" tabindex="-1">' + \
'<button class="buttonevent">' + \
translate['Happening This Week'] + '</button></a>'
else:
happeningStr += \
'<a href="' + usersPath + \
'/calendar" tabindex="-1">' + \
'<button class="button">' + \
translate['Happening This Week'] + '</button></a>'
elif dayEventsCheck(baseDir, nickname, domain, tomorrow):
# happening tomorrow button
if not iconsAsButtons:
happeningStr += \
'<a href="' + usersPath + '/calendar?year=' + \
str(tomorrow.year) + '?month=' + str(tomorrow.month) + \
'?day=' + str(tomorrow.day) + '" tabindex="-1">' + \
'<button class="buttonevent">' + \
translate['Happening Tomorrow'] + '</button></a>'
else:
happeningStr += \
'<a href="' + usersPath + '/calendar?year=' + \
str(tomorrow.year) + '?month=' + str(tomorrow.month) + \
'?day=' + str(tomorrow.day) + '" tabindex="-1">' + \
'<button class="button">' + \
translate['Happening Tomorrow'] + '</button></a>'
elif dayEventsCheck(baseDir, nickname, domain, twodays):
if not iconsAsButtons:
happeningStr += \
'<a href="' + usersPath + \
'/calendar" tabindex="-1">' + \
'<button class="buttonevent">' + \
translate['Happening This Week'] + '</button></a>'
else:
happeningStr += \
'<a href="' + usersPath + \
'/calendar" tabindex="-1">' + \
'<button class="button">' + \
translate['Happening This Week'] + '</button></a>'
if not featuresHeader:
# button for the outbox