Skip to content

Commit

Permalink
use datetime now, convewrt to local timezone, highlight now running p…
Browse files Browse the repository at this point in the history
…rograms
  • Loading branch information
joshinils committed Sep 5, 2020
1 parent 52d73aa commit aefc545
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
6 changes: 5 additions & 1 deletion models/day.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .channel import Channel
from typing import List
from datetime import datetime
from datetime import datetime, timedelta, timezone
from .programme import Programme


Expand All @@ -20,6 +20,10 @@ def addProgram(self, prog: Programme):
def getDate(self) -> str:
return str(self.date)

def isToday(self) -> bool:
LOCAL_TIMEZONE = datetime.now(timezone(timedelta(0))).astimezone().tzinfo
return self.date == datetime.now(LOCAL_TIMEZONE).date()

def getWochentag(self) -> str:
weekdays = {0: "Montag",
1: "Dienstag",
Expand Down
12 changes: 9 additions & 3 deletions models/programme.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from typing import Dict
from .channelName import ChannelName

LOCAL_TIMEZONE = datetime.now(timezone(timedelta(0))).astimezone().tzinfo


class Programme:
def __init__(self, channelName: ChannelName, start: datetime, stop: datetime):
self.channelName: ChannelName = channelName
date_format: str = "%Y%m%d%H%M%S %z"
self.start = datetime.strptime(start, date_format) + timedelta(hours=2)
self.stop = datetime.strptime(stop, date_format) + timedelta(hours=2)

self.start = datetime.strptime(start, date_format).astimezone(LOCAL_TIMEZONE)
self.stop = datetime.strptime(stop, date_format).astimezone(LOCAL_TIMEZONE)

self.data: Dict = {}
self.prominent = False
if self.start.hour >= 20 and self.start.minute >= 1:
self.prominent = True
if self.start.hour >= 21:
self.prominent = True
self.onPrevDay = False
now = datetime.now(LOCAL_TIMEZONE)
self.nowRunning = now >= self.start and now <= self.stop

def startTime(self) -> str:
return self.start.strftime("%H:%M")
Expand Down
4 changes: 4 additions & 0 deletions static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ body {
display: inline;
}

.nowRunning {
background-color: #ffffcc !important;
}

.prominent {
/* https://stackoverflow.com/questions/17158253/indent-starting-from-the-second-line-of-a-paragraph-with-css */
padding-left: 1.5em;
Expand Down
4 changes: 2 additions & 2 deletions templates/hello.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{% for day in guide.days.items() %}
<tr class="channelDay">
<td>
<div class="date">
<div class="date{% if day[1].isToday() %} nowRunning{% endif %}">
<div class="wochentag">
{{ day[1].getWochentag() }}
</div>
Expand All @@ -25,7 +25,7 @@
{{ channel[1].name.name }}
</div>
{% for prog in channel[1].programs %}
<div class="programme{% if prog.prominent %} prominent{% else %} nonprominent{% endif %}{% if prog.onPrevDay %} onPrevDay{% else %} onDay{% endif %} {{ prog.catgy() }}">
<div class="programme{% if prog.prominent %} prominent{% else %} nonprominent{% endif %}{% if prog.onPrevDay %} onPrevDay{% else %} onDay{% endif %}{% if prog.nowRunning %} nowRunning{% endif %} {{ prog.catgy() }}">
<div class="start">
{{ prog.startTime() }}
</div>
Expand Down

0 comments on commit aefc545

Please sign in to comment.