-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.example.py
More file actions
89 lines (73 loc) · 3.34 KB
/
config.example.py
File metadata and controls
89 lines (73 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""
Configuration file for MyFitnessPal to Postgres sync.
Loads sensitive data from .env file.
SETUP:
1. Copy .env.example to .env
2. Edit .env with your actual Postgres credentials
3. This config.py can be committed to Git (no sensitive data here)
"""
import os
from pathlib import Path
from dotenv import load_dotenv
# Load environment variables from .env file
env_path = Path(__file__).parent / '.env'
load_dotenv(dotenv_path=env_path)
# ============================================================================
# POSTGRES DATABASE CONFIGURATION
# ============================================================================
POSTGRES_CONFIG = {
'host': os.getenv('POSTGRES_HOST', 'localhost'),
'port': int(os.getenv('POSTGRES_PORT', '5432')),
'database': os.getenv('POSTGRES_DB', 'analytics'),
'user': os.getenv('POSTGRES_USER', 'postgres'),
'password': os.getenv('POSTGRES_PASSWORD') # Required - must be in .env
}
# Validate that password is set
if not POSTGRES_CONFIG['password']:
raise ValueError(
"POSTGRES_PASSWORD not found in environment variables!\n"
"Please create a .env file (copy from .env.example) and set your password."
)
# ============================================================================
# TABLE NAMES
# ============================================================================
FOOD_ENTRIES_TABLE = 'food_entries'
EXERCISES_TABLE = 'exercises'
WEIGHT_MEASUREMENTS_TABLE = 'weight_measurements'
# ============================================================================
# SYNC MODE
# ============================================================================
# Controls how data is synced to the database:
# - 'append': Only insert/update records (deletions in MFP won't be reflected)
# - 'overwrite': Delete all records for each day before syncing (captures deletions)
SYNC_MODE = 'overwrite'
# ============================================================================
# SYNC SETTINGS
# ============================================================================
# Date range for syncing
# Can be:
# - datetime.date object: date(2025, 1, 1)
# - Callable/lambda: lambda: date.today() - timedelta(days=90)
# - String that will be parsed: '2025-01-01'
#
# Examples:
# START_DATE = date(2025, 1, 1) # Absolute date
# START_DATE = lambda: date.today() - timedelta(days=90) # Relative date
# END_DATE = lambda: date.today() # Today (inclusive)
from datetime import date, timedelta
START_DATE = lambda: date.today() - timedelta(days=90) # 90 days ago
END_DATE = lambda: date.today() # Today (inclusive)
# Wait time in seconds between API requests (to avoid rate limiting)
RATE_LIMIT_SECONDS = 2
# ============================================================================
# BROWSER AUTHENTICATION SETTINGS
# ============================================================================
# This script uses Firefox cookies for authentication
# Make sure you're logged in to MyFitnessPal in Firefox
# Maximum time to wait for manual login (in seconds)
MAX_LOGIN_WAIT_SECONDS = 300 # 5 minutes
# MyFitnessPal login URL
MFP_LOGIN_URL = 'https://www.myfitnesspal.com/account/login'
# Note: Firefox cookies persist even when Firefox is closed, so scheduled
# tasks will work fine without Firefox running. If cookies expire (typically
# after 30 days), the script will open Firefox for you to log in again.