Browse Source

analyzer: Make map timestamps in ISO format

master
Jakub Valenta 3 years ago
parent
commit
ab6d04bb5b
  1. 10
      README.md
  2. 6
      novinky_polls/analyzer.py
  3. 2
      setup.py

10
README.md

@ -60,11 +60,11 @@ Add current poll id with current timestamp to a CSV file:
The CSV file `my_polls.csv` now contains a map of poll timestamps to poll ids:
```
20150101190335,13678
20150101190338,13678
20150102153411,None
20150102202406,13677
20150102202408,13677
2015-01-01T19:03:35+02:00,13678
2015-01-01T19:03:38+02:00,13678
2015-01-02T15:34:11+02:00,None
2015-01-02T20:24:06+02:00,13677
2015-01-02T20:24:08+02:00,13677
...
```

6
novinky_polls/analyzer.py

@ -58,9 +58,7 @@ def read_map_lines(path: str) -> Iterator[MapLine]:
with open(path) as f:
reader = csv.reader(f)
for datetime_str, raw_poll_id in reader:
datetime_ = datetime.datetime.strptime(
datetime_str, '%Y%m%d%H%M%S'
)
datetime_ = datetime.datetime.fromisoformat(datetime_str)
if raw_poll_id is None:
poll_id: Optional[str] = ''
elif raw_poll_id == 'None':
@ -86,7 +84,7 @@ def map_write(path: str, poll_map: TPollMap):
with open(path, 'w') as f:
writer = csv.writer(f, lineterminator='\n')
writer.writerows(
(datetime_.strftime('%Y%m%d%H%M%S'), poll_id)
(datetime_.isformat(timespec='seconds'), poll_id)
for datetime_, poll_id in sorted(poll_map.items())
)

2
setup.py

@ -4,7 +4,7 @@ from setuptools import find_packages, setup
setup(
name='novinky-polls',
version='2.0.0',
version='2.1.0',
description=(
'Download and render opinion polls from the Czech news site '
'Novinky.cz'

Loading…
Cancel
Save