Created
August 23, 2015 17:36
-
-
Save kevinhughes27/8ec8fdf9bf6ec9b8f857 to your computer and use it in GitHub Desktop.
scrape date between 2 date ranges from my fitness pal. Scrapes current nutrients being tracked but you can change your settings and re-run the scraper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import myfitnesspal # pip install myfitnesspal | |
import ipdb | |
print 'logging in ...' | |
client = myfitnesspal.Client('username', 'password') | |
days = [] | |
for i in range(2, 18+1): | |
print 'fetching 2015, 6,', i | |
days.append( client.get_date(2015, 6, i) ) | |
print 'saving ...' | |
f = open('scrape_1.csv', 'w') | |
header = "" | |
header += 'date,' | |
header += 'food,' | |
header += ",".join(days[0].totals.keys()) | |
header += "\n" | |
f.write(header) | |
for day in days: | |
for meal in day.meals: | |
for entry in meal: | |
date_string = str(day.date) | |
name = entry.name.strip().replace(',', ' ') | |
totals = ",".join( map(str, entry.totals.values()) ) | |
row = "" | |
row += date_string | |
row += "," | |
row += name | |
row += "," | |
row += totals | |
row += "\n" | |
f.write(row) | |
f.close() | |
print "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment