Skip to content

Instantly share code, notes, and snippets.

@dannolan
Created June 23, 2014 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dannolan/9995643c1282ae41b46c to your computer and use it in GitHub Desktop.
Save dannolan/9995643c1282ae41b46c to your computer and use it in GitHub Desktop.
gordy pls
import json
from pprint import pprint
json_data=open('formatted.json')
data = json.load(json_data)
# pprint(data['features'])
for x in data['features']:
print(x["properties"]["headline"])
json_data.close()
@GeordieGuy
Copy link

Ok so here's the thing;

import requests, json

TrafficHazardsJSON = requests.get('http://livetraffic.rta.nsw.gov.au/traffic/hazards/incident-open.json', auth=('tdx@gguy.me', 'BushDid911'))
This returns a web object

print TrafficHazardsJSON

Response [200]

The content of the object is TrafficHazardsJSON.content

print TrafficHazardsJSON.content

{"type":"FeatureCollection","rights":{"copyright":"Transport for NSW","licence":"http://livetraffic.com/#dev"},"layerName":"Incident-Open","lastPublished":1402383701814,"features":[{"type":"Feature","id":474067,"geometry":{"type":"POINT","coordinates":[151.21123,-33.87342]},"properties":{"webLinks":[],"headline":"CHANGED TRAFFIC CONDITIONS - SYDNEY CBD Park St near Hyde Park","periods":[],"specialEventClearwaysUrl":" ","speedLimit":-1,"webLinkUrl":null,"expectedDelay":" ","ended":false,"isNewIncident":false,"impactingNetwork":false,"subCategoryB":" ","arrangementAttachments":[],"isInitialReport":false,"created":1403203771191,"isMajor":false,"name":null,"subCategoryA":" ","adviceB":" ","adviceA":"Check signage","end":1405087199059,"mainCategory":"Changed traffic conditions - planned","lastUpdated":1403212149138,"otherAdvice":"Due to rail replacement buses using the area, special event clearways will be in place on both sides of Park Street between Elizabeth Street and the mid-block pedestrian crossing (Hyde Park), from Monday 7 July 2am to Friday 11 July 9pm.

Check signs before parking as vehicles left in clearways will be towed - fines and fees apply.","arrangementElements":[],"diversions":" ","additionalInfo":[" "],"roadClosureUrl":" ","webLinkName":null,"attendingGroups":[" "],"duration":" ","start":1404655200000,"displayName":"CHANGED TRAFFIC CONDITIONS Special Event Clearways","media":[],"roads":[{"conditionTendency":"","crossStreet":"Hyde Park","delay":"","impactedLanes":[],"locationQualifier":"near","mainStreet":"Park Street","quadrant":"","queueLength":0,"region":"SYD_MET","secondLocation":" ","suburb":"Sydney CBD","trafficVolume":"","ubdRef":" "}]}},{"type":"Feature","id":472899,"geometry":{"type":"POINT","coordinates":[150.89309,-34.42482]},"properties":{"webLinks":[{"linkText":"Wollongong Central","linkURL":"http://www.wollongongcentral.com.au/development"}],"headline":"CHANGED TRAFFIC CONDITIONS - WOLLONGONG Keira St between Crown St and Market St","periods":[],"specialEventClearwaysUrl":" ","speedLimit":-1,"webLinkUrl":null,"expectedDelay":" ","ended":false,"isNewIncident":false,"impactingNetwork":false,"subCategoryB":" ","arrangementAttachments":[],"isInitialReport":false,"created":1402072977240,"isMajor":false,"name":null,"subCategoryA":" ","adviceB":"Allow extra travel time","adviceA":"Check signage","end":1412085599059,"mainCategory":"Changed traffic conditions - planned","lastUpdated":1403377666120,"otherAdvice":"Keira Street between Crown Street and Market Street will close in both directions from 1 July to 30 September 2014.</b>

* Bus services on Keira Street will be affected. Affected bus routes are 1, 2, 3, 4, 6, 7, 8, 10, 887. Alternative temporary bus routes and stops will be in place. No changes to Keira Street bus timetables.

* Pedestrian access will be maintained along Keira Street to local businesses and shops.","arrangementElements":[],"diversions":"CBD road detours will be in place. Alternative routes will be signposted. Follow all signs.","additionalInfo":[" "],"roadClosureUrl":" ","webLinkName":null,"attendingGroups":[" "],"duration":" ","start":1404136800000,"displayName":"CHANGED TRAFFIC CONDITIONS - Works associated with expansion of Wollongong Central Shopping Centre","media":[],"roads":[{"conditionTendency":"","crossStreet":"Crown Street","delay":"","impactedLanes":[{"affectedDirection":"Both directions","closedLanes":" ","description":" ","extent":"Closed","numberOfLanes":" ","roadType":"Road"}],"locationQualifier":"between","mainStreet":"Keira Street","quadrant":"","queueLength":0,"region":"REG_SOUTH","secondLocation":"Market Street","suburb":"Wollongong","trafficVolume":"","ubdRef":" "}]}},{"type":"Feature","id":474423,"geometry":{"type":"POINT","coordinates":[151.83514,-32.84377]},"properties":{"webLinks":[],"headline":"ACCIDENT Truck - FULLERTON COVE Nelson Bay Rd between Coxs Lane and Fullerton Cove Rd North","periods":[],"specialEventClearwaysUrl":null,"speedLimit":-1,"webLinkUrl":null,"expectedDelay":null,"ended":false,"isNewIncident":false,"impactingNetwork":false,"subCategoryB":" ","arrangementAttachments":[],"isInitialReport":false,"created":1403575028644,"isMajor":true,"name":null,"subCategoryA":"Truck","adviceB":" ","adviceA":"Exercise caution","end":null,"mainCategory":"Accident","lastUpdated":1403579495043,"otherAdvice":"The diversion is not suitable for B-Doubles.","arrangementElements":[],"diversions":"Coxs Lane and Fullerton Cove Road.","additionalInfo":[" "],"roadClosureUrl":null,"webLinkName":null,"attendingGroups":["Emergency service(s)","RMS"],"duration":null,"start":null,"displayName":"ACCIDENT Truck","media":[],"roads":[{"conditionTendency":"","crossStreet":"Coxs Lane","delay":"","impactedLanes":[{"affectedDirection":"Both directions","closedLanes":" ","description":" ","extent":"Closed","numberOfLanes":" ","roadType":"Road"}],"locationQualifier":"between","mainStreet":"Nelson Bay Road","quadrant":"","queueLength":0,"region":"REG_NORTH","secondLocation":"Fullerton Cove Road North","suburb":"Fullerton Cove","trafficVolume":"","ubdRef":" "}]}},{"type":"Feature","id":474424,"geometry":{"type":"POINT","coordinates":[151.15936,-33.85623]},"properties":{"webLinks":[],"headline":"ACCIDENT Two cars - DRUMMOYNE Victoria Rd at Park Ave","periods":[],"specialEventClearwaysUrl":null,"speedLimit":-1,"webLinkUrl":null,"expectedDelay":null,"ended":false,"isNewIncident":false,"impactingNetwork":false,"subCategoryB":"Two cars","arrangementAttachments":[],"isInitialReport":false,"created":1403575420661,"isMajor":false,"name":null,"subCategoryA":"Car","adviceB":" ","adviceA":"Exercise caution","end":null,"mainCategory":"Accident","lastUpdated":1403579156597,"otherAdvice":" ","arrangementElements":[],"diversions":" ","additionalInfo":[" "],"roadClosureUrl":null,"webLinkName":null,"attendingGroups":["Emergency service(s)"],"duration":null,"start":null,"displayName":"ACCIDENT Two cars","media":[],"roads":[{"conditionTendency":"","crossStreet":"Park Avenue","delay":"","impactedLanes":[{"affectedDirection":"Northbound","closedLanes":"1","description":"Lane 1","extent":"Lanes closed","numberOfLanes":"3","roadType":" "}],"locationQualifier":"at","mainStreet":"Victoria Road","quadrant":"","queueLength":0,"region":"SYD_MET","secondLocation":" ","suburb":"Drummoyne","trafficVolume":"","ubdRef":" "}]}},{"type":"Feature","id":474389,"geometry":{"type":"POINT","coordinates":[150.90074,-33.76292]},"properties":{"webLinks":[],"headline":"BURST WATER MAIN - BLACKTOWN Richmond Rd at Kent St","periods":[],"specialEventClearwaysUrl":null,"speedLimit":-1,"webLinkUrl":null,"expectedDelay":null,"ended":false,"isNewIncident":false,"impactingNetwork":false,"subCategoryB":" ","arrangementAttachments":[],"isInitialReport":false,"created":1403558717608,"isMajor":false,"name":null,"subCategoryA":"Burst water main","adviceB":" ","adviceA":" ","end":null,"mainCategory":"Hazard","lastUpdated":1403578893453,"otherAdvice":" ","arrangementElements":[],"diversions":" ","additionalInfo":[" "],"roadClosureUrl":null,"webLinkName":null,"attendingGroups":["Utility company"],"duration":null,"start":null,"displayName":"BURST WATER MAIN","media":[],"roads":[{"conditionTendency":"","crossStreet":"Kent Street","delay":"Minimal","impactedLanes":[{"affectedDirection":"Eastbound","closedLanes":"1","description":"Lane 1","extent":"Lanes closed","numberOfLanes":"2","roadType":" "}],"locationQualifier":"at","mainStreet":"Richmond Road","quadrant":"","queueLength":-1,"region":"SYD_WEST","secondLocation":" ","suburb":"Blacktown","trafficVolume":" ","ubdRef":" "}]}},{"type":"Feature","id":473870,"geometry":{"type":"POINT","coordinates":[151.20712,-33.88506]},"properties":{"webLinks":[],"headline":"CHANGED TRAFFIC CONDITIONS - SURRY HILLS Chalmers St","periods":[],"specialEventClearwaysUrl":" ","speedLimit":-1,"webLinkUrl":null,"expectedDelay":" ","ended":false,"isNewIncident":false,"impactingNetwork":false,"subCategoryB":" ","arrangementAttachments":[],"isInitialReport":false,"created":1403033618711,"isMajor":false,"name":null,"subCategoryA":" ","adviceB":" ","adviceA":"Check signage","end":1405346399059,"mainCategory":"Changed traffic conditions - planned","lastUpdated":1403212166466,"otherAdvice":"Due to rail replacement buses using the area, special event clearways will be in place on the western side of Chalmers Street on:
* Saturday 28 June 2am to Monday 30 June 2am
* Monday 7 July 2am to Friday 11 July 9pm
* Saturday 12 July 2am to Monday 14 July 2am

Check signs before parking as vehicles left in clearways will be towed - fines and fees apply.

The taxi rank will be relocated to the opposite side of the road.","arrangementElements":[],"diversions":" ","additionalInfo":[" "],"roadClosureUrl":" ","webLinkName":null,"attendingGroups":[" "],"duration":" ","start":1403272800000,"displayName":"CHANGED TRAFFIC CONDITIONS Special Event Clearways","media":[],"roads":[{"conditionTendency":"","crossStreet":" ","delay":"","impactedLanes":[],"locationQualifier":"-","mainStreet":"Chalmers Street","quadrant":"","queueLength":0,"region":"SYD_MET","secondLocation":" ","suburb":"Surry Hills","trafficVolume":"","ubdRef":" "}]}},{"type":"Feature","id":474430,"geometry":{"type":"POINT","coordinates":[141.82883,-33.96403]},"properties":{"webLinks":[],"headline":"ACCIDENT - WENTWORTH Silver City Hwy at 15km North of Wentworth","periods":[],"specialEventClearwaysUrl":null,"speedLimit":-1,"webLinkUrl":null,"expectedDelay":null,"ended":false,"isNewIncident":false,"impactingNetwork":false,"subCategoryB":" ","arrangementAttachments":[],"isInitialReport":false,"created":1403577481494,"isMajor":false,"name":null,"subCategoryA":" ","adviceB":" ","adviceA":"Exercise caution","end":null,"mainCategory":"Accident","lastUpdated":1403579197391,"otherAdvice":" ","arrangementElements":[],"diversions":" ","additionalInfo":[" "],"roadClosureUrl":null,"webLinkName":null,"attendingGroups":["Emergency service(s)","RMS"],"duration":null,"start":null,"displayName":"ACCIDENT - Truck - B-triple","media":[],"roads":[{"conditionTendency":"","crossStreet":"15km North of Wentworth","delay":"","impactedLanes":[],"locationQualifier":"at","mainStreet":"Silver City Highway","quadrant":"","queueLength":0,"region":"REG_SOUTH","secondLocation":" ","suburb":"Wentworth","trafficVolume":"","ubdRef":" "}]}},{"type":"Feature","id":474431,"geometry":{"type":"POINT","coordinates":[151.05554,-33.7818]},"properties":{"webLinks":[],"headline":"HAZARD Debris - CARLINGFORD Marsden Rd at Rickard St","periods":[],"specialEventClearwaysUrl":null,"speedLimit":-1,"webLinkUrl":null,"expectedDelay":null,"ended":false,"isNewIncident":true,"impactingNetwork":false,"subCategoryB":" ","arrangementAttachments":[],"isInitialReport":false,"created":1403579119780,"isMajor":false,"name":null,"subCategoryA":"Debris","adviceB":" ","adviceA":"Exercise caution","end":null,"mainCategory":"Hazard","lastUpdated":1403579119780,"otherAdvice":" ","arrangementElements":[],"diversions":" ","additionalInfo":[" "],"roadClosureUrl":null,"webLinkName":null,"attendingGroups":["RMS"],"duration":null,"start":null,"displayName":"HAZARD Debris - Bricks","media":[],"roads":[{"conditionTendency":"","crossStreet":"Rickard Street","delay":"","impactedLanes":[{"affectedDirection":"Southbound","closedLanes":" ","description":" ","extent":"Affected","numberOfLanes":" ","roadType":" "}],"locationQualifier":"at","mainStreet":"Marsden Road","quadrant":"","queueLength":0,"region":"SYD_WEST","secondLocation":" ","suburb":"Carlingford","trafficVolume":"","ubdRef":" "}]}},{"type":"Feature","id":474420,"geometry":{"type":"POINT","coordinates":[150.92428,-33.94389]},"properties":{"webLinks":[],"headline":"TRAFFIC LIGHTS BLACKED OUT Power failure - MOOREBANK Moorebank Ave at Anzac Rd","periods":[],"specialEventClearwaysUrl":null,"speedLimit":-1,"webLinkUrl":null,"expectedDelay":null,"ended":false,"isNewIncident":false,"impactingNetwork":false,"subCategoryB":"Power failure","arrangementAttachments":[],"isInitialReport":false,"created":1403573233110,"isMajor":false,"name":null,"subCategoryA":"Lights blacked out","adviceB":" ","adviceA":"Exercise caution","end":null,"mainCategory":"Traffic signals","lastUpdated":1403579185676,"otherAdvice":"Expected to remain this way until at least 3pm","arrangementElements":[],"diversions":" ","additionalInfo":[" "],"roadClosureUrl":null,"webLinkName":null,"attendingGroups":["Utility company"],"duration":null,"start":null,"displayName":"TRAFFIC LIGHTS BLACKED OUT Power failure","media":[],"roads":[{"conditionTendency":"","crossStreet":"Anzac Road","delay":"","impactedLanes":[{"affectedDirection":"All directions","closedLanes":" ","description":" ","extent":"Affected","numberOfLanes":" ","roadType":" "}],"locationQualifier":"at","mainStreet":"Moorebank Avenue","quadrant":"","queueLength":0,"region":"SYD_SOUTH","secondLocation":" ","suburb":"Moorebank","trafficVolume":"","ubdRef":"269E13"}]}}]}

Now this isn't a JSON object, it's a Python dict, and it seems there's no longer the relationship between indexes and values?

@GeordieGuy
Copy link

Wow gist trying to parse Python as markdown is a whole other problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment