Merge branch 'main' of ssh://code.freedombone.net:2222/bashrc/epicyon

main
Bob Mottram 2021-05-31 15:14:47 +01:00
commit 912c35cbda
18 changed files with 68 additions and 120 deletions

View File

@ -9,13 +9,12 @@ __status__ = "Production"
import os import os
from uuid import UUID from uuid import UUID
from datetime import datetime from datetime import datetime
from datetime import timedelta
from utils import isPublicPost from utils import isPublicPost
from utils import loadJson from utils import loadJson
from utils import saveJson from utils import saveJson
from utils import locatePost from utils import locatePost
from utils import daysInMonth
from utils import mergeDicts
def _validUuid(testUuid: str, version=4): def _validUuid(testUuid: str, version=4):
@ -259,13 +258,12 @@ def getTodaysEvents(baseDir: str, nickname: str, domain: str,
return events return events
def todaysEventsCheck(baseDir: str, nickname: str, domain: str) -> bool: def dayEventsCheck(baseDir: str, nickname: str, domain: str, currDate) -> bool:
"""Are there calendar events today? """Are there calendar events for the given date?
""" """
now = datetime.now() year = currDate.year
year = now.year monthNumber = currDate.month
monthNumber = now.month dayNumber = currDate.day
dayNumber = now.day
calendarFilename = \ calendarFilename = \
baseDir + '/accounts/' + nickname + '@' + domain + \ baseDir + '/accounts/' + nickname + '@' + domain + \
@ -297,57 +295,12 @@ def todaysEventsCheck(baseDir: str, nickname: str, domain: str) -> bool:
eventTime = \ eventTime = \
datetime.strptime(tag['startTime'], datetime.strptime(tag['startTime'],
"%Y-%m-%dT%H:%M:%S%z") "%Y-%m-%dT%H:%M:%S%z")
if int(eventTime.strftime("%Y")) == year and \ if int(eventTime.strftime("%d")) != dayNumber:
int(eventTime.strftime("%m")) == monthNumber and \
int(eventTime.strftime("%d")) == dayNumber:
eventsExist = True
break
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 continue
if int(eventTime.strftime("%m")) != monthNumber:
postJsonObject = loadJson(postFilename)
if not _isHappeningPost(postJsonObject):
continue continue
if int(eventTime.strftime("%Y")) != year:
for tag in postJsonObject['object']['tag']:
if not _isHappeningEvent(tag):
continue 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 eventsExist = True
break break
@ -361,9 +314,9 @@ def getThisWeeksEvents(baseDir: str, nickname: str, domain: str) -> {}:
Note: currently not used but could be with a weekly calendar screen Note: currently not used but could be with a weekly calendar screen
""" """
now = datetime.now() now = datetime.now()
endOfWeek = now + timedelta(7)
year = now.year year = now.year
monthNumber = now.month monthNumber = now.month
dayNumber = now.day
calendarFilename = \ calendarFilename = \
baseDir + '/accounts/' + nickname + '@' + domain + \ baseDir + '/accounts/' + nickname + '@' + domain + \
@ -388,7 +341,6 @@ def getThisWeeksEvents(baseDir: str, nickname: str, domain: str) -> {}:
continue continue
postEvent = [] postEvent = []
dayOfMonth = None
weekDayIndex = None weekDayIndex = None
for tag in postJsonObject['object']['tag']: for tag in postJsonObject['object']['tag']:
if not _isHappeningEvent(tag): if not _isHappeningEvent(tag):
@ -401,21 +353,17 @@ def getThisWeeksEvents(baseDir: str, nickname: str, domain: str) -> {}:
eventTime = \ eventTime = \
datetime.strptime(tag['startTime'], datetime.strptime(tag['startTime'],
"%Y-%m-%dT%H:%M:%S%z") "%Y-%m-%dT%H:%M:%S%z")
if (int(eventTime.strftime("%Y")) == year and if eventTime >= now and eventTime <= endOfWeek:
int(eventTime.strftime("%m")) == monthNumber and weekDayIndex = (eventTime - now).days()
(int(eventTime.strftime("%d")) >= dayNumber and
int(eventTime.strftime("%d")) <= dayNumber + 6)):
dayOfMonth = str(int(eventTime.strftime("%d")))
weekDayIndex = dayOfMonth - dayNumber
postEvent.append(tag) postEvent.append(tag)
else: else:
# tag is a place # tag is a place
postEvent.append(tag) postEvent.append(tag)
if postEvent and weekDayIndex: if postEvent and weekDayIndex:
calendarPostIds.append(postId) calendarPostIds.append(postId)
if not events.get(dayOfMonth): if not events.get(weekDayIndex):
events[weekDayIndex] = [] events[weekDayIndex] = []
events[dayOfMonth].append(postEvent) events[weekDayIndex].append(postEvent)
# if some posts have been deleted then regenerate the calendar file # if some posts have been deleted then regenerate the calendar file
if recreateEventsFile: if recreateEventsFile:
@ -424,23 +372,6 @@ def getThisWeeksEvents(baseDir: str, nickname: str, domain: str) -> {}:
calendarFile.write(postId + '\n') calendarFile.write(postId + '\n')
calendarFile.close() calendarFile.close()
lastDayOfMonth = daysInMonth(year, monthNumber)
if dayNumber+6 > lastDayOfMonth:
monthNumber += 1
if monthNumber > 12:
monthNumber = 1
year += 1
for d in range(1, dayNumber + 6 - lastDayOfMonth):
dailyEvents = \
getTodaysEvents(baseDir, nickname, domain,
year, monthNumber, d)
if dailyEvents:
if dailyEvents.get(d):
newEvents = {}
newEvents[d + (7 - (dayNumber + 6 - lastDayOfMonth))] = \
dailyEvents[d]
events = mergeDicts(events, newEvents)
return events return events

View File

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

View File

@ -213,6 +213,7 @@
"Sensitive": "Sensible", "Sensitive": "Sensible",
"Word Replacements": "Substitucions de paraula", "Word Replacements": "Substitucions de paraula",
"Happening Today": "Avui", "Happening Today": "Avui",
"Happening Tomorrow": "Demà",
"Happening This Week": "Aviat", "Happening This Week": "Aviat",
"Blog": "Bloc", "Blog": "Bloc",
"Blogs": "Blocs", "Blogs": "Blocs",

View File

@ -213,6 +213,7 @@
"Sensitive": "Sensitif", "Sensitive": "Sensitif",
"Word Replacements": "Amnewidiadau Geiriau", "Word Replacements": "Amnewidiadau Geiriau",
"Happening Today": "Heddiw", "Happening Today": "Heddiw",
"Happening Tomorrow": "Yfory",
"Happening This Week": "Yn fuan", "Happening This Week": "Yn fuan",
"Blog": "Blog", "Blog": "Blog",
"Blogs": "Blogs", "Blogs": "Blogs",

View File

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

View File

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

View File

@ -213,6 +213,7 @@
"Sensitive": "Sensible", "Sensitive": "Sensible",
"Word Replacements": "Reemplazos de palabras", "Word Replacements": "Reemplazos de palabras",
"Happening Today": "Hoy", "Happening Today": "Hoy",
"Happening Tomorrow": "Mañana",
"Happening This Week": "Pronto", "Happening This Week": "Pronto",
"Blog": "Blog", "Blog": "Blog",
"Blogs": "Blogs", "Blogs": "Blogs",

View File

@ -213,6 +213,7 @@
"Sensitive": "Sensible", "Sensitive": "Sensible",
"Word Replacements": "Remplacements de mots", "Word Replacements": "Remplacements de mots",
"Happening Today": "Aujourd'hui", "Happening Today": "Aujourd'hui",
"Happening Tomorrow": "Demain",
"Happening This Week": "Bientôt", "Happening This Week": "Bientôt",
"Blog": "Blog", "Blog": "Blog",
"Blogs": "Blogs", "Blogs": "Blogs",

View File

@ -213,6 +213,7 @@
"Sensitive": "Íogair", "Sensitive": "Íogair",
"Word Replacements": "Athchur Focal", "Word Replacements": "Athchur Focal",
"Happening Today": "Inniu", "Happening Today": "Inniu",
"Happening Tomorrow": "Amárach",
"Happening This Week": "Go gairid", "Happening This Week": "Go gairid",
"Blog": "Blag", "Blog": "Blag",
"Blogs": "Blaganna", "Blogs": "Blaganna",

View File

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

View File

@ -213,6 +213,7 @@
"Sensitive": "Sensibile", "Sensitive": "Sensibile",
"Word Replacements": "Sostituzioni di parole", "Word Replacements": "Sostituzioni di parole",
"Happening Today": "Oggi", "Happening Today": "Oggi",
"Happening Tomorrow": "Domani",
"Happening This Week": "Presto", "Happening This Week": "Presto",
"Blog": "Blog", "Blog": "Blog",
"Blogs": "Blog", "Blogs": "Blog",

View File

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

View File

@ -213,6 +213,7 @@
"Sensitive": "Pêketî", "Sensitive": "Pêketî",
"Word Replacements": "Veguheztinên Peyvan", "Word Replacements": "Veguheztinên Peyvan",
"Happening Today": "Îro", "Happening Today": "Îro",
"Happening Tomorrow": "Sibê",
"Happening This Week": "Nêzda", "Happening This Week": "Nêzda",
"Blog": "Blog", "Blog": "Blog",
"Blogs": "Blogs", "Blogs": "Blogs",

View File

@ -208,7 +208,8 @@
"Remove Twitter posts": "Remove Twitter posts", "Remove Twitter posts": "Remove Twitter posts",
"Sensitive": "Sensitive", "Sensitive": "Sensitive",
"Word Replacements": "Word Replacements", "Word Replacements": "Word Replacements",
"Happening Today": "Happening Today", "Happening Today": "Today",
"Happening Tomorrow": "Tomorrow",
"Happening This Week": "Soon", "Happening This Week": "Soon",
"Blog": "Blog", "Blog": "Blog",
"Blogs": "Blogs", "Blogs": "Blogs",

View File

@ -213,6 +213,7 @@
"Sensitive": "Sensível", "Sensitive": "Sensível",
"Word Replacements": "Substituições do Word", "Word Replacements": "Substituições do Word",
"Happening Today": "Hoje", "Happening Today": "Hoje",
"Happening Tomorrow": "Amanhã",
"Happening This Week": "Em breve", "Happening This Week": "Em breve",
"Blog": "Blog", "Blog": "Blog",
"Blogs": "Blogs", "Blogs": "Blogs",

View File

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

View File

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

View File

@ -10,8 +10,8 @@ __status__ = "Production"
import os import os
import time import time
from datetime import datetime from datetime import datetime
from happening import todaysEventsCheck from datetime import timedelta
from happening import thisWeeksEventsCheck from happening import dayEventsCheck
from webapp_utils import htmlHighlightLabel from webapp_utils import htmlHighlightLabel
@ -152,9 +152,10 @@ def headerButtonsTimeline(defaultTimeline: str,
# show todays events buttons on the first inbox page # show todays events buttons on the first inbox page
happeningStr = '' happeningStr = ''
if boxName == 'inbox' and pageNumber == 1: 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 # happening today button
if not iconsAsButtons: if not iconsAsButtons:
happeningStr += \ happeningStr += \
@ -171,23 +172,23 @@ def headerButtonsTimeline(defaultTimeline: str,
'<button class="button">' + \ '<button class="button">' + \
translate['Happening Today'] + '</button></a>' translate['Happening Today'] + '</button></a>'
# happening this week button elif dayEventsCheck(baseDir, nickname, domain, tomorrow):
if thisWeeksEventsCheck(baseDir, nickname, domain): # happening tomorrow button
if not iconsAsButtons: if not iconsAsButtons:
happeningStr += \ happeningStr += \
'<a href="' + usersPath + \ '<a href="' + usersPath + '/calendar?year=' + \
'/calendar" tabindex="-1">' + \ str(tomorrow.year) + '?month=' + str(tomorrow.month) + \
'?day=' + str(tomorrow.day) + '" tabindex="-1">' + \
'<button class="buttonevent">' + \ '<button class="buttonevent">' + \
translate['Happening This Week'] + '</button></a>' translate['Happening Tomorrow'] + '</button></a>'
else: else:
happeningStr += \ happeningStr += \
'<a href="' + usersPath + \ '<a href="' + usersPath + '/calendar?year=' + \
'/calendar" tabindex="-1">' + \ str(tomorrow.year) + '?month=' + str(tomorrow.month) + \
'?day=' + str(tomorrow.day) + '" tabindex="-1">' + \
'<button class="button">' + \ '<button class="button">' + \
translate['Happening This Week'] + '</button></a>' translate['Happening Tomorrow'] + '</button></a>'
else: elif dayEventsCheck(baseDir, nickname, domain, twodays):
# happening this week button
if thisWeeksEventsCheck(baseDir, nickname, domain):
if not iconsAsButtons: if not iconsAsButtons:
happeningStr += \ happeningStr += \
'<a href="' + usersPath + \ '<a href="' + usersPath + \