Esempio n. 1
0
moves = MovesClient(MOVES_CLIENT_ID, MOVES_CLIENT_SECRET)
moves.access_token = MOVES_ACCESS_TOKEN

[dl_yr, dl_mo] = [int(d) for d in yr_mo_str.split('-')]
dl_maxdy = monthrange(dl_yr, dl_mo)[1]

start_date = max(MOVES_FIRST_DATE, date(dl_yr, dl_mo, 1))
end_date = min(date(dl_yr, dl_mo, dl_maxdy), date.today())
# end_date = date.today() - timedelta(days=1)

moves_data = []
dl_date = start_date

# Storyline download

print 'Downloading Moves storyline for %s' % yr_mo_str

while dl_date <= end_date:
    datestr = dl_date.strftime('%Y%m%d')
    print datestr
    new_storyline = moves.user_storyline_daily(datestr, trackPoints='true')
    moves_data.extend(new_storyline)
    dl_date = dl_date + timedelta(days=1)
    time.sleep(1)  # Enough to be a good citizen?

with open(outfile, 'w') as outfp:
    json.dump(moves_data, outfp)
    
print 'Wrote %d records.' % len(moves_data)