Skip to content

Instantly share code, notes, and snippets.

@soohyunc
Forked from veekas/RescueTimeExport.py
Last active August 18, 2019 11:48
Show Gist options
  • Save soohyunc/8e0e70f4ad69f637e85818b48f73bd31 to your computer and use it in GitHub Desktop.
Save soohyunc/8e0e70f4ad69f637e85818b48f73bd31 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" # You need to create API key from RescueTime homepage
fileDirectory = ""
filePrefix = "rescuetime"
def main():
print "RescueTime Data Exporter"
print "Dates in format YYYY-MM-DD"
#TODO auto-populate the date of last modified
date_s = raw_input("Start Date: ")
#TODO change to 'yesterday's' date: yesterday = datetime.now() - timedelta(days=1); yesterday.strftime('%Y%m%d')
date_e = raw_input("End Date: ")
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