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


Python Factual.raw_write方法代码示例

本文整理汇总了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']
开发者ID:jgraham6,项目名称:factual-python-driver,代码行数:70,代码来源:api_test.py

示例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):
开发者ID:jholkeboer,项目名称:check-me-in,代码行数:70,代码来源:api_test.py


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