当前位置: 首页>>代码示例>>Python>>正文


Python factual.Factual类代码示例

本文整理汇总了Python中factual.Factual的典型用法代码示例。如果您正苦于以下问题:Python Factual类的具体用法?Python Factual怎么用?Python Factual使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Factual类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: search

def search(name):
    f = Factual(FACTUAL_KEY, FACTUAL_SECRET)
    table = f.table('restaurants-us')
    
    result = table.search(name)
    #print result.data()[0]
    return result.data()[0]
开发者ID:dkurk,项目名称:SoftDev-Projects,代码行数:7,代码来源:factual-proof.py

示例2: main

def main():
    factual = Factual(KEY, SECRET)

    table = factual.table('places-us')
    lim = 400
    
    q = table.filters({"$and":[{'locality':{'$in':['los angeles', 'boston', 'rawlins']}}, {'name': {'$blank': False}}, {'locality': {'$blank': False}}, {'latitude': {'$blank': False}}, {'longitude': {'$blank': False}},{'factual_id': {'$blank': False}}]}).limit(lim).sort('$random_133').select("name,locality,latitude,longitude,factual_id")

    print '{ "type": "FeatureCollection","features": ['

    for count in range(0,lim):

        lat = q.data()[count][u'latitude']
        name = q.data()[count][u'name']
        lng = q.data()[count][u'longitude']
        fid = q.data()[count][u'factual_id']
        locality = q.data()[count][u'locality']

        coor = '"coordinates":' + '[' + str(lng) + ',' + str(lat) +']},'

        pop_den = dstk.coordinates2statistics((lat,lng))[0]['statistics']['population_density']['value']
        #pop_den sometimes returns value even when in mountain or ocean. pop_us remedies this issue but is limited to US. 
        pop_us = dstk.coordinates2statistics((lat,lng))[0]['statistics']['us_population']['value']
        landCover = dstk.coordinates2statistics((lat,lng))[0]['statistics']['land_cover']['value']
        
        typFeat = '{ "type": "Feature",'
        geo = '"geometry": {"type": "Point",' + coor
        prop = '"properties": {"name": "' + name + '", "locality":"' + locality + '", "factual_id": "' + fid + '", "pop_density": "' + str(pop_den) + '", "us_pop": "' + str(pop_us) + '", "enviro": "' + landCover + '"}}'
        
        if count == lim-1:
            print typFeat + geo + prop
        else:
            print typFeat + geo + prop + ","

    print ']}'
开发者ID:nayeon-factual,项目名称:MapVisual,代码行数:35,代码来源:factual_project1.py

示例3: look_up_upc

def look_up_upc(upc):
    factual = Factual("1psULPx7BQfmamX3bnkOnR7NWkcPRKcjnSvazvXF", "Eu8sIGOyXIPrq3jHAudGjkPea4v5v813jJcxOOTW")

    q = factual.table("products-cpg").filters({"upc": "611269991000"})

    result = q.data()[0]
    return "{brand} - {product_name}".format(**result)
开发者ID:jachin,项目名称:bom_data_viz,代码行数:7,代码来源:upc_lookup.py

示例4: handle

    def handle(self, *args, **options):
        factual = Factual(KEY, SECRET)
        restaurants_table = factual.table('restaurants-us')

        # Get all restaurants from New York
        # {"$and":[{"country":{"$eq":"US"}},{"region":{"$eq":"NY"}}]}
        query = restaurants_table.filters({'$and':[{'region':{'$eq':"NY"}}]}).include_count(True)
        total = query.total_row_count()
        cnt_requests = (total-1)/BATCH + 1
        self.stdout.write('Ready to import %s restaurants, in %s requests' % (total, cnt_requests))
        for i in range(cnt_requests):
            try:
                data = query.offset(BATCH * i).limit(BATCH).data()
            except APIException as e:
                # If you are using a free version of factual, only 500 restaurant are imported
                # you need to premium account to access the complete data
                self.stdout.write('API Error: %s' % e)
                break

            for restoData in data:
                # Get or created restaruant using factual id
                resto, created = Restaurant.objects.get_or_create(identifier=restoData.get('factual_id'))
                # Update restaurant with new values
                self.map_data_restaurant(resto, restoData)

            self.stdout.write('Successfully imported batch %s of restaurants' % i)
开发者ID:philbritton,项目名称:resto,代码行数:26,代码来源:import_restaurants.py

示例5: searchZip

def searchZip(name, zipcode):
    f = Factual(FACTUAL_KEY, FACTUAL_SECRET)
    table = f.table('restaurants-us')

    filters = table.filters({'postcode': zipcode}).limit(1)
    result = filters.search(name)
    #print result.data()[0]
    return result.data()[0]
开发者ID:dkurk,项目名称:SoftDev-Projects,代码行数:8,代码来源:factual-proof.py

示例6: search

def search(name):
    f = Factual(FACTUAL_KEY, FACTUAL_SECRET)
    table = f.table('restaurants-us')
    
    result = table.search(name)
    try:
        return result.data()[0]
    except IndexError:
        return {}
开发者ID:dkurk,项目名称:SoftDev-Projects,代码行数:9,代码来源:factual_search.py

示例7: push_product

def push_product(org_id, ean_13, quantity):
    fb = firebase.FirebaseApplication('https://feedthechildren.firebaseio.com/', None)
    exists = fb.get("/inventory/" + org_id, None, params={'print': 'pretty'}, headers={'X_FANCY_HEADER': 'VERY FANCY'})
    if exists is not None and ean_13 in exists:
        result = fb.put('/inventory/' + org_id + '/' + ean_13, 'quantity', str(int(exists[ean_13]['quantity']) + quantity), params={'print': 'pretty'}, headers={'X_FANCY_HEADER': 'VERY FANCY'})
        return str(result)
    factual = Factual('pFMeueZJQpyZnSPILemUPxzNJmathJyrxoqOnow0', 'ROHZOgzy9GwJGb9egKpzAVTYZq35iuj6f3Uu4rNu')
    nutrition = factual.table('products-cpg-nutrition').search(ean_13)
    result = fb.put('/inventory/' + org_id, ean_13, {'quantity': str(quantity), 'metadata' : nutrition.data()[0], 'reserved' : str(0)}, params={'print': 'pretty'}, headers={'X_FANCY_HEADER': 'VERY FANCY'})
    return str(result)
开发者ID:NYC2015,项目名称:team-13,代码行数:10,代码来源:app.py

示例8: searchCity

def searchCity(name,city,state):
    f = Factual(FACTUAL_KEY, FACTUAL_SECRET)
    table = f.table('restaurants-us')

    filters = table.filters({'locality': city, 'region': state}).limit(1)
    result = filters.search(name)
    try:
        return result.data()[0]
    except IndexError:
        return {}
开发者ID:dkurk,项目名称:SoftDev-Projects,代码行数:10,代码来源:factual_search.py

示例9: main

def main():
    factual = Factual(KEY, SECRET)
    
    table = factual.table('places')
    
    # q1 = table.search("sushi Santa Monica")
    # print q1.data()[1]
    # print q1.get_url()
    
    q2 = table.select("longitude,latitude,website").filters({'category_ids':{'$includes':218}, 'region': "WA", 'locality': "SEATTLE"}).limit(50)
    print q2.data()
开发者ID:alacer,项目名称:aml-investigator,代码行数:11,代码来源:WA-banks.py

示例10: new_restaurants

def new_restaurants():
    """
    This function gets restaurants for a certain zipcode and is not visible to the user.
    """
    factual = Factual(KEY, SECRET)
    table = factual.table('restaurants')
    user_geo =  session['user_geo']   
    new_restaurants = table.filters({"postcode": 20006}).limit(50)
    check_db_for_restos(new_restaurants, user_geo)

    return "Success"
开发者ID:laurenchow,项目名称:Parsley,代码行数:11,代码来源:parsley.py

示例11: main

def main():
    #print "---------------TEST OF FACTUAL API-----------------"
    f = Factual(FACTUAL_KEY, FACTUAL_SECRET)
    
    table = f.table('restaurants-us')
    
    q1 = table.search("Ichiro")
    print q1.data()[1]['name']
    #print q1.get_url()
    
    q2 = table.filters({'region': "NY"}).limit(1)
开发者ID:dkurk,项目名称:SoftDev-Projects,代码行数:11,代码来源:factual-proof.py

示例12: main

def main():
    factual = Factual(KEY, SECRET)
    
    table = factual.table('places')
    
    q1 = table.search("sushi Santa Monica")
    print q1.data()[1]
    print q1.get_url()
    
    q2 = table.filters({'category': "Food & Beverage", 'region': "CA"}).limit(1)
    print q2.data()
开发者ID:seedwithroot,项目名称:factual-python-driver,代码行数:11,代码来源:example.py

示例13: main

def main():
    factual = Factual(KEY, SECRET)
    
    table = factual.table('places')
    
    q1 = table.search("sushi Santa Monica")
    print q1.data()[1]
    print q1.get_url()
    
    q2 = table.filters({'category_ids':{'$includes':338}, 'region': "CA"}).limit(1)
    print q2.data()
开发者ID:ianawilson,项目名称:factual-python-driver,代码行数:11,代码来源:example.py

示例14: main

def main():

	factual = Factual(KEY, SECRET)

	table = factual.table('restaurants')

	q1= table.filters({"locality":"washington"})

	q2= q1.select("name, address, tel, website")


	print q2.data()
开发者ID:guerragiancarlo8,项目名称:EatSafe-DC,代码行数:12,代码来源:test.py

示例15: check_db_for_restos

def check_db_for_restos(restaurant_data, user_geo):
    """ 
    Checks database for restaurants to see if they exist as entries yet. 
    If not, adds restaurants into database.
    """

    restaurant_ids = []

    factual = Factual(KEY, SECRET)
    table = factual.table('restaurants')
 

    for restaurant in restaurant_data: 
        parsed_data = parse_restaurant_input(restaurant)
        db_entry = model.session.query(model.Restaurant).filter_by(name= parsed_data['name']).first() 
        

        if db_entry:
             restaurant_deets = db_entry.restaurant_features.get_all_data()
             if restaurant_deets:
                restaurant_ids.append(db_entry.id)
 
        else:
            new_resto = table.filters({'name':{'$bw':parsed_data['name']}})
            new_resto_data = new_resto.data() 
       
            if new_resto_data:
                new_restaurant = model.Restaurant()

                for item in new_resto_data: 
                    new_restaurant.set_from_factual(item)
                    model.session.add(new_restaurant)
            
                    new_restaurant_features = model.Restaurant_Features()
                    new_restaurant_features.restaurant = new_restaurant
                    new_restaurant_features.set_from_factual(item)

                    model.session.add(new_restaurant_features)

                    new_restaurant_categories = model.Restaurant_Category()  
                    new_restaurant_categories.restaurant_id = new_restaurant.id                  
                    new_restaurant_categories.set_from_factual(item)
                    model.session.add(new_restaurant_categories)
                    model.session.commit()

                restaurant_ids.append(new_restaurant.id) 
    
    if restaurant_ids == []:
        flash("We need a bit more information, please try some other restaurants.")
        return redirect("/restaurants")
    else: 
        return restaurant_ids
开发者ID:laurenchow,项目名称:Parsley,代码行数:52,代码来源:parsley.py


注:本文中的factual.Factual类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。