本文整理匯總了Python中factual.Factual.raw_write方法的典型用法代碼示例。如果您正苦於以下問題:Python Factual.raw_write方法的具體用法?Python Factual.raw_write怎麽用?Python Factual.raw_write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類factual.Factual
的用法示例。
在下文中一共展示了Factual.raw_write方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: FactualAPITestSuite
# 需要導入模塊: from factual import Factual [as 別名]
# 或者: from factual.Factual import raw_write [as 別名]
#.........這裏部分代碼省略.........
def test_in(self):
q = self.places.filters({"locality":{"$in":["Santa Monica","Los Angeles","Culver City"]}})
row = q.data()[0]
self.assertIn(row['locality'], ["Santa Monica","Los Angeles","Culver City"])
def test_and(self):
q = self.places.filters({"$and":[{"country":"US"},{"website":{"$blank":False}}]})
row = q.data()[0]
self.assertEqual('US', row['country'].upper())
self.assertRegexpMatches(row['website'], 'http')
def test_includes(self):
q = self.places.filters({'category_ids':{'$includes':10}})
rows = q.data()
for row in rows:
self.assertIn(10, row['category_ids'])
def test_raw_read(self):
# filters here is url encoded {"name":"Starbucks"}
response = self.factual.raw_read('t/places/read', 'limit=15&filters=%7B%22name%22%3A%22Starbucks%22%7D')
payload = json.loads(response)
data = payload['response']['data']
self.assertEqual(15, payload['response']['included_rows'])
self.assertTrue(all(row['name'] == 'Starbucks' for row in data))
def test_raw_read_with_map(self):
response = self.factual.raw_read('t/places/read', {'limit':15,'filters':{"name":"Starbucks"}})
payload = json.loads(response)
data = payload['response']['data']
self.assertEqual(15, payload['response']['included_rows'])
self.assertTrue(all(row['name'] == 'Starbucks' for row in data))
def test_raw_write(self):
uuid = '1007462b-dd79-44f5-a69f-e0b6041fa8bd'
params = {'problem':'other','user':'python_driver_tester','debug':True}
response = self.factual.raw_write('t/us-sandbox/' + uuid + '/flag', params)
payload = json.loads(response)
self.assertEqual('ok', payload['status'])
def test_facets1(self):
q = self.facets.search("starbucks").select("country")
results = q.data()['country']
self.assertTrue(results['us'] > 5000)
self.assertTrue(results['ca'] > 200)
def test_facets2(self):
q = self.facets.search("starbucks").select("locality,region").filters({"country":"US"})
locality = q.data()['locality']
region = q.data()['region']
self.assertTrue(locality['chicago'] > 50)
self.assertTrue(region['tx'] > 200)
def test_facets_geo(self):
q = self.facets.select("locality").geo(circle(34.06018, -118.41835, 1000))
locality = q.data()['locality']
self.assertTrue(locality['los angeles'] > 3000)
self.assertTrue(locality['beverly hills'] > 500)
def test_geopulse(self):
geopulse = self.factual.geopulse(point(34.06021, -118.41828))
income_only = geopulse.select('income')
all_results = geopulse.data()
income_results = income_only.data()
self.assertIn('demographics', all_results)
demographics = all_results['demographics']
示例2: FactualAPITestSuite
# 需要導入模塊: from factual import Factual [as 別名]
# 或者: from factual.Factual import raw_write [as 別名]
#.........這裏部分代碼省略.........
def test_in(self):
q = self.places.filters({"locality":{"$in":["Santa Monica","Los Angeles","Culver City"]}})
row = q.data()[0]
self.assertIn(row['locality'], ["Santa Monica","Los Angeles","Culver City"])
def test_and(self):
q = self.places.filters({"$and":[{"country":"US"},{"website":{"$blank":False}}]})
row = q.data()[0]
self.assertEqual('US', row['country'].upper())
self.assertRegexpMatches(row['website'], 'http')
def test_includes(self):
q = self.places.filters({'category_ids':{'$includes':10}})
rows = q.data()
for row in rows:
self.assertIn(10, row['category_ids'])
def test_raw_read(self):
# filters here is url encoded {"name":"Starbucks"}
response = self.factual.raw_read('t/places/read', 'limit=15&filters=%7B%22name%22%3A%22Starbucks%22%7D')
payload = json.loads(response)
data = payload['response']['data']
self.assertEqual(15, payload['response']['included_rows'])
self.assertTrue(all(row['name'] == 'Starbucks' for row in data))
def test_raw_read_with_map(self):
response = self.factual.raw_read('t/places/read', {'limit':15,'filters':{"name":"Starbucks"}})
payload = json.loads(response)
data = payload['response']['data']
self.assertEqual(15, payload['response']['included_rows'])
self.assertTrue(all(row['name'] == 'Starbucks' for row in data))
def test_raw_write(self):
uuid = SANDBOX_UUID
params = {'problem':'other','user':'python_driver_tester','debug':True}
response = self.factual.raw_write('t/us-sandbox/' + uuid + '/flag', params)
payload = json.loads(response)
self.assertEqual('ok', payload['status'])
def test_facets1(self):
q = self.facets.search("starbucks").select("country")
results = q.data()['country']
self.assertTrue(results['us'] > 5000)
self.assertTrue(results['ca'] > 200)
def test_facets2(self):
q = self.facets.search("starbucks").select("locality,region").filters({"country":"US"})
locality = q.data()['locality']
region = q.data()['region']
self.assertTrue(locality['chicago'] > 50)
self.assertTrue(region['tx'] > 200)
def test_facets_geo(self):
q = self.facets.select("locality").geo(circle(34.06018, -118.41835, 1000))
locality = q.data()['locality']
self.assertTrue(locality['los angeles'] > 3000)
self.assertTrue(locality['beverly hills'] > 500)
def test_geocode(self):
geocode = self.factual.geocode(point(34.058744, -118.416937))
result = geocode.data()[0]
self.assertEqual('1999 Avenue Of The Stars', result['address'])
self.assertLess(result['$distance'], 20)
def test_submit_without_id(self):