Last active 1518188251

Looks up addresses on nbnco.com.au

nbn.py Raw
1#!/usr/bin/env python
2import requests # pip install requests, apt install python-requests
3from time import time
4from argparse import ArgumentParser
5from sys import exit
6
7headers = {"Referer": "https://www.nbnco.com.au/"}
8
9parser = ArgumentParser()
10parser.add_argument("address", nargs="*")
11parser.add_argument("--opts", help="e.g addressDetail.techType,location.id,servingArea.serviceStatus")
12args = parser.parse_args()
13locations = requests.get("https://places.nbnco.net.au/places/v1/autocomplete", params={"query": args.address, "timestamp": int(time()*1000)}, headers=headers).json()
14for n,location in enumerate(locations["suggestions"]):
15 print("{}: {}".format(n,location["formattedAddress"]))
16if len(locations["suggestions"]) != 1:
17 try:
18 choice = raw_input("Pick a number> ")
19 except NameError:
20 choice = input("Pick a number> ")
21else:
22 choice = 0
23location = locations["suggestions"][int(choice)]
24
25nbninfo = requests.get("https://places.nbnco.net.au/places/v1/details/{}".format(location["id"]), headers=headers).json()
26if args.opts:
27 info = {}
28 for opt in args.opts.split(","):
29 _opt = opt
30 while "." in opt:
31 c,opt = opt.split(".",1)
32 current = nbninfo[c]
33 info[_opt] = current[opt]
34 nbninfo = info
35for k,v in nbninfo.items():
36 if type(v) is dict:
37 print("{}: {}".format(k,"\n\t".join("{}: {}".format(m,f) for m,f in v.items())))
38 else:
39 print("{}: {}".format(k,v))