Closed dpfrakes closed 1 year ago
Thanks man, merging it now, well solving the conflicts, since I always merge in the wrong order lol, and you forgot all about the free upper characters in example.py menu B-Z ;-)
I have all working, except for the delete_weigh_ins, it gives an error, seems the POST overrride with DELETE doesn't work, we don't use our own request code any more, need some investigation (option D in example.py
) and maybe a garth delete method...
Executing: Delete all weigh-ins for '2023-09-14'
WARNING:garminconnect:Multiple weigh-ins found for 2023-09-14
Traceback (most recent call last):
File "/home/ron/.local/lib/python3.11/site-packages/garth/http.py", line 123, in request
self.last_resp.raise_for_status()
File "/usr/lib/python3/dist-packages/requests/models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 405 Client Error: Method Not Allowed for url: https://connectapi.garmin.com/weight-service/weight/2023-09-14/byversion/1694695073182
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ron/development/python-garminconnect/./example.py", line 628, in <module>
switch(api, option)
File "/home/ron/development/python-garminconnect/./example.py", line 575, in switch
api.delete_weigh_ins(today.isoformat(), delete_all=True)
File "/home/ron/development/python-garminconnect/garminconnect/__init__.py", line 327, in delete_weigh_ins
self.delete_weigh_in(w['samplePk'], cdate)
File "/home/ron/development/python-garminconnect/garminconnect/__init__.py", line 306, in delete_weigh_in
return self.garth.post(
^^^^^^^^^^^^^^^^
File "/home/ron/.local/lib/python3.11/site-packages/garth/http.py", line 135, in post
return self.request("POST", *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ron/.local/lib/python3.11/site-packages/garth/http.py", line 125, in request
raise GarthHTTPError(
garth.exc.GarthHTTPError: Error in request: 405 Client Error: Method Not Allowed for url: https://connectapi.garmin.com/weight-service/weight/2023-09-14/byversion/1694695073182
Here's how you perform a DELETE
using Garth:
garth.request(
"DELETE",
"connectapi",
path,
api=True,
)
A correct response will be of type requests.Response
with status 204 No Content
.
garth.request( "DELETE", "connectapi", path, api=True, )
Yes this works, thanks a lot again!
@cyberjunky hope you don't mind but I saw https://github.com/cyberjunky/python-garminconnect/issues/130 and figured I'd give it a shot!
I didn't add these to your example script (running out of keys!), but I've documented sample usage here. Weight is returned by Garmin API in grams (g).
New methods
add_weigh_in(weight, unitKey, timestamp)
get_weigh_ins(startdate, enddate)
get_daily_weigh_ins(cdate)
delete_weigh_in(weight_pk, cdate)
<- not meant to be called directly since you need the weigh-in IDdelete_weigh_ins(cdate, delete_all)