1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# -*- coding: utf-8 -*-
from datetime import datetime
from dateutil.parser import parse
fullformat = lambda dt: dt.strftime('%Y-%m-%d %H:%M')
class QueryApi():
def __init__(self):
pass
def call(self):
raise NotImplementedError("The inheriting class needs to implement "
"the call() method!")
class Departure():
def __init__(self, start, end, when, line):
self.start = start
self.end = end
self.now = datetime.now()
if isinstance(when, (int, float)):
# We assume to get a UNIX / POSIX timestamp
self.when = datetime.fromtimestamp(when)
elif isinstance(when, str):
self.when = parse(when)
#if (self.when - self.now).total_seconds() < -60:
# self.when = self.when + timedelta(days=1)
elif isinstance(when, datetime):
self.when = when
else:
ValueError("when must be a valid datetime, timestamp or string!")
self.line = line
def __str__(self):
return "Start: %s, End: %s, when: %s, now: %s, line: %s" % (
self.start, self.end, fullformat(self.when), fullformat(self.now),
self.line)
@property
def remaining(self):
return self.when - self.now
def to_json(self):
pass
|