Now this could be me being very stupid here but please see the below code.
I am trying to work out what percentage of my carb goal I've already consumed at the point I run the script. I get the totals and store them in carbsConsumed
and carbsGoal
. carbsPercent
then calculates the percentage consumed. However, carbsPercent
returns 0 each time. Any thoughts?
#!/usr/bin/env python2.7
import myfitnesspal
from datetime import datetime
username = 'someusername'
password = 'somepassword'
date = datetime.now()
client = myfitnesspal.Client(username, password)
day = client.get_date(date.year, date.month, date.day)
#day = client.get_date(2015,11,12)
carbs = 'carbohydrates'
carbsConsumed = day.totals[carbs]
carbsGoal = day.goals[carbs]
carbsPercent = (carbsConsumed / carbsGoal) * 100
print 'Carbs consumed: ' + str(carbsConsumed)
print 'Carbs goal: ' + str(carbsGoal)
print 'Percentage consumed: ' + str(carbsPercent)