예제 #1
0
 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
예제 #2
0
    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', '')
예제 #3
0
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)
예제 #4
0
 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
예제 #5
0
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
예제 #6
0
    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
예제 #7
0
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
예제 #8
0
    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()
예제 #9
0
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)
예제 #10
0
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)))
예제 #11
0
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
예제 #12
0
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'))
예제 #13
0
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
예제 #14
0
파일: venue.py 프로젝트: beebikun/sz2013
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
예제 #15
0
 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()

예제 #17
0
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()
예제 #18
0
파일: fs.py 프로젝트: bjacobel/bosfoodfails
 def __init__(self, config):
     self.config = config
     self.client = Foursquare(client_id=config.FoursquareClientId,
                              client_secret=config.FoursquareClientSecret)
예제 #19
0
def makeClient():
    return Foursquare(
        client_id="3GZG0BE3SQSWRKGCXXSEJD4FM2TWGXTQOFQUWOKCQ3ZILXEP",
        client_secret="EXTDHANAPBAR3PDAGJU2DLLZFJPPH1KZYESMY00LXZCVTEBW",
        redirect_uri=base_url + "/auth2")
예제 #20
0
 def __init__(self, client_id: str, client_secret: str):
     self.fq = Foursquare(client_id=client_id, client_secret=client_secret)
예제 #21
0
 def __init__(self):
     self.client = Foursquare(client_id=FS_CLIENT_ID,
                              client_secret=FS_CLIENT_SECRET)
def login():

    client = Foursquare(access_token=config['foursquare/access_token'])
    return client
예제 #23
0
 def __init__(self):
     self.db_context = None
     self.client = Foursquare(
         client_id='4BCP14BAZCUWOEOBF5KEDFJJHSMY1MYS1FDQIFM45OQUHBFZ',
         client_secret='SY2LZONNB0PMHTYKSZZGUKZVSUIQMQUTB4IYBR02UUAO5BRZ')
예제 #24
0
def checkins(access_token: str) -> Iterator[Any]:
    client = Foursquare(access_token=access_token)
    return client.users.all_checkins()