@@ -6,12 +6,17 @@ import json
66from typing import Optional
77from dataclasses import dataclass
88from itertools import count , chain
9+ from subprocess import check_output
910import shutil
1011from datetime import datetime
1112import urllib .parse
1213import urllib .request
1314import urllib .error
1415
16+ APIKEY = check_output (
17+ ('pass' , 'stibmivb.opendatasoft.com/apikey' )
18+ ).decode ().strip ()
19+
1520TZ = 'Europe/Brussels'
1621
1722CACHE = 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-
7577def _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
104106def _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+
145154for halt , lines in config .items ():
146155
147156 try :
0 commit comments