# HG changeset patch # User Paul Fisher # Date 1569772343 14400 # Node ID 6dbd9825b3f5d5f311662342a6bab160ac925db7 # Parent b1657de734d59412a2f6f18286f52fa8ee100dcc http_writer: switch to "preamble" based location/password. diff -r b1657de734d5 -r 6dbd9825b3f5 weatherlog/http_writer.py --- a/weatherlog/http_writer.py Sun Sep 29 01:18:58 2019 -0400 +++ b/weatherlog/http_writer.py Sun Sep 29 11:52:23 2019 -0400 @@ -11,15 +11,16 @@ class HTTPWriter(logger.RemoteWriter): - def __init__(self, url: str): + def __init__(self, url: str, preamble: t.Dict[str, t.Any]): self._url = url self._session = requests.Session() self._session.headers['User-Agent'] = 'weatherlogger/0.0.1' + self._preamble = bson.BSON.encode(preamble) def write(self, readings: t.Sequence[types.Reading]) -> None: try: data = b''.join(bson.BSON.encode(r.as_dict()) for r in readings) - response = self._session.post(self._url, data=data) + response = self._session.post(self._url, data=self._preamble + data) response.raise_for_status() except requests.exceptions.RequestException as rex: raise logger.RemoteWriteError("Coulndn't write values") from rex