Last active 1518188251

Looks up addresses on nbnco.com.au

Revision f457731d6adb32b3fa6de76b127fdfde2bffa60b

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
5
6headers = {"Referer": "https://www.nbnco.com.au/"}
7
8parser = ArgumentParser()
9parser.add_argument("address")
10args = parser.parse_args()
11locations = requests.get("https://places.nbnco.net.au/places/v1/autocomplete", params={"query": args.address, "timestamp": int(time()*1000)}, headers=headers).json()
12for n,location in enumerate(locations["suggestions"]):
13 print("{}: {}".format(n,location["formattedAddress"]))
14if len(locations["suggestions"]) != 1:
15 try:
16 choice = raw_input("Pick a number> ")
17 except NameError:
18 choice = input("Pick a number> ")
19else:
20 choice = 0
21location = locations["suggestions"][int(choice)]
22
23nbninfo = requests.get("https://places.nbnco.net.au/places/v1/details/{}".format(location["id"]), headers=headers).json()
24for 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))