Last active 1518188251

Looks up addresses on nbnco.com.au

Steven Smith revised this gist 1518224250. Go to revision

1 file changed, 11 insertions

nbn.py

@@ -2,11 +2,13 @@
2 2 import requests # pip install requests, apt install python-requests
3 3 from time import time
4 4 from argparse import ArgumentParser
5 + from sys import exit
5 6
6 7 headers = {"Referer": "https://www.nbnco.com.au/"}
7 8
8 9 parser = ArgumentParser()
9 10 parser.add_argument("address", nargs="*")
11 + parser.add_argument("--opts", help="e.g addressDetail.techType,location.id,servingArea.serviceStatus")
10 12 args = parser.parse_args()
11 13 locations = requests.get("https://places.nbnco.net.au/places/v1/autocomplete", params={"query": args.address, "timestamp": int(time()*1000)}, headers=headers).json()
12 14 for n,location in enumerate(locations["suggestions"]):
@@ -21,6 +23,15 @@ else:
21 23 location = locations["suggestions"][int(choice)]
22 24
23 25 nbninfo = requests.get("https://places.nbnco.net.au/places/v1/details/{}".format(location["id"]), headers=headers).json()
26 + if 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
24 35 for k,v in nbninfo.items():
25 36 if type(v) is dict:
26 37 print("{}: {}".format(k,"\n\t".join("{}: {}".format(m,f) for m,f in v.items())))

Steven Smith revised this gist 1518222648. Go to revision

1 file changed, 1 insertion, 1 deletion

nbn.py

@@ -6,7 +6,7 @@ from argparse import ArgumentParser
6 6 headers = {"Referer": "https://www.nbnco.com.au/"}
7 7
8 8 parser = ArgumentParser()
9 - parser.add_argument("address")
9 + parser.add_argument("address", nargs="*")
10 10 args = parser.parse_args()
11 11 locations = requests.get("https://places.nbnco.net.au/places/v1/autocomplete", params={"query": args.address, "timestamp": int(time()*1000)}, headers=headers).json()
12 12 for n,location in enumerate(locations["suggestions"]):

Steven Smith revised this gist 1518222543. Go to revision

1 file changed, 2 insertions, 2 deletions

nbn.py

@@ -1,5 +1,5 @@
1 - #!/usr/bin/env python3
2 - import requests
1 + #!/usr/bin/env python
2 + import requests # pip install requests, apt install python-requests
3 3 from time import time
4 4 from argparse import ArgumentParser
5 5

Steven Smith revised this gist 1518222484. Go to revision

1 file changed, 28 insertions

nbn.py(file created)

@@ -0,0 +1,28 @@
1 + #!/usr/bin/env python3
2 + import requests
3 + from time import time
4 + from argparse import ArgumentParser
5 +
6 + headers = {"Referer": "https://www.nbnco.com.au/"}
7 +
8 + parser = ArgumentParser()
9 + parser.add_argument("address")
10 + args = parser.parse_args()
11 + locations = requests.get("https://places.nbnco.net.au/places/v1/autocomplete", params={"query": args.address, "timestamp": int(time()*1000)}, headers=headers).json()
12 + for n,location in enumerate(locations["suggestions"]):
13 + print("{}: {}".format(n,location["formattedAddress"]))
14 + if len(locations["suggestions"]) != 1:
15 + try:
16 + choice = raw_input("Pick a number> ")
17 + except NameError:
18 + choice = input("Pick a number> ")
19 + else:
20 + choice = 0
21 + location = locations["suggestions"][int(choice)]
22 +
23 + nbninfo = requests.get("https://places.nbnco.net.au/places/v1/details/{}".format(location["id"]), headers=headers).json()
24 + for k,v in nbninfo.items():
25 + if type(v) is dict:
26 + print("{}: {}".format(k,"\n\t".join("{}: {}".format(m,f) for m,f in v.items())))
27 + else:
28 + print("{}: {}".format(k,v))
Newer Older