-
-
Save veekas/2fe3cf30fe6375f5d121c6372a550000 to your computer and use it in GitHub Desktop.
RescueTime Data Export
This file contains hidden or 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() |
What steps do I need to take to use this? (Do I run it in terminal, and if so how?...)
@jmes - you need to create an API key from RescueTime homepage. There is a section saying "Data API / Integration", so visit this link, and the rest of the steps looks quite intuitive. After creating an API key, you need to replace line 12 "API_KEY" to the one you have it. Then, run "$ python RescueTimeExport.py
" in your terminal.
just rewrote this for python3 if anyone is interested https://gist.github.com/tuananhle7/28f0e57ed12cba544f0f90dc085ad78b
I just saw this, everyone. Sorry I left you all hanging. @tuananhle7's gist is great, I recommend using that going forward. :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey veekas,
For my MSc thesis, I'm working on modeling rescuetime data. Have you any idea where I might find a database of anonymous RT data?