本文整理汇总了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]
示例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 ']}'
示例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)
示例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)
示例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]
示例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 {}
示例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)
示例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 {}
示例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()
示例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()
示例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)
示例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()
示例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"
示例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()
示例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