-
-
Save twolfson/3818a48ee29c6b027d2f61e8c991844b to your computer and use it in GitHub Desktop.
Simple Foursquare Checkins Archive of one User
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
checkins/ | |
venuehistory/ | |
venuelikes/ |
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
import requests, os, glob, json, sys, webbrowser | |
you = 'self' | |
# Configure preferred endpoint | |
# Checkins | |
data_path = 'checkins' | |
data_key = 'checkins' | |
item_id_key = None | |
# # Venue history | |
# data_path = 'venuehistory' | |
# data_key = 'venues' | |
# item_id_key = 'venue' | |
# # Venue likes | |
# data_path = 'venuelikes' | |
# data_key = 'venues' | |
# item_id_key = None | |
try: os.mkdir(data_path) | |
except OSError: pass | |
cid = 'YOUR_CLIENT_ID' | |
api_version = '20181219' | |
indent = 2 # spaces | |
if len(sys.argv) < 2: | |
webbrowser.open("""https://foursquare.com/oauth2/authenticate?client_id=%s&response_type=token&redirect_uri=%s""" % (cid, 'http://localhost:8000/')) | |
else: | |
token = sys.argv[1] | |
def run(offset = 0): | |
already = glob.glob("%s/*.json" % data_path) | |
start = 'https://api.foursquare.com/v2/users/%s/%s?oauth_token=%s&limit=100&offset=%s&v=%s' % (you, data_path, token, offset, api_version) | |
res = requests.get(start) | |
has_new = False | |
if res.status_code != 200: | |
raise RuntimeError("Received non-200 status code: %s -- %s" % (res.status_code, res.text)) | |
content = json.loads(res.text) | |
for item in content['response'][data_key]['items']: | |
item_id = item['id'] if item_id_key is None else item[item_id_key]['id'] | |
if ("%s/%s.json" % (data_path, item_id)) not in already: | |
with open('%s/%s.json' % (data_path, item_id), 'w') as fd: | |
json.dump(item, fd, indent=indent) | |
has_new = True | |
if has_new: | |
run(offset + 100) | |
print 'starting 4sq archive of @%s' % you | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment