Created
February 19, 2013 05:45
-
-
Save loisaidasam/4983399 to your computer and use it in GitHub Desktop.
Foursquare miner for "here now" - you used to be able to do this, but apparently can't anymore... : \
This file contains 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 urllib | |
import simplejson as json | |
import random | |
import time | |
client_id = 'FOURSQUARE_CLIENT_ID (yours, not mine)' | |
client_secret = 'FOURSQUARE_CLIENT_SECRET (yours, not mine)' | |
'''Ljubljana''' | |
min_lat = 46.0424722222 | |
max_lat = 46.0643916667 | |
min_lon = 14.49575 | |
max_lon = 14.5225416667 | |
'''New York | |
min_lat = max_lat = 42.782138 | |
min_lon = max_lon = -86.108573 | |
''' | |
CONST = 10000000000 | |
while True: | |
'''Ljubljana''' | |
lat = random.randrange(0, int((max_lat - min_lat)*CONST)) | |
lat = min_lat + (float(lat)/CONST) | |
lon = random.randrange(0, int((max_lon - min_lon)*CONST)) | |
lon = min_lon + (float(lon)/CONST) | |
'''New York | |
lat = min_lat | |
lon = min_lon | |
''' | |
#lat = '46.048723' | |
#lon = '14.514184' | |
ll = '%s,%s' % (lat, lon) | |
print "lat/lon: %s, %s" % (lat, lon) | |
limit = 50 | |
# Apparently you used to be able to do this, but not anymore: | |
# https://developer.foursquare.com/docs/venues/search | |
# https://developer.foursquare.com/docs/venues/herenow | |
url = 'https://api.foursquare.com/v2/venues/search?ll=%s&client_id=%s&client_secret=%s&limit=%s' % (ll, client_id, client_secret, limit) | |
sock = urllib.urlopen(url) | |
data = sock.read() | |
sock.close() | |
jdata = json.loads(data) | |
#print jdata | |
response = jdata['response'] | |
#group = response['groups'].pop() | |
for group in response['groups']: | |
print "%s items in group '%s'" % (len(group['items']), group['name']) | |
for item in group['items']: | |
if item['hereNow']['count']: | |
print "%s: %s" % (item['name'], item['hereNow']['count']) | |
time.sleep(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment