1
0

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>
This commit is contained in:
Jon Michael Aanes 2025-06-25 00:15:13 +02:00
parent 088cac75fc
commit bc4cea1cbc

View File

@ -0,0 +1,42 @@
"""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']}