Mercurial > personal > weatherlog
changeset 11:6dbd9825b3f5
http_writer: switch to "preamble" based location/password.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Sun, 29 Sep 2019 11:52:23 -0400 |
parents | b1657de734d5 |
children | 91e22a09b82f |
files | weatherlog/http_writer.py |
diffstat | 1 files changed, 3 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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