Skip to content

Commit

Permalink
some effort to handle events without time
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelu123 committed Jan 19, 2024
1 parent 1d09301 commit 2d3e03d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
11 changes: 10 additions & 1 deletion src/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
}
}


def loadSZ():
szPath = "c:/temp/tpjson/sommerzeiten.json"
global sommerzeiten
Expand All @@ -56,6 +57,8 @@ def loadSZ():

# see https://stackoverflow.com/questions/4770297/convert-utc-datetime-string-to-local-datetime-with-python
def convertToMEZOrMSZ(beginning): # '2018-04-29T06:30:00+00:00'
if beginning[10:19] == "T00:00:00":
return beginning[0:10] # without time, just return day
# scribus/Python2 does not support %z
beginning = beginning[0:19] # '2018-04-29T06:30:00'
d = time.strptime(beginning, "%Y-%m-%dT%H:%M:%S")
Expand Down Expand Up @@ -83,6 +86,13 @@ def convertToMEZOrMSZ(beginning): # '2018-04-29T06:30:00+00:00'
return mez


def getTime(date):
# if convertToMEZOrMSZ returned only day, then time=""
if len(date) <= 16:
return ""
return date[11:16]


class SAXHandler(xml.sax.handler.ContentHandler):
def __init__(self):
super().__init__()
Expand Down Expand Up @@ -331,4 +341,3 @@ def getAnmeldung(self):

def getTitel(self):
return self.titel

11 changes: 7 additions & 4 deletions src/eventXml.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ def tourLoc(self, tl):
beginning = tl.get("Beginning")
logger.debug("beginning %s", beginning) # '2018-04-24T12:00:00'
beginning = event.convertToMEZOrMSZ(beginning) # '2018-04-24T14:00:00'
beginning = beginning[11:16] # 14:00
# TODO wt
beginning = event.getTime(beginning) # 14:00
name = tl.get("Name")
street = tl.get("Street")
city = tl.get("City")
Expand Down Expand Up @@ -322,7 +323,7 @@ def getDatum(self):
day = str(datum[0:10])
date = time.strptime(day, "%Y-%m-%d")
weekday = event.weekdays[date.tm_wday]
res = (weekday + ", " + day[8:10] + "." + day[5:7] + "." + day[0:4], datum[11:16])
res = (weekday + ", " + day[8:10] + "." + day[5:7] + "." + day[0:4], event.getTime(datum))
return res

def getDatumRaw(self):
Expand All @@ -335,7 +336,8 @@ def getEndDatum(self):
day = str(datum[0:10])
date = time.strptime(day, "%Y-%m-%d")
weekday = event.weekdays[date.tm_wday]
res = (weekday + ", " + day[8:10] + "." + day[5:7] + "." + day[0:4], datum[11:16])
# TODO wt
res = (weekday + ", " + day[8:10] + "." + day[5:7] + "." + day[0:4], event.getTime(datum))
return res

def getEndDatumRaw(self):
Expand Down Expand Up @@ -433,7 +435,8 @@ def getAnmeldung(self):
res += max
if closDate is not None and closDate != "":
closDate = event.convertToMEZOrMSZ(closDate) # '2018-04-24T14:00:00'
closDate = closDate[8:10] + "." + closDate[5:7] + "." + closDate[0:4] + " " + closDate[11:16]
closDate = closDate[8:10] + "." + closDate[5:7] + "." + closDate[0:4] + " " + event.getTime(closDate)
# TODO wt
res += ", Anmeldeschluss: " + closDate + " (" + self.getDatum()[0][4:9] + ")"
if rurl != "":
res += ", extUrl=" + rurl
Expand Down
10 changes: 8 additions & 2 deletions src/expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,15 @@ def expAbfahrtenM(tour, _):
afs = tour.getAbfahrten()
if len(afs) == 0:
return ""
s = afs[0][1] + " Uhr; " + afs[0][2]
if afs[0][1] != "":
s = afs[0][1] + " Uhr; " + afs[0][2]
else:
s = afs[0][2]
for afx, af in enumerate(afs[1:]):
s = s + "\n " + str(afx + 2) + ". Startpunkt: " + afs[afx][1] + " Uhr;" + afs[afx][2]
if afs[afx][1] != "":
s = s + "\n " + str(afx + 2) + ". Startpunkt: " + afs[afx][1] + " Uhr;" + afs[afx][2]
else:
s = s + "\n " + str(afx + 2) + ". Startpunkt: " + afs[afx][2]
return s


Expand Down
8 changes: 4 additions & 4 deletions src/tourRest.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def getAbfahrten(self):
beginning = tourLoc.get("beginning")
logger.debug("beginning %s", beginning) # '2018-04-24T12:00:00'
beginning = event.convertToMEZOrMSZ(beginning) # '2018-04-24T14:00:00'
beginning = beginning[11:16] # 14:00
beginning = event.getTime(beginning) # 14:00
else:
beginning = ""
name = tourLoc.get("name")
Expand Down Expand Up @@ -235,7 +235,7 @@ def getDatum(self):
day = str(datum[0:10])
date = time.strptime(day, "%Y-%m-%d")
weekday = event.weekdays[date.tm_wday]
res = (weekday + ", " + day[8:10] + "." + day[5:7] + "." + day[0:4], datum[11:16], datum)
res = (weekday + ", " + day[8:10] + "." + day[5:7] + "." + day[0:4], event.getTime(datum), datum)
return res

def getDatumRaw(self):
Expand All @@ -250,7 +250,7 @@ def getEndDatum(self):
day = str(enddatum[0:10])
date = time.strptime(day, "%Y-%m-%d")
weekday = event.weekdays[date.tm_wday]
res = (weekday + ", " + day[8:10] + "." + day[5:7] + "." + day[0:4], enddatum[11:16])
res = (weekday + ", " + day[8:10] + "." + day[5:7] + "." + day[0:4], event.getTime(enddatum))
return res

def getEndDatumRaw(self):
Expand Down Expand Up @@ -335,7 +335,7 @@ def getAnmeldung(self):
res += str(max)
if closDate is not None and closDate != "":
closDate = event.convertToMEZOrMSZ(closDate)
closDate = closDate[8:10] + "." + closDate[5:7] + "." + closDate[0:4] + " " + closDate[11:16]
closDate = closDate[8:10] + "." + closDate[5:7] + "." + closDate[0:4] + " " + event.getTime(closDate)
res += ", Anmeldeschluss: " + closDate + " (" + self.getDatum()[0][4:9] + ")"
if rurl != "":
res += ", extUrl=" + rurl
Expand Down

0 comments on commit 2d3e03d

Please sign in to comment.