Skip to content

Commit 6fd6ae8

Browse files
✨ feat(.bin/stib.fetch): Configure API key and timezone.
1 parent 61825d9 commit 6fd6ae8

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

.bin/stib.fetch

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ import json
66
from typing import Optional
77
from dataclasses import dataclass
88
from itertools import count, chain
9+
from subprocess import check_output
910
import shutil
1011
from datetime import datetime
1112
import urllib.parse
1213
import urllib.request
1314
import urllib.error
1415

16+
APIKEY = check_output(
17+
('pass', 'stibmivb.opendatasoft.com/apikey')
18+
).decode().strip()
19+
1520
TZ = 'Europe/Brussels'
1621

1722
CACHE = os.path.expanduser('~/.cache/stib')
@@ -69,9 +74,6 @@ def save(event: Event):
6974
with open(TIME.format(event.halt, event.line, event.eta.isoformat()), 'w'):
7075
pass
7176

72-
with open(CONFIG) as _config:
73-
config = json.load(_config)
74-
7577
def _fetch(halt, lines):
7678
results = _fetch_halt(halt)
7779
events = chain.from_iterable(map(_events, results))
@@ -102,10 +104,14 @@ def _result_for(halt: str):
102104
return _f
103105

104106
def _fetch_halt_page(halt: str, page: int):
107+
apikey = APIKEY
108+
timezone = TZ
105109
offset = (page - 1) * PAGE_SIZE
106110
limit = PAGE_SIZE
107111

108112
params = urllib.parse.urlencode({
113+
'apikey': apikey,
114+
'timezone': timezone,
109115
'where': 'pointid={}'.format(halt),
110116
'limit': limit,
111117
'offset': offset
@@ -142,6 +148,9 @@ def _line_filter(lines: set[str]):
142148
return predicate
143149

144150

151+
with open(CONFIG) as _config:
152+
config = json.load(_config)
153+
145154
for halt, lines in config.items():
146155

147156
try:

0 commit comments

Comments
 (0)