def access_force(self, timeout=3): url = self.url_for_access if url.startswith('http'): super(LegacyPlace, self).access_force(timeout=timeout) return result = None if url.startswith('4square'): from foursquare import Foursquare client = Foursquare(client_id=FOURSQUARE_CLIENT_ID, client_secret=FOURSQUARE_CLIENT_SECRET) result = client.venues(url.split('//')[1]) elif url.startswith('google'): result = self.access_force_google(url) else: raise NotImplementedError if result: result = json_dumps(result, ensure_ascii=False) file = Path(self.path_accessed) if not file.parent.exists(): file.parent.mkdir(parents=True) summary = Path(self.path_summarized) if not Path(self.path_summarized).parent.exists(): summary.parent.mkdir(parents=True) file.write_text(result) self._cache_accessed = result.replace('\r', '')
def search_venues(): fsq = Foursquare(client_id=keys.FOURSQUARE_CLIENT_ID, client_secret=keys.FOURSQUARE_CLIENT_SECRET, version=keys.FOURSQUARE_VERSION) lcs = ['19.5024271,-99.1316738', '19.412084,-99.180576', '19.427657,-99.204116'] for l in lcs: venues = fsq.find_venues(location=l, radius=1500) for venue in venues: location = venue.get('location') slocation = "%s, %s" % (location.get('city', 'NA'), location.get('state', 'NA')) categories = [] for category in venue.get('categories'): u = 'https://api.parse.com/1/classes/Category' cat = requests.get(u, data={ 'where': json.dumps({'sq_id': category.get('id')}), }, headers={ "X-Parse-Application-Id": keys.PARSE_APP_ID, "X-Parse-REST-API-Key": keys.PARSE_REST_KEY }) cats = cat.json()['results'] for c in cats: if c.get('sq_id') == category.get('id'): categories.append({ '__type': 'Pointer', 'className': 'Category', 'objectId': c.get('objectId') }) break requests.post('https://api.parse.com/1/classes/Place', json={ 'location': { '__type': 'GeoPoint', 'latitude': location.get('lat'), 'longitude': location.get('lng') }, 'name': venue.get('name'), 'sq_id': venue.get('id'), 'shortLocation': slocation, 'categories': {'__op': 'AddRelation', 'objects': categories} }, headers={ "X-Parse-Application-Id": keys.PARSE_APP_ID, "X-Parse-REST-API-Key": keys.PARSE_REST_KEY, 'Content-type': 'application/json', }) print venue.get('name') return "Populated :D"
def popular_hashtags(lat, long): hashtags = {} fs = Foursquare() venues = fs.venues(lat, long, 10) for v in venues: #print "Venue: ", v.name results = twitter_call(v.name, (lat,long,radius)) for s in results: ht = parse_hashtags(s.text) for h in ht: if hashtags.has_key(h): hashtags[h] = hashtags[h]+1 else: hashtags[h] = 1 return hashtags
def __init__(self, user_store, dialog_store, conversation_username, conversation_password, conversation_workspace_id, foursquare_client_id, foursquare_client_secret): """ Creates a new instance of HealthBot. Parameters ---------- user_store - Instance of CloudantUserStore used to store and retrieve users from Cloudant dialog_store - Instance of CloudantDialogStore used to store conversation history conversation_username - The Watson Conversation username conversation_password - The Watson Converation password conversation_workspace_id - The Watson Conversation workspace ID foursquare_client_id - The Foursquare Client ID foursquare_client_secret - The Foursquare Client Secret """ self.user_store = user_store self.dialog_store = dialog_store self.dialog_queue = {} self.conversation_client = ConversationV1( username=conversation_username, password=conversation_password, version='2016-07-11' ) self.conversation_workspace_id = conversation_workspace_id if foursquare_client_id is not None and foursquare_client_secret is not None: self.foursquare_client = Foursquare(client_id=foursquare_client_id, client_secret=foursquare_client_secret) else: self.foursquare_client = None
def make_venues_yaml(access_token: str) -> None: client = Foursquare(access_token=access_token) tree = client.venues.categories() tree = strip(tree) with open("venues.yaml", "w", encoding='utf-8') as f: yaml.safe_dump(tree, stream=f, sort_keys=False, allow_unicode=True)
def __init__(self, oauth, explore=None, photos=None): if explore is None: explore = {} if photos is None: photos = [] self.f = Foursquare(access_token=oauth) self.explore = explore self.photos = photos
def __init__(self, access_token=None): self.logger = get_logger(__name__) self.fsq = Foursquare( client_id=FOURSQUARE_CLIENT_ID, client_secret=FOURSQUARE_CLIENT_SECRET, redirect_uri=LOGIN_REDIRECT_URI ) if access_token is not None: self.set_token(access_token) self.cache = Cache()
def create_clients(): clients = [] clients.append( Foursquare( client_id='TXJGNUZMJ1KRZW1DMQCH43LS4G2GYRIJDRWWWZ44XYMHW0SY', client_secret='HAR0VUXOUMTKAGYMEK20SINMZKD2HECG1ZGVTHICHMTUBNKB')) clients.append( Foursquare( client_id='Z51MG4J5IW2OIB4QJYFDENW5OGK2IK3JJ3CCXDA5V1GG1URI', client_secret='0KKY3EUPQDK3JPXMC0ICETGP1EZJOXW4UNM5NNCL0YVZ1I0A')) clients.append( Foursquare( client_id='MYOBFJCXXTCYJZSHSTAXDZRQ3HSI3CCMKSVWNU5B5UPBLP04', client_secret='GYOPNHNIJBJT0POOYFMBPGEXMWM1VT2TBVBJ4IWEBGCINCYV')) clients.append( Foursquare( client_id='DKF1U0IIIGKHKUM3P3Q1CUOB1P5IGO1PBECGCP501V22LGUT', client_secret='PWQBZLVURTBWZJBGQNKULHAPDVYWLSLD45UBMI1SD2XIN3II')) clients.append( Foursquare( client_id='Z3ONQA0HX4EOBHTWNMKYPAF3SITXVHOA45LQJIBP2SCHY1JD', client_secret='KBV3MSMGAJ0CQJVGDDM20ZCKOXQYFRLTVQTPLDVM3N0CHPNU')) clients.append( Foursquare( client_id='WJTFTKDUFL3TBC1RN4LZ3KMTX4QCUA04U0GXMZGP5IQEWLRM', client_secret='15DFPEVFMYL1Q5LOCQ5D3AKLFGAO3L3SXSYONQBGLQQR5JDR')) clients.append( Foursquare( client_id='11TIOC2VSEIR0J0PZA2UIV1V053OQNNUJ1FRWMBJAVQC1M2A', client_secret='FU1BMT1L0Z3R34OLDBM1PMBK5HXFKXBPTR4KGHHACMAWOJFJ')) clients.append( Foursquare( client_id='0SCCF3VM21YCYIVH2PWIM5AQRTSWZ1241THVVXLRXDIXGKKF', client_secret='1LWLCHKYGP4FG3P2BAQQSDDSWWAZZS1Q5MYQO15ZS1NDD30F')) clients.append( Foursquare( client_id='PXQHCO0MQJ45BNXJ1SZTCCF1CJT5ZWSB4CCT4S0J50F0X2LK', client_secret='3MNNLG4YJ1Z4JQRNNYZLH5WHEHO24DKV2CIIKAQAEY3V4DU1')) clients.append( Foursquare( client_id='3GROBV5QXWMX3O30BITHE5VIW2VHE4KEUCROGBVXHXPQILW1', client_secret='HZMRZTCYCCS1E1OVTUMKYFEDEHWDZGLZJSQIJSYNCV1LMVPE')) return clients
def get_last_checkin(self): # use the access token to get user's data foursquare_client = Foursquare(access_token=self.fs_access_token) fs_checkin = foursquare_client.users.checkins(params={'limit': 1}) # flag to indicate that the checkin is new new_chk = False if (fs_checkin['checkins']['count'] == 0): # foursquare did not send the user's last checkin # possible that the user have not ever checked in last_stored_checkin = self.checkins.order_by('-id').first() if last_stored_checkin is None: # don't have a last checkin stored for this user return None, new_chk else: return last_stored_checkin, new_chk # got a checkin from foursquare # is this a newer checkin than what we have in the database? fs_id = fs_checkin['checkins']['items'][0]['id'] fs_created = fs_checkin['checkins']['items'][0]['createdAt'] # get user's last checkin stored in the database last_stored_checkin = self.checkins.order_by('-id').first() # if checkin table is empty or the stored fs_checkin id doesn't match # the checkin fs_id received from fs, then add the checkin received # from foursquare to the list of checkins for this user if (last_stored_checkin is None or last_stored_checkin.fs_created != fs_created): name = fs_checkin['checkins']['items'][0]['venue']['name'] fs_created_tz_offset = fs_checkin['checkins']['items'][0][ 'timeZoneOffset'] location = fs_checkin['checkins']['items'][0]['venue']['location'] lat = location['lat'] lng = location['lng'] checkin = Checkin(name=name, fs_id=fs_id, fs_created=fs_created, fs_created_tz_offset=fs_created_tz_offset, lat=lat, lng=lng, user=self) db.session.add(checkin) db.session.commit() new_chk = True return checkin, new_chk else: # foursquare does not keep state of the checkins it sends # we have seen this checkin before return last_stored_checkin, new_chk
def getFoursquareClient(): from foursquare import Foursquare import webbrowser if FOURSQUARE_USER_TOKEN: foursq_client = Foursquare(access_token=FOURSQUARE_USER_TOKEN, version='20130415') else: foursq_client = Foursquare( client_id=FOURSQUARE_CLIENT_ID, client_secret=FOURSQUARE_CLIENT_SECRET, redirect_uri='http://vu0.org/projects/appsquare/foursquare.html', version='20130415') webbrowser.open(foursq_client.oauth.auth_url()) foursq_code = raw_input('Please paste the code from the website: ') access_token = foursq_client.oauth.get_token(foursq_code) print 'FOURSQUARE_USER_TOKEN for the script: %s' % access_token sys.exit(0) return foursq_client
def __init__(self): try: Module.__init__(self, "foursquare") except: return self.client = Foursquare( access_token=config.get('foursquare', 'access_token')) if not self.initial_import(): self.regular_import()
def prompt_fs_authorize(): # get secret and urls fs_client_id = app.config['FS_CLIENT_ID'] fs_client_secret = app.config['FS_CLIENT_SECRET'] fs_redirect_uri = app.config['FS_REDIRECT_URI'] # get fs redirect link foursquare_client = Foursquare(client_id=fs_client_id, client_secret=fs_client_secret, redirect_uri=fs_redirect_uri) fs_authorize_url = foursquare_client.oauth.auth_url() return render_template('fs_authorize.html', fs_link=fs_authorize_url)
def checkins(gauge_factory, config, logger): """Number of foursquare check-ins done since midnight today in UTC. """ gauge = gauge_factory('foursquare.checkins') client = Foursquare(access_token=config['foursquare.access_token']) epoch = epoch_for_day(today_utc()) checkins = client.users.checkins(params={'afterTimestamp': epoch}) checkins = checkins['checkins']['items'] gauge.save(today_utc(), len(checkins)) logger.info('Saved {0} foursquare checkins'.format(len(checkins)))
def get_categories(): def push_category(category, cats, parent=None): """ Save category on Parse """ categories = category.get('categories', []) category_dict = { 'hash': category.get('hash'), 'name': category.get('name'), 'sq_id': category.get('id'), 'icon': category.get('icon'), } cats[0] += 1 if parent: category_dict.update({'parent': { '__type': "Pointer", 'className': 'Category', 'objectId': parent }}) oid = requests.get('https://api.parse.com/1/classes/Category', json=category_dict, headers={ "X-Parse-Application-Id": keys.PARSE_APP_ID, "X-Parse-REST-API-Key": keys.PARSE_REST_KEY, 'Content-type': 'application/json', }).json()['objectId'] for cat in categories: push_category(cat, parent=oid, cats=cats) fsq = Foursquare(client_id=keys.FOURSQUARE_CLIENT_ID, client_secret=keys.FOURSQUARE_CLIENT_SECRET, version=keys.FOURSQUARE_VERSION) categs = fsq.find_categories() cs = [0] for category in categs: push_category(category, cats=cs)
def callback(): # get the current user user = current_user # parse out code from call back code = request.args.get('code') session['code'] = code # exchange code for access token, get secret and urls fs_client_id = app.config['FS_CLIENT_ID'] fs_client_secret = app.config['FS_CLIENT_SECRET'] fs_redirect_uri = app.config['FS_REDIRECT_URI'] foursquare_client = Foursquare(client_id=fs_client_id, client_secret=fs_client_secret, redirect_uri=fs_redirect_uri) access_token = foursquare_client.oauth.get_token(code) # save the access token if access_token and access_token != '': user.fs_access_token = access_token db.session.commit() return redirect(url_for('forecast'))
def process_websocket_message(text): load_dotenv(os.path.join(os.path.dirname(__file__), '.env')) foursquare_client_id = os.environ.get('FOURSQUARE_CLIENT_ID') foursquare_client_secret = os.environ.get('FOURSQUARE_CLIENT_SECRET') print foursquare_client_id print foursquare_client_secret foursquare_client = None if foursquare_client_id is not None and foursquare_client_secret is not None: foursquare_client = Foursquare(client_id=foursquare_client_id, client_secret=foursquare_client_secret) else: foursquare_client = None query = text + ' Doctor' # Get the location entered by the user to be used in the query location = 'austin' params = { 'query': query, 'near': location, 'radius': 5000, 'categoryId': '4bf58dd8d48988d104941735,4bf58dd8d48988d10f951735' } print(params) venues = foursquare_client.venues.search(params=params) print "here" #cvenues = self.foursquare_client.venues.search(params=params) if venues is None or 'venues' not in venues.keys() or len( venues['venues']) == 0: reply = 'Sorry, I couldn\'t find any doctors near you.' else: reply = 'Here is what I found:\n' for venue in venues['venues']: if len(reply) > 0: reply = reply + '\n' reply = reply + '* ' + venue['name'] return reply
def search(position, query, radius): if not LEBOWSKI_MODE_TEST: client = Foursquare( client_id=FOURSQUARE_CONFIG['client_id'], client_secret=FOURSQUARE_CONFIG['client_secret'], redirect_uri=FOURSQUARE_CONFIG['redirect_uri'], version='20120609', ) params = { 'll': ('%s,%s' % (position['latitude'], position['longitude'])), 'categoryId': '4d4b7105d754a06378d81259', 'limit': 10, } if position.get('accuracy'): params['llAcc'] = position['accuracy'] if radius: params['radius'] = radius if query: params['query'] = query.encode('utf8') response = client.venues.search(params) else: response = {'venues':shelve.open('generated_place.shelve')['venues']} return response
def __init__(self): self.client = Foursquare(client_id=FS_CLIENT_ID, client_secret=FS_CLIENT_SECRET)
def __init__(self, config): self.config = config self.client = Foursquare(client_id=config.FoursquareClientId, client_secret=config.FoursquareClientSecret)
def __init__(self, access_token): ''' Initiate the connector ''' self.connector = Foursquare(access_token=access_token, version='20140116')
from foursquare import Foursquare client = Foursquare(client_id='KEE332SEACBCB00LBQ5QBS5OQYPHYBGBO2LEK14RFUJOGHS0', client_secret='SJ4L5E5RDMHSPA0EZNH0RS5QTEK0DMDGV5XI2TGCCASBMTBO') # Build the authorization url for your app auth_uri = client.oauth.auth_url() rooftops = client.users()
from factual import Factual from foursquare import Foursquare from googleplaces import GooglePlaces from yelp.client import Client from yelp.oauth1_authenticator import Oauth1Authenticator from app.yelp3 import Yelp3Client with io.open('keys.local.json') as cred: creds = json.load(cred) _yelpCreds = creds["yelp"] _auth = Oauth1Authenticator(**_yelpCreds) yelpClient = Client(_auth) _factualCreds = creds["factual"] factualClient = Factual(_factualCreds["key"], _factualCreds["secret"]) _foursquareCreds = creds["foursquare"] foursquareClient = Foursquare(_foursquareCreds["client_id"], _foursquareCreds["client_secret"]) googleapikey = creds["googleapikey"] gplacesClient = GooglePlaces(googleapikey) eventfulkey = creds["eventfulkey"] tripadvisorkey = creds["tripadvisorkey"] _yelp3Creds = creds["yelp3"] yelp3Client = Yelp3Client(_yelp3Creds["app_id"], _yelp3Creds["app_secret"]) yelp3Client.refreshAccessToken()
class FoursquareAPI(object): def __init__(self, access_token=None): self.logger = get_logger(__name__) self.fsq = Foursquare( client_id=FOURSQUARE_CLIENT_ID, client_secret=FOURSQUARE_CLIENT_SECRET, redirect_uri=LOGIN_REDIRECT_URI ) if access_token is not None: self.set_token(access_token) self.cache = Cache() # TODO: разобраться, в чем дело # def auth(self, access_code): # access_token = self.fsq.oauth.get_token(access_code) # self.fsq.set_access_token(access_token) def auth(self, access_code): resp = requests.get( 'https://foursquare.com/oauth2/access_token', params={ 'client_id': FOURSQUARE_CLIENT_ID, 'client_secret': FOURSQUARE_CLIENT_SECRET, 'grant_type': 'authorization_code', 'redirect_uri': LOGIN_REDIRECT_URI, 'code': access_code, } ).json() self.logger.debug(resp) access_token = resp['access_token'] self.set_token(access_token) return access_token def set_token(self, access_token): self.fsq.set_access_token(access_token) return self @property def auth_url(self): return self.fsq.oauth.auth_url() def get_current_user(self): json_response = self.fsq.users() return User(json_user=json_response['user']) def search(self, search_term, categories, per_category_limit): bounds = Rect.rect_with_center_and_halfsize( MOSCOW_CENTER, MOSCOW_RADIUS ) self.logger.debug(u'API::search \'{}\' with bounds {}'.format( search_term, bounds )) return self.fsq.venues.search(params={ 'intent': SEARCH_INTENT, 'sw': bounds.sw, 'ne': bounds.ne, 'query': search_term.encode('UTF-8'), 'limit': per_category_limit, 'categoryId': categories, }) def get_categories_filter(self): KEY = '.'.join((__name__, self.__class__.__name__, 'categories_filter')) if self.cache.exists(KEY): return self.cache.get(KEY) self.logger.debug('API::Categories') categories = Category.list_from_json(self.fsq.venues.categories()) result = ','.join((x['id'] for x in categories)) self.cache.put(KEY, result, CATEGORIES_LIST_CACHE_TIMEOUT) return result
class provider(basicProvider): ''' This class is used to: 1. Make the connection to the Foursquare API 2. Get user's Photos 3. Get OPENi album Photos 4. Post Photos to OPENi album ''' def __init__(self, access_token): ''' Initiate the connector ''' self.connector = Foursquare(access_token=access_token, version='20140116') # region Media API # As described here: http://redmine.openi-ict.eu/projects/openi/wiki/Media_API # region Photo Object # As described here: http://redmine.openi-ict.eu/projects/openi/wiki/Photo_Mapping def get_user(self, data): return self.connector.users() def get_a_photo(self, data): ''' GET API_PATH/[PHOTO_ID] ''' # /media/media-id (ie media/628147512937366504_917877895) raw_data = self.connector.media(data['media_id']) response = { 'meta': { 'total_count': 1, 'next': None }, 'data': [self.format_photo_response( raw_data.id, self.check_if_exists(raw_data, 'type', 'image'), 'openi', raw_data.link, raw_data.user.id, raw_data.user.username, raw_data.user.website, raw_data.caption.text, raw_data.link, self.defJsonRes, self.check_if_exists(raw_data, 'location'), raw_data.created_time, self.defJsonRes, self.check_if_exists(raw_data, 'tags'), self.defJsonRes, self.defJsonRes )] } return response def get_all_photos_for_account(self, data): ''' GET API_PATH/[ACCOUNT_ID]/photos ''' # /users/user-id (ie users/917877895) raw_datas, next = self.connector.user_recent_media(data['account_id']) response = { 'meta': { 'total_count': len(raw_datas), 'next': next }, 'data' : [] } for raw_data in raw_datas: response['data'].append(self.format_photo_response( raw_data.id, self.check_if_exists(raw_data, 'type', 'image'), 'openi', raw_data.link, raw_data.user.id, raw_data.user.username, raw_data.user.website, raw_data.caption.text, raw_data.link, self.defJsonRes, self.check_if_exists(raw_data, 'location'), raw_data.created_time, self.defJsonRes, self.check_if_exists(raw_data, 'tags'), self.defJsonRes, self.defJsonRes )) return response # region Connections def get_photo_comments(self, data): ''' GET API_PATH/[PHOTO_ID]/comments ''' # /media/media-id/comments (ie media/628147512937366504_917877895/comments) raw_datas = self.connector.media_comments(data['media_id']) response = { 'meta': { 'total_count': len(raw_datas['data']) }, 'data' : [] } for raw_data in raw_datas['data']: response['data'].append(self.format_comment_response( raw_data['id'], 'Photo Comment', 'openi', defJsonRes, raw_data['from']['id'], raw_data['from']['username'], defJsonRes, raw_data['created_time'], defJsonRes, defJsonRes, raw_data['text'], defJsonRes )) return response def post_comment(self, data): ''' POST API_PATH/[PHOTO_ID]/comments ''' # /media/media-id/comments (ie media/628147512937366504_917877895/comments) # 'error_message': 'Please visit http://bit.ly/instacomments for commenting access' Please email apidevelopers[at]instagram.com for access. return defaultMethodResponse def delete_comment(self, data): ''' DELETE API_PATH/[COMMENT_ID] ''' # /media/media-id/comments/comment-id (ie media/628147512937366504_917877895/comments/628902539272471262) response = self.connector.delete_comment(data['media_id'], data['comment_id']) return response def like_a_photo(self, data): ''' POST API_PATH/[PHOTO_ID]/likes ''' # /media/media-id/likes (ie media/628147512937366504_917877895/likes) response = self.connector.like_media(data['media_id']) return response def get_photo_likes(self, data): ''' GET API_PATH/[PHOTO_ID]/likes ''' # /media/media-id/likes (ie media/628147512937366504_917877895/likes) raw_datas = self.connector.media_likes(data['media_id']) response = { 'meta': { 'total_count': len(raw_datas['data']) }, 'data' : [] } for raw_data in raw_datas['data']: response['data'].append(self.format_comment_response( defJsonRes,#id 'Photo Like',#obj_type 'openi',#service defJsonRes,#url raw_data['id'],#from:id raw_data['username'],#from:username defJsonRes,#from:url defJsonRes,#time:created_time defJsonRes,#time:edited_time defJsonRes#target_id )) return 'Not supported by this service' def unlike_photo(self, data): ''' DELETE API_PATH/[PHOTO_ID]/likes ''' # /media/media-id/likes (ie media/628147512937366504_917877895/likes) response = self.connector.unlike_media(data['media_id']) return response # endregion Connections # endregion Photo Object # endregion Media API # region Location API # As described here: http://redmine.openi-ict.eu/projects/openi/wiki/Location_API # region Event Object # As described here: http://redmine.openi-ict.eu/projects/openi/wiki/Event_Mapping def get_an_event(self, data): """ GET API_PATH/[EVENT_ID] """ response = self.connector.Events(data['event_id']) return defaultMethodResponse def get_all_events_for_account(self, data): """ GET API_PATH/[VENUE_ID]/events """ response = self.connector.venues.events(data['venue_id']) return defaultMethodResponse def post_event_to_account(self, data): """ POST API_PATH/[ACCOUNT_ID]/events """ return defaultMethodResponse def post_event_to_aggregation(self, data): """ POST API_PATH/[AGGREGATION_ID]/events """ return defaultMethodResponse def edit_an_event(self, data): """ PUT API_PATH/[EVENT_ID] """ return defaultMethodResponse def delete_an_event(self, data): """ DELETE API_PATH/[EVENT_ID] """ return defaultMethodResponse # region Connections def get_event_comments(self, data): """ GET API_PATH/[EVENT_ID]/comments """ return defaultMethodResponse def post_event_comment(self, data): """ POST API_PATH/[EVENT_ID]/comments """ return defaultMethodResponse def delete_event_comment(self, data): """ DELETE API_PATH/[COMMENT_ID] """ return defaultMethodResponse def edit_event_comment(self, data): """ PUT API_PATH/[COMMENT_ID] """ return defaultMethodResponse def like_an_event(self, data): """ POST API_PATH/[EVENT_ID]/likes """ return defaultMethodResponse def get_event_likes(self, data): """ GET API_PATH/[EVENT_ID]/likes """ return defaultMethodResponse def unlike_event(self, data): """ DELETE API_PATH/[EVENT_ID]/likes """ return defaultMethodResponse def dislike_event(self, data): """ POST API_PATH/[EVENT_ID]/dislikes """ return defaultMethodResponse def get_event_dislikes(self, data): """ GET API_PATH/[EVENT_ID]/dislikes """ return defaultMethodResponse def delete_event_dislikes(self, data): """ DELETE API_PATH/[EVENT_ID]/dislikes """ return defaultMethodResponse # endregion Connections # endregion Event Object # endregion Location API
def get_pix(): fsq = Foursquare(client_id=keys.FOURSQUARE_CLIENT_ID, client_secret=keys.FOURSQUARE_CLIENT_SECRET, version=keys.FOURSQUARE_VERSION) u = 'https://api.parse.com/1/classes/Place' places_req = requests.get(u, data={ 'limit': 500 }, headers={ "X-Parse-Application-Id": keys.PARSE_APP_ID, "X-Parse-REST-API-Key": keys.PARSE_REST_KEY }) places = places_req.json().get('results', []) for place in places: print 'Obteniendo fotos para >> %s <<' % place.get('name') sq_id = place.get('sq_id') place_parse_id = place.get('objectId') pix_objects = [] if sq_id: pix = fsq.venues_pix(sq_id) pix_len = len(pix) # for pic in pix: for i in xrange(0, 7): if i >= pix_len: break pic = pix[i] if pic.get('visibility') == 'public': dimen = "%sx%s" % (pic.get('height'), pic.get('width')) url = "%s%s%s" % (pic.get('prefix'), dimen, pic.get('suffix')) pic_request = requests.get(url) upload_url = 'https://api.parse.com/1/files/' + pic.get('suffix')[1:] upload_request = requests.post(upload_url, data=pic_request.content, headers={ "X-Parse-Application-Id": keys.PARSE_APP_ID, "X-Parse-REST-API-Key": keys.PARSE_REST_KEY, 'Content-type': 'image/jpeg' }) uploaded_filename = upload_request.json().get('name') if not uploaded_filename: print upload_request.json() continue pic_parse_url = 'https://api.parse.com/1/classes/Pic' pic_parse_request = requests.post(pic_parse_url, data=json.dumps({ 'image': { '__type': 'File', 'name': uploaded_filename } }), headers={ "X-Parse-Application-Id": keys.PARSE_APP_ID, "X-Parse-REST-API-Key": keys.PARSE_REST_KEY, }) pic_objectId = pic_parse_request.json().get('objectId') if pic_objectId: pix_objects.append({ '__type': 'Pointer', 'className': 'Pic', 'objectId': pic_objectId }) else: print "\tNo hay fotos" continue if pix_objects: print '\tActualizando fotos' place_parse_url = 'https://api.parse.com/1/classes/Place/' + place_parse_id place_pix_request = requests.put(place_parse_url, data=json.dumps({ 'pix': {'__op': 'AddRelation', 'objects': pix_objects} }), headers={ "X-Parse-Application-Id": keys.PARSE_APP_ID, "X-Parse-REST-API-Key": keys.PARSE_REST_KEY, }) if place_pix_request.json().get('updatedAt'): print '\t\tActualizado.', "((%s))" % place_parse_id, '\n\n\n'
def __init__(self, client_id: str, client_secret: str): self.fq = Foursquare(client_id=client_id, client_secret=client_secret)
def login(): client = Foursquare(access_token=config['foursquare/access_token']) return client
def __init__(self): self.db_context = None self.client = Foursquare( client_id='4BCP14BAZCUWOEOBF5KEDFJJHSMY1MYS1FDQIFM45OQUHBFZ', client_secret='SY2LZONNB0PMHTYKSZZGUKZVSUIQMQUTB4IYBR02UUAO5BRZ')
def makeClient(): return Foursquare( client_id="3GZG0BE3SQSWRKGCXXSEJD4FM2TWGXTQOFQUWOKCQ3ZILXEP", client_secret="EXTDHANAPBAR3PDAGJU2DLLZFJPPH1KZYESMY00LXZCVTEBW", redirect_uri=base_url + "/auth2")
def checkins(access_token: str) -> Iterator[Any]: client = Foursquare(access_token=access_token) return client.users.all_checkins()