當前位置: 首頁>>代碼示例>>Python>>正文


Python Factual.table方法代碼示例

本文整理匯總了Python中factual.Factual.table方法的典型用法代碼示例。如果您正苦於以下問題:Python Factual.table方法的具體用法?Python Factual.table怎麽用?Python Factual.table使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在factual.Factual的用法示例。


在下文中一共展示了Factual.table方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: search

# 需要導入模塊: from factual import Factual [as 別名]
# 或者: from factual.Factual import table [as 別名]
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,代碼行數:9,代碼來源:factual-proof.py

示例2: main

# 需要導入模塊: from factual import Factual [as 別名]
# 或者: from factual.Factual import table [as 別名]
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,代碼行數:37,代碼來源:factual_project1.py

示例3: look_up_upc

# 需要導入模塊: from factual import Factual [as 別名]
# 或者: from factual.Factual import table [as 別名]
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,代碼行數:9,代碼來源:upc_lookup.py

示例4: handle

# 需要導入模塊: from factual import Factual [as 別名]
# 或者: from factual.Factual import table [as 別名]
    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,代碼行數:28,代碼來源:import_restaurants.py

示例5: searchZip

# 需要導入模塊: from factual import Factual [as 別名]
# 或者: from factual.Factual import table [as 別名]
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,代碼行數:10,代碼來源:factual-proof.py

示例6: search

# 需要導入模塊: from factual import Factual [as 別名]
# 或者: from factual.Factual import table [as 別名]
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,代碼行數:11,代碼來源:factual_search.py

示例7: push_product

# 需要導入模塊: from factual import Factual [as 別名]
# 或者: from factual.Factual import table [as 別名]
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,代碼行數:12,代碼來源:app.py

示例8: searchCity

# 需要導入模塊: from factual import Factual [as 別名]
# 或者: from factual.Factual import table [as 別名]
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,代碼行數:12,代碼來源:factual_search.py

示例9: main

# 需要導入模塊: from factual import Factual [as 別名]
# 或者: from factual.Factual import table [as 別名]
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,代碼行數:13,代碼來源:example.py

示例10: main

# 需要導入模塊: from factual import Factual [as 別名]
# 或者: from factual.Factual import table [as 別名]
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,代碼行數:13,代碼來源:WA-banks.py

示例11: main

# 需要導入模塊: from factual import Factual [as 別名]
# 或者: from factual.Factual import table [as 別名]
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,代碼行數:13,代碼來源:factual-proof.py

示例12: main

# 需要導入模塊: from factual import Factual [as 別名]
# 或者: from factual.Factual import table [as 別名]
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,代碼行數:13,代碼來源:example.py

示例13: new_restaurants

# 需要導入模塊: from factual import Factual [as 別名]
# 或者: from factual.Factual import table [as 別名]
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,代碼行數:13,代碼來源:parsley.py

示例14: main

# 需要導入模塊: from factual import Factual [as 別名]
# 或者: from factual.Factual import table [as 別名]
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,代碼行數:14,代碼來源:test.py

示例15: check_db_for_restos

# 需要導入模塊: from factual import Factual [as 別名]
# 或者: from factual.Factual import table [as 別名]
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,代碼行數:54,代碼來源:parsley.py


注:本文中的factual.Factual.table方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。