Skip to content

Instantly share code, notes, and snippets.

@kevinhughes27
Created August 23, 2015 17:36
Show Gist options
  • Save kevinhughes27/8ec8fdf9bf6ec9b8f857 to your computer and use it in GitHub Desktop.
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
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