nbn.py
· 1.1 KiB · Python
Raw
#!/usr/bin/env python
import requests # pip install requests, apt install python-requests
from time import time
from argparse import ArgumentParser
headers = {"Referer": "https://www.nbnco.com.au/"}
parser = ArgumentParser()
parser.add_argument("address")
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()
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))
| 1 | #!/usr/bin/env python |
| 2 | import requests # pip install requests, apt install python-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)) |