示例#1
0
    def test_search_no_api_key(self):
        client = ApixuClient()
        with self.assertRaises(ApixuException) as cm:
            client.search()

        self.assertEqual(cm.exception.code, errors.API_KEY_NOT_PROVIDED)
示例#2
0
    def test_search():
        api_key = os.environ['APIXUKEY']
        client = ApixuClient(api_key)

        history = client.search(q='London')
        validate(history, schema.read("search.json"))
示例#3
0
    def test_search_invalid_api_key(self):
        client = ApixuClient('INVALID_KEY')
        with self.assertRaises(ApixuException) as cm:
            client.search()

        self.assertEqual(cm.exception.code, errors.API_KEY_INVALID)
示例#4
0
import os

from apixu.client import ApixuClient

api_key = os.environ['APIXUKEY']
client = ApixuClient(api_key)

search = client.search(q='London')

for location in search:
    print(location['id'])
    print(location['name'])
    print(location['region'])
    print('\n')
'''
[  
   {  
      "id":2801268,
      "name":"London, City of London, Greater London, United Kingdom",
      "region":"City of London, Greater London",
      "country":"United Kingdom",
      "lat":51.52,
      "lon":-0.11,
      "url":"london-city-of-london-greater-london-united-kingdom"
   }
]
'''