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


Python Factual.flag方法代碼示例

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


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

示例1: FactualAPITestSuite

# 需要導入模塊: from factual import Factual [as 別名]
# 或者: from factual.Factual import flag [as 別名]

#.........這裏部分代碼省略.........
        # 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_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("category").geo(circle(34.06018, -118.41835, 5000))
        category = q.data()['category']
        self.assertTrue(category['shopping'] > 1000)
        self.assertTrue(category['health & medicine > physicians'] > 1000)

    def test_geopulse(self):
        geopulse = self.factual.geopulse(point(34.06021, -118.41828))
        income_only = geopulse.select('income')
        all_results = geopulse.data()[0]
        income_results = income_only.data()[0]
        self.assertIn('commercial_density', all_results)
        self.assertTrue(0 <= all_results['commercial_density'] <= 1)
        self.assertEqual(1, len(income_results))
        self.assertIn('income', income_results)

    def test_geocode(self):
        geocode = self.factual.geocode(point(34.06021, -118.41828))
        result = geocode.data()[0]
        self.assertEqual('1801 Avenue Of The Stars', result['address'])
        self.assertLess(result['$distance'], 20)

    def test_monetize(self):
        monetize = self.factual.monetize().filters({'place_locality':'Los Angeles'})
        result = monetize.data()
        self.assertGreaterEqual(len(result), 1)
        self.assertTrue(all(row['place_locality'] == 'Los Angeles' for row in result))

    def test_submit_without_id(self):
        values = {'longitude': 100}
        submit = self.factual.submit('t7RSEV', values=values).user('python_driver_tester')
        response = submit.write()
        if 'new_entity' in response:
            self.assertTrue(response['new_entity'])
        else:
            self.assertIn('status', response)
            self.assertEqual('warning', response['status'])

    def test_submit_with_id(self):
        values = {'longitude': 100}
        submit = self.factual.submit('t7RSEV', factual_id='bf6547a8-c0f3-4ada-abf8-9b831bbd5eeb', values=values).user('python_driver_tester')
        response = submit.write()
        if 'new_entity' in response:
            self.assertFalse(response['new_entity'])
        else:
            self.assertIn('status', response)
            self.assertEqual('warning', response['status'])

    def test_flag(self):
        flag = self.factual.flag('t7RSEV', 'bf6547a8-c0f3-4ada-abf8-9b831bbd5eeb').user('python_driver_tester').other().debug(True)
        response = flag.write()
        self.assertEqual('ok', response['status'])

    def test_diffs(self):
        diffs = self.factual.diffs('2EH4Pz', 1339123455775, 1339136968687).data()
        self.assertGreater(len(diffs), 0)

    def test_diffs_streaming(self):
        diff_request = self.factual.diffs('2EH4Pz', 1339123455775, 1339136968687)
        batch = diff_request.data()
        streamed = list(diff_request.stream())
        self.assertItemsEqual(batch, streamed)

    def test_match(self):
        match = self.factual.match({'name':'McDonalds','address':'10451 Santa Monica Blvd','locality':'Los Angeles','region':'CA'})
        match_id = match.get_id()
        self.assertEqual('bd886f67-9d86-40c5-9217-f7bcd53cfc0e', match_id)

    def test_multi(self):
        q1 = self.factual.table('places').filters({'postcode':'90067'})
        q2 = self.factual.facets('places').filters({'postcode':'90067'}).select('category')
        response = self.factual.multi({'query1':q1,'query2':q2})
        self.assertTrue('query1' in response and 'query2' in response)
開發者ID:mmoutenot,項目名稱:factual-python-driver,代碼行數:104,代碼來源:api_test.py

示例2: FactualAPITestSuite

# 需要導入模塊: from factual import Factual [as 別名]
# 或者: from factual.Factual import flag [as 別名]

#.........這裏部分代碼省略.........
        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']
        self.assertIn('area_statistics', demographics)
        area_statistics = demographics['area_statistics']
        self.assertIn('commercial_residential', area_statistics)
開發者ID:jgraham6,項目名稱:factual-python-driver,代碼行數:70,代碼來源:api_test.py

示例3: FactualAPITestSuite

# 需要導入模塊: from factual import Factual [as 別名]
# 或者: from factual.Factual import flag [as 別名]

#.........這裏部分代碼省略.........
        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):
        values = {'longitude': 100}
        submit = self.factual.submit('us-sandbox', values=values).user('python_driver_tester')
        response = submit.write()
開發者ID:jholkeboer,項目名稱:check-me-in,代碼行數:70,代碼來源:api_test.py


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