diff options
author | Christian Struck <christian@struck.se> | 2013-01-25 19:13:38 +0100 |
---|---|---|
committer | Christian Struck <christian@struck.se> | 2013-01-25 19:13:38 +0100 |
commit | 60eb631bb4628f59e0a32692b21ea045772be754 (patch) | |
tree | 9862c0914460d425ac5f743e7847afabec5f5dbf | |
parent | 2869559f6764a2f0e081cf284d72834160c52ee1 (diff) | |
download | bvg-grabber-60eb631bb4628f59e0a32692b21ea045772be754.tar.gz bvg-grabber-60eb631bb4628f59e0a32692b21ea045772be754.tar.bz2 bvg-grabber-60eb631bb4628f59e0a32692b21ea045772be754.zip |
added fuzzy time parsing, because there can be some random strings in the timestring
-rw-r--r-- | bvggrabber/api/__init__.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/bvggrabber/api/__init__.py b/bvggrabber/api/__init__.py index 1e31359..2793e3c 100644 --- a/bvggrabber/api/__init__.py +++ b/bvggrabber/api/__init__.py @@ -4,6 +4,7 @@ from dateutil.parser import parse fullformat = lambda dt: dt.strftime('%Y-%m-%d %H:%M') +hourformat = lambda dt: dt.strftime('%H:%M') class QueryApi(): @@ -26,7 +27,7 @@ class Departure(): # We assume to get a UNIX / POSIX timestamp self.when = datetime.fromtimestamp(when) elif isinstance(when, str): - self.when = parse(when) + self.when = parse(when, fuzzy=True) #if (self.when - self.now).total_seconds() < -60: # self.when = self.when + timedelta(days=1) elif isinstance(when, datetime): @@ -37,7 +38,7 @@ class Departure(): 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.start, self.end, hourformat(self.when), hourformat(self.now), self.line) @property |