Last active
February 10, 2018 00:57
-
-
Save blha303/3752dbcbbe52aaeecf2605ee84337885 to your computer and use it in GitHub Desktop.
Looks up addresses on nbnco.com.au
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
#!/usr/bin/env python | |
import requests # pip install requests, apt install python-requests | |
from time import time | |
from argparse import ArgumentParser | |
from sys import exit | |
headers = {"Referer": "https://www.nbnco.com.au/"} | |
parser = ArgumentParser() | |
parser.add_argument("address", nargs="*") | |
parser.add_argument("--opts", help="e.g addressDetail.techType,location.id,servingArea.serviceStatus") | |
args = parser.parse_args() | |
locations = requests.get("https://places.nbnco.net.au/places/v1/autocomplete", params={"query": args.address, "timestamp": int(time()*1000)}, headers=headers).json() | |
for n,location in enumerate(locations["suggestions"]): | |
print("{}: {}".format(n,location["formattedAddress"])) | |
if len(locations["suggestions"]) != 1: | |
try: | |
choice = raw_input("Pick a number> ") | |
except NameError: | |
choice = input("Pick a number> ") | |
else: | |
choice = 0 | |
location = locations["suggestions"][int(choice)] | |
nbninfo = requests.get("https://places.nbnco.net.au/places/v1/details/{}".format(location["id"]), headers=headers).json() | |
if args.opts: | |
info = {} | |
for opt in args.opts.split(","): | |
_opt = opt | |
while "." in opt: | |
c,opt = opt.split(".",1) | |
current = nbninfo[c] | |
info[_opt] = current[opt] | |
nbninfo = info | |
for k,v in nbninfo.items(): | |
if type(v) is dict: | |
print("{}: {}".format(k,"\n\t".join("{}: {}".format(m,f) for m,f in v.items()))) | |
else: | |
print("{}: {}".format(k,v)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment