Created
December 27, 2013 06:38
-
-
Save blech/8143434 to your computer and use it in GitHub Desktop.
A start on archiving data from Path
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
# requirements | |
# biplist==0.6 | |
# requests==2.1.0 | |
import json | |
import requests | |
from biplist import readPlist | |
from requests.auth import HTTPBasicAuth | |
from StringIO import StringIO | |
username = "" | |
password = "" | |
auth = HTTPBasicAuth(username, password) | |
api_url = "https://api.path.com/3/" | |
method = "moment/feed" | |
args = '' | |
more = True | |
moments = [] | |
old_oldest = 0 | |
while more: | |
r = requests.get(api_url+method+args, auth=auth) | |
plist = readPlist(StringIO(r.content)) | |
if not plist or not plist['moments']: | |
print "No more to add!" | |
more = False | |
else: | |
oldest = plist['moments'][-1]['created'] | |
moments.extend(plist['moments']) | |
# is there a better way to do this? | |
f = open("moments.json", 'w') | |
f.write(json.dumps(moments, sort_keys=True, indent=2)) | |
f.close() | |
print "Wrote %s moments back to %s" % (len(moments), oldest) | |
args = '?older_than=%s' % int(oldest) | |
if old_oldest == oldest: | |
more = False | |
else: | |
old_oldest = oldest | |
print "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment