-
-
Save b-luu/35151056154ce94c89e7e86c5381c72e to your computer and use it in GitHub Desktop.
RescueTime Data Export
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
#!/usr/bin/env python | |
#-*- coding: utf-8 -*- | |
# RescueTime Data Exporter | |
# Dan Nixon 18/09/2011 | |
# Chris Burgess 03/08/2015 | |
# Brice Luu 20/05/2016 | |
import urllib | |
import sys | |
from datetime import datetime | |
firstDayIUsed = "2016-05-03" # replace with yours | |
apiKey = "API_KEY" # add your API key | |
fileDirectory = "" | |
filePrefix = "RescueTimeData" | |
def main(): | |
print "RescueTime Data Exporter" | |
print "Dates in format YYYY-MM-DD" | |
date_s = sys.argv[1] if len(sys.argv) > 1 else firstDayIUsed | |
date_e = sys.argv[2] if len(sys.argv) > 2 else datetime.now().strftime('%Y-%m-%d') | |
print "Getting Data for Interval", date_s, "to", date_e | |
params = urllib.urlencode({'key':apiKey, 'perspective':'interval', 'format':'csv', 'restrict_begin':date_s, 'restrict_end':date_e}) | |
u = urllib.urlopen("https://www.rescuetime.com/anapi/data", params) | |
CSVdata = u.read() | |
filePath = fileDirectory + filePrefix + date_s.replace("-", "") + "-" + date_e.replace("-", "") + ".csv" | |
f = open(filePath, "w") | |
f.write(CSVdata) | |
f.close() | |
print "Data Saved to", filePath | |
print "" | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment