aioamazondevices 0.2.0__py3-none-any.whl → 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  """aioamazondevices library."""
2
2
 
3
- __version__ = "0.2.0"
3
+ __version__ = "0.4.0"
4
4
 
5
5
 
6
6
  from .api import AmazonDevice, AmazonEchoApi
aioamazondevices/api.py CHANGED
@@ -185,21 +185,43 @@ class AmazonEchoApi:
185
185
  url,
186
186
  data=input_data,
187
187
  )
188
+ content_type = resp.headers.get("Content-Type", "")
189
+ _LOGGER.debug("Response content type: %s", content_type)
190
+
191
+ if "text/html" in content_type:
192
+ await self._save_to_file(
193
+ resp.text,
194
+ url,
195
+ )
196
+ elif content_type == "application/json":
197
+ await self._save_to_file(
198
+ orjson.dumps(
199
+ orjson.loads(resp.text),
200
+ option=orjson.OPT_INDENT_2,
201
+ ).decode("utf-8"),
202
+ url,
203
+ extension="json",
204
+ )
188
205
 
189
- await self._save_to_file(
190
- resp.text,
191
- url,
192
- )
193
206
  return BeautifulSoup(resp.content, "html.parser"), resp
194
207
 
195
- async def _save_to_file(self, html_code: str, url: str) -> None:
196
- """Sage HTML data to disk."""
208
+ async def _save_to_file(
209
+ self,
210
+ html_code: str,
211
+ url: str,
212
+ extension: str = "html",
213
+ output_path: str = "out",
214
+ ) -> None:
215
+ """Save response data to disk."""
197
216
  if not self._save_html:
198
217
  return
199
218
 
219
+ output_dir = Path(output_path)
220
+ output_dir.mkdir(parents=True, exist_ok=True)
221
+
200
222
  url_split = url.split("/")
201
- filename = f"{url_split[3]}-{url_split[4].split('?')[0]}.html"
202
- with Path.open(Path(filename), "w+") as file:
223
+ filename = f"{url_split[3]}-{url_split[4].split('?')[0]}.{extension}"
224
+ with Path.open(output_dir / filename, "w+") as file:
203
225
  file.write(html_code)
204
226
  file.write("\n")
205
227
 
@@ -275,12 +297,19 @@ class AmazonEchoApi:
275
297
  "GET",
276
298
  f"https://alexa.amazon.{self._domain}{URI_QUERIES[key]}",
277
299
  )
300
+ _LOGGER.debug("Response URL: %s", raw_resp.url)
301
+ response_code = raw_resp.status_code
302
+ _LOGGER.debug("Response code: %s", response_code)
303
+
304
+ response_data = raw_resp.text
305
+ _LOGGER.debug("Response data: |%s|", response_data)
306
+ json_data = {} if len(raw_resp.content) == 0 else raw_resp.json()
307
+
308
+ _LOGGER.debug("JSON data: |%s|", json_data)
278
309
 
279
310
  devices.update(
280
311
  {
281
- key: orjson.loads(
282
- raw_resp.text,
283
- ),
312
+ key: json_data,
284
313
  },
285
314
  )
286
315
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aioamazondevices
3
- Version: 0.2.0
3
+ Version: 0.4.0
4
4
  Summary: Python library to control Amazon devices
5
5
  Home-page: https://github.com/chemelli74/aioamazondevices
6
6
  License: Apache Software License 2.0
@@ -0,0 +1,9 @@
1
+ aioamazondevices/__init__.py,sha256=DSS6phrrmu0Q8zWGTzUhabNcQr2KgMV-Gpc6TF9EkR0,276
2
+ aioamazondevices/api.py,sha256=XAUw079QI2CC6eL532_LVg566B-Nxo4WmO_IP2zL_P8,10789
3
+ aioamazondevices/const.py,sha256=bZaeO8AeJbDc5hdlbJ3cMwM9teTgYhExSR1oEpRFMLk,1089
4
+ aioamazondevices/exceptions.py,sha256=tERMur_gry9TmU3UyzndJO_CLViISn4b8ClrRbryFy8,444
5
+ aioamazondevices/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ aioamazondevices-0.4.0.dist-info/LICENSE,sha256=sS48k5sp9bFV-NSHDfAJuTZZ_-AP9ZDqUzQ9sffGlsg,11346
7
+ aioamazondevices-0.4.0.dist-info/METADATA,sha256=iN60iBJz_Zu6J3_fbheEZrWGmvJ5WgKv9dBU5TRgjl8,4680
8
+ aioamazondevices-0.4.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
9
+ aioamazondevices-0.4.0.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- aioamazondevices/__init__.py,sha256=Zw6lQsQsOiDmSNnKKCTznWyMHgQ3us0XQsAww3w6YkU,276
2
- aioamazondevices/api.py,sha256=0du0a0tWEtT-5sIHIfk8K5Zf0ntIBpYgY3nwER_Pcm4,9735
3
- aioamazondevices/const.py,sha256=bZaeO8AeJbDc5hdlbJ3cMwM9teTgYhExSR1oEpRFMLk,1089
4
- aioamazondevices/exceptions.py,sha256=tERMur_gry9TmU3UyzndJO_CLViISn4b8ClrRbryFy8,444
5
- aioamazondevices/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- aioamazondevices-0.2.0.dist-info/LICENSE,sha256=sS48k5sp9bFV-NSHDfAJuTZZ_-AP9ZDqUzQ9sffGlsg,11346
7
- aioamazondevices-0.2.0.dist-info/METADATA,sha256=ypYsMxLoVYrWxQdLA8cHM0-ysCPWVzIN3yxYxMLs_M8,4680
8
- aioamazondevices-0.2.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
9
- aioamazondevices-0.2.0.dist-info/RECORD,,