-
-
Save chmullig/9f1fe4f1400270dda5821294449a89b5 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 | |
# forked from Chris Burgess (xurizaemon) | |
import urllib | |
import datetime | |
apiKey = "API_KEY" | |
fileDirectory = "" | |
filePrefix = "RescueTime Data" | |
def main(): | |
print "RescueTime Data Exporter" | |
print "Dates in format YYYY-MM-DD" | |
date_s = raw_input("Start Date: ") #TODO auto-populate the date of last modified | |
date_e = raw_input("End Date: ") #TODO change to 'yesterday's' date: yesterday = datetime.now() - timedelta(days=1); yesterday.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 + ".csv" #simplified and generalized the filepath | |
f = open(filePath, "a") #changed to append the existing csv file instead of creating a new one | |
#TODO delete the duplicate header row that is created with each update | |
f.write(CSVdata) | |
f.close() | |
print "Data Saved to", filePath | |
print "" | |
#TODO make this process repeat daily/weekly/etc | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment