Skip to content

Instantly share code, notes, and snippets.

@veekas
Forked from xurizaemon/RTExport
Last active June 5, 2020 06:17
Show Gist options
  • Save veekas/2fe3cf30fe6375f5d121c6372a550000 to your computer and use it in GitHub Desktop.
Save veekas/2fe3cf30fe6375f5d121c6372a550000 to your computer and use it in GitHub Desktop.
RescueTime Data Export
#!/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()
@soohyunc
Copy link

@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.

@tuananhle7
Copy link

just rewrote this for python3 if anyone is interested https://gist.github.com/tuananhle7/28f0e57ed12cba544f0f90dc085ad78b

@veekas
Copy link
Author

veekas commented Jun 5, 2020

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