Last active
March 9, 2016 07:01
-
-
Save kenguish/eab115b9b6127b2bedae to your computer and use it in GitHub Desktop.
data.gov.hk Address Lookup Service Python Helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
''' | |
Valid language: en, zh-Hant | |
''' | |
def address_check( address, language="en" ): | |
if language not in ['en', 'zh-Hant']: | |
raise ValueError('language is not specified correctly. Either in \'en\' or \'zh-Hant\'') | |
headers = { | |
'User-Agent': 'Mozilla/5.0 (Linux; Android 5.1; E5363 Build/27.2.B.0.155) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.95 Mobile Safari/537.36', | |
'Accept' : 'application/json', | |
'Accept-Language' : language | |
} | |
ssl_url = "https://www.als.ogcio.gov.hk/lookup?q=" | |
url = "%s%s" % (ssl_url,address) | |
r = requests.get( url, headers=headers ) | |
if r.status_code == 200: | |
return r.json() | |
else: | |
return None | |
if __name__ == "__main__": | |
address_check( "IFC 2") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment