-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_cli.py
48 lines (37 loc) · 1.42 KB
/
main_cli.py
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
import myfitnesspal
from rich.console import Console
from rich.table import Table
from datetime import date
def fetch_myfitnesspal_data(username, password):
try:
client = myfitnesspal.Client(username, password)
day = client.get_date(date.today())
total_calories = day.totals.get('calories', 0)
macros = {
'Protein': day.totals.get('protein', 0),
'Carbs': day.totals.get('carbohydrates', 0),
'Fats': day.totals.get('fat', 0)
}
return total_calories, macros
except Exception as e:
print(f"Error fetching data: {e}")
return None, None
def display_data_in_terminal(total_calories, macros):
console = Console()
table = Table(title="MyFitnessPal Summary", title_style="bold magenta")
table.add_column("Metric", style="bold cyan")
table.add_column("Value", style="bold green")
table.add_row("Calories", str(total_calories))
for macro, value in macros.items():
table.add_row(macro, str(value))
console.print(table)
def main():
username = input("Enter your MyFitnessPal username: ")
password = input("Enter your MyFitnessPal password: ")
total_calories, macros = fetch_myfitnesspal_data(username, password)
if total_calories is not None:
display_data_in_terminal(total_calories, macros)
else:
print("Failed to fetch or display data.")
if __name__ == "__main__":
main()