Skip to content

Instantly share code, notes, and snippets.

@craigeley
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigeley/335507da44a655070d66 to your computer and use it in GitHub Desktop.
Save craigeley/335507da44a655070d66 to your computer and use it in GitHub Desktop.
A Pythonista script that logs you into Foursquare. See http://craigeley.com/08-18-2014/foursquare-pythonista/ for more information.
# -*- coding: utf-8 -*-
# To call script, use the follwing URL Action:
# - <pythonista://foursquare_checkin.py?action=run>
# Replace the information in lines 21-23 with your actual client and authorization codes.
import location
import re
import sys
import urllib
import console
import webbrowser
import json
import requests
location.start_updates()
name = console.input_alert("Location", "Where are you?")
client_id = "CLIENT_ID"
client_secret = "CLIENT_SECRET"
access_token = "OAUTH_TOKEN"
b = location.get_location()
location.stop_updates()
ll = str(b["latitude"]) + "," + str(b["longitude"])
full_url = "https://api.foursquare.com/v2/venues/search?ll="+ll+"&query="+name+"&limit=1&client_id="+client_id+"&client_secret="+client_secret+"&v=20140816"
req = urllib.urlopen(full_url)
fsdata=json.load(req)
for item in fsdata['response']['venues']:
id = (item['id'])
venue = (item['name'])
checkin = "https://api.foursquare.com/v2/checkins/add?venueId="+id+"&ll="+ll+"&oauth_token="+access_token+"&v=20140816&m=swarm"
requests.post(checkin)
console.hud_alert("Checked in at "+venue)
webbrowser.open("launch://")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment