sam-roberts / oura-data-visualiser

Grabs sleep data from the Oura API, stores it in a local database and allows you to visualise the data with Grafana
GNU General Public License v3.0
62 stars 10 forks source link

Can't load plugin: sqlalchemy.dialects:postgres #2

Closed benjaffe closed 1 year ago

benjaffe commented 1 year ago

I'm running into an issue getting this set up. I ran through the steps in the Readme, but am getting stuck when running the script.

$ cd ../oura-data-visualiser/
$ source venv/bin/activate
$ python3 sleep-data.py
Traceback (most recent call last):
  File "/Users/ben/Library/CloudStorage/Dropbox/Sites/oura-data-visualiser/sleep-data.py", line 231, in <module>
    main()
  File "/Users/ben/Library/CloudStorage/Dropbox/Sites/oura-data-visualiser/sleep-data.py", line 217, in main
    f"{config['db']['dbtype']}://{config['db']['username']}:{config['db']['password']}@{config['db']['host']}/{config['db']['dbname']}"
  File "/opt/homebrew/Cellar/python@3.9/3.9.17_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/configparser.py", line 1257, in __getitem__
    raise KeyError(key)
KeyError: 'dbtype'

I added dbtype = postgres to the config, and ran it again, and it got further (maybe dbtype should be added to the sample config in the repo?

Here's the error I'm stuck on now.

$ python3 sleep-data.py
Traceback (most recent call last):
  File "/Users/ben/Library/CloudStorage/Dropbox/Sites/oura-data-visualiser/sleep-data.py", line 231, in <module>
    main()
  File "/Users/ben/Library/CloudStorage/Dropbox/Sites/oura-data-visualiser/sleep-data.py", line 216, in main
    engine = create_engine(
  File "<string>", line 2, in create_engine
  File "/Users/ben/Library/CloudStorage/Dropbox/Sites/oura-data-visualiser/venv/lib/python3.9/site-packages/sqlalchemy/util/deprecations.py", line 281, in warned
    return fn(*args, **kwargs)  # type: ignore[no-any-return]
  File "/Users/ben/Library/CloudStorage/Dropbox/Sites/oura-data-visualiser/venv/lib/python3.9/site-packages/sqlalchemy/engine/create.py", line 552, in create_engine
    entrypoint = u._get_entrypoint()
  File "/Users/ben/Library/CloudStorage/Dropbox/Sites/oura-data-visualiser/venv/lib/python3.9/site-packages/sqlalchemy/engine/url.py", line 754, in _get_entrypoint
    cls = registry.load(name)
  File "/Users/ben/Library/CloudStorage/Dropbox/Sites/oura-data-visualiser/venv/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 368, in load
    raise exc.NoSuchModuleError(
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres

When I run pip install -r requirements.txt, I get "Requirement already satisfied" a bunch of times, so I think I have all the deps installed. I also tried to manually add the dep, pip install psycopg2, but I get the same error.

I'm on MacOS, and although I've done a lot of JS/TS development in my day, I've never actually played much with Python. Any ideas about what might be wrong?

sam-roberts commented 1 year ago

Hey @benjaffe sorry for that, my personal config file and the template got out of sync try dbtype = postgresql

with the 'l' at the end.

benjaffe commented 1 year ago

Yay, it's working! One confusing bit at first was that it doesn't output if it succeeds. And on subsequent runs, it just logs "sleep_sessions table has been dropped.". But it's working!

benjaffe commented 1 year ago

Thanks for the quick reply! Now I have more motivation for finally learn SQL after over a decade of avoiding it. O_O

sam-roberts commented 1 year ago

Yeah @benjaffe I had a decision to make (assuming the script runs daily) - whether to just add the new day to the previous data... or b) throw out all data, and reimport it all - and chose option B. So yes when you run the script it does actually delete the rows in the table, then inserts it all again. Its debatably inefficient but at this data size doesn't matter

benjaffe commented 1 year ago

Oh definitely @sam-roberts , that's completely reasonable. My only point is that it logs an expected thing that sounds scary, but doesn't give any feedback on success. I'd expect a "import complete" or something, to get the warm fuzzy feelings (and to verify that it did something the first time it's run). But dropping the table is definitely the move at this point in the project 😄