robberwick / pylibrelinkup

`pylibrelinkup` is a Python client for the LibreLinkUp API, which allows you to interact with the LibreLinkUp service to retrieve glucose data and other related information. This project is a Python implementation inspired by the [libre-link-up-api-client](https://github.com/DiaKEM/libre-link-up-api-client) project.
MIT License
2 stars 0 forks source link

patient_data.history limited to 141 blood level readings #34

Open alfredoramirez3 opened 4 days ago

alfredoramirez3 commented 4 days ago

patient_data.history only returns 141 items; not the complete history.

robberwick commented 4 days ago

patient_data.history should return the complete set of measurements that are reported by the LLU api's /llu/connections/{patient_id}/graph endpoint, which is not the full history of the patient's readings.

The raw response is exposed as the raw property on the ConnectionResponse model returned by the call to read(), so you should be able to check that nothing has been dropped.

what do you get if you run the following, replacing the {email}, {password}, and {patient_id} with your values?

from pylibrelinkup import PyLibreLinkUp
import json

client = PyLibreLinkUp(email="{email}", password="{password}")
client.authenticate()

conn_response = client.read(patient_identifier="{patient_id}")
raw_data = json.loads(conn_response.raw)

print(f"patient data history length: {len(conn_response.history)}")
print(f"raw graph data length: {len(raw_data['graph_data'])}")
robberwick commented 4 days ago

interestingly, running that with known login details for me gives only 47 items, but they do match:

patient data history length: 47
raw graph data length: 47
alfredoramirez3 commented 4 days ago

https://gist.github.com/khskekec/6c13ba01b10d3018d816706a32ae8ab2 image Please view comment by faysal-ali dated Feb 6 and ATouhou response dated Feb 10.. @faysal-ali I was able to access more data than described in this Gist, using the "/logbook" endpoint. Same headers and setup as "/graph" url. The data available from that is the same as is shown in the app under "log book / Logbog (danish)".

to your point, I was hoping to get "full history". not sure if using the /graph endpoint provides "full history" or just more data points.

any chance of adding an additional method that utilizes the /logbook endpoint?

alfredoramirez3 commented 4 days ago

sorry, correction ...

to your point, I was hoping to get "full history". not sure if using the "/logbook" endpoint provides "full history" or just more data points.

any chance of adding an additional method that utilizes the "/logbook" endpoint?

robberwick commented 4 days ago

Hi @alfredoramirez3 - apologies for that, i misunderstood your original question.

any chance of adding an additional method that utilizes the "/logbook" endpoint?

That's an excellent idea. Yeah, I can absolutely do that.

I'm fairly sure it'll still be only a truncated set of the full history, but if it's more than just the graph data, that's at least something..

robberwick commented 4 days ago

Hmm. looking at that thread, further down, there appears to be a suggestion that the data is only available from LibreView, and not LibreLinkUp (which would make sense given that the URL is /glucoseHistory/history, and doesn't have the usual llu/connections/{patient_id}/{endpoint} format.

I'll have a look into it though. If i can't implement that glucoseHistory endpoint via the LLU api, I'll add the logbook endpoint as a new method at the very least.

alfredoramirez3 commented 4 days ago

Wonder why the api’s didn’t provide start and end timestamp arguments for data extraction.

I’m a retired Data Engineer/Data Integration. Poor API design.

robberwick commented 4 days ago

yeah, the API is weird in places. don't even get me started on the fact that some of their json keys are camelCase and others are snake_case, even in the same object!

it makes my eye twitch just looking at it. 😄

robberwick commented 3 days ago

hi @alfredoramirez3 - i have a PR to implement support for that logbook endpoint on a working branch. if you want to give it an early play and see how it works for you, you can uninstall the pypi installed version and install it directly from github.

pip uninstall pylibrelinkup
pip install git+https://github.com/robberwick/pylibrelinkup.git@logbook-endpoint

I still need to write up some docs for it, and i might end up fiddling with the read method now that it's not the only method for retrieving data, so it's a bit poorly named, but you should be able to have a play with that logbook endpoint and see how you get on.