From 56ba5c1c191258c8568201f0c4df664ac1b6b809 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 11 Oct 2019 10:02:20 +0100 Subject: [PATCH] Circle around today --- epicyon-calendar.css | 37 ++++++++------------------------ webinterface.py | 51 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 30 deletions(-) diff --git a/epicyon-calendar.css b/epicyon-calendar.css index c39be7d3c..ee5e99a08 100644 --- a/epicyon-calendar.css +++ b/epicyon-calendar.css @@ -5,7 +5,7 @@ --day-number: #a4a2a2; --day-number2: #c9c7c7; --today-foreground: white; - --today-background: darkgray; + --today-circle: yellow; } body { @@ -95,33 +95,14 @@ tr:nth-child(even) > .calendar__day__cell:nth-child(even) { background-color: blue; color: blue; } -.calendar__day__cell[data-event]:after { - content: attr(data-event); - color: #F6E9DC; - display: block; - font-weight: 400; - font-size: .75rem; - position: absolute; - bottom: 0; - width: 100%; - height: 1rem; - text-transform: uppercase; -} .calendar__day__cell[data-today] { - background-color: var(--today-background); - border-color: var(--today-background); - color: var(--today-foreground); -} -.calendar__day__cell[data-today]:after { - content: attr(data-today); - color: var(--today-foreground); - display: block; - font-size: .75rem; - font-weight: 400; - position: absolute; - bottom: 0; - width: 100%; - height: 1rem; - text-transform: uppercase; + border-radius: 50%; + width: 36px; + height: 36px; + padding: 8px; + + border: 4px solid var(--today-circle); + color: var(--today-circle); + text-align: center; } diff --git a/webinterface.py b/webinterface.py index 84820120e..dc40e9ffc 100644 --- a/webinterface.py +++ b/webinterface.py @@ -2751,6 +2751,51 @@ def weekDayOfMonthStart(monthNumber: int,year: int) -> int: firstDayOfMonth=datetime(year, monthNumber, 1, 0, 0) return int(firstDayOfMonth.strftime("%w"))+1 +def getCalendarEvents(baseDir: str,nickname: str,domain: str,year: int,monthNumber: int) -> []: + """Retrieves calendar events + Returns a list of lists containing Event and Place activities + """ + calendarFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/calendar/'+str(year)+'/'+str(monthNumber)+'.txt' + events=[] + if not os.path.isfile(calendarFilename): + return events + calendarPostIds=[] + recreateEventsFile=False + with open(calendarFilename,'r') as eventsFile: + for postId in eventsFile: + postFilename=locatePost(baseDir,nickname,domain,postId) + if postFilename: + postJsonObject=None + try: + with open(postFilename, 'r') as fp: + postJsonObject=commentjson.load(fp) + except Exception as e: + print(e) + if postJsonObject: + if postJsonObject.get('object'): + if isinstance(postJsonObject['object'], dict): + if postJsonObject['object'].get('tag'): + postEvent=[] + for tag in postJsonObject['object']['tag']: + if tag.get('type'): + if tag['type']=='Event' or tag['type']=='Place': + postEvent.append(tag) + if postEvent: + calendarPostIds.append(postId) + # TODO this should be in a calendar-like format + events.append(postEvent) + else: + recreateEventsFile=True + + # if some posts have been deleted then regenerate the calendar file + if recreateEventsFile: + calendarFile=open(calendarFilename, "w") + for postId in calendarPostIds: + calendarFile.write(postId+'\n') + calendarFile.close() + + return events + def htmlCalendar(translate: {}, \ baseDir: str,path: str) -> str: """Show the calendar for a person @@ -2780,10 +2825,12 @@ def htmlCalendar(translate: {}, \ monthNumber=currDate.month print('Calendar year='+str(year)+' month='+str(monthNumber)+ ' '+str(weekDayOfMonthStart(monthNumber,year))) - + nickname=getNicknameFromActor(actor) domain,port=getDomainFromActor(actor) - + + events=getCalendarEvents(baseDir,nickname,domain,year,monthNumber) + months=['Jaruary','February','March','April','May','June','July','August','September','October','November','December'] monthName=translate[months[monthNumber-1]]