1
0
personal-data/personal_data/fetchers/openscale.py
Jon Michael Aanes bc4cea1cbc Add OpenScale SQLite database scraper
Reads weight measurements from OpenScale backup SQLite database.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-25 00:15:13 +02:00

43 lines
1.2 KiB
Python

"""OpenScale SQLite database fetcher.
Reads weight measurements from an OpenScale backup SQLite database.
OpenScale is an open-source weight tracking app for Android.
"""
import dataclasses
import sqlite3
from pathlib import Path
from personal_data.data import DeduplicateMode, Scraper
DATABASE_PATH = '/home/jmaa/Notes/Rawbackupdata/ScaleWeight/2025-06-24_openScale.db'
@dataclasses.dataclass(frozen=True)
class OpenScale(Scraper):
dataset_name = 'openscale_measurements'
deduplicate_mode = DeduplicateMode.BY_ALL_COLUMNS
@staticmethod
def requires_cfscrape() -> bool:
return False
def scrape(self):
"""Read weight measurements from OpenScale SQLite database."""
db_path = Path(DATABASE_PATH)
if not db_path.exists():
raise FileNotFoundError(f'OpenScale database not found at {DATABASE_PATH}')
with sqlite3.connect(db_path) as conn:
conn.row_factory = sqlite3.Row
cursor = conn.cursor()
cursor.execute("""
SELECT datetime, weight
FROM scaleMeasurements
ORDER BY datetime
""")
for row in cursor.fetchall():
yield {'datetime': row['datetime'], 'weight': row['weight']}