import json
import urllib2


username = 'DEVELOPX'
password = 'TEST1234'
url1 = 'http://legallandconverter.com/'
url2 = 'http://legallandconverter.com/cgi/shopfps.cgi?cmd=forward&unit=A&section=69&latdeg=62&latmin=30&longdeg=114&longmin=15&output=geojson'

# INSTALL PASSWORD AUTHENTICATION

auth = urllib2.HTTPBasicAuthHandler()
auth.add_password("Administrator",url1,username,password)
opener = urllib2.build_opener(auth)
urllib2.install_opener(opener)

# GET DATA FROM MOTHERSHIP

feed = urllib2.urlopen(url2)

data = json.load(feed)


# RETRIEVE AND PRINT DATA OUT OF THE JSON BLOB

# Conversion Status

print data['success']
print

# Text Data

print data['features'][0]['properties']['TITLE']
print data['features'][0]['properties']['LATITUDE']
print data['features'][0]['properties']['LONGITUDE']

print data['features'][0]['properties']['MGRS']
print data['features'][0]['properties']['UTM']
print data['features'][0]['properties']['NTS']

print data['features'][0]['properties']['PROVINCE']
print data['features'][0]['properties']['COUNTY']

print data['features'][0]['properties']['GRIDNAME']
print data['features'][0]['properties']['REGIONNAME']

print data['features'][0]['properties']['ZOOM']

print

# Polygon Coordinate Pairs

print data['features'][0]['geometry']['coordinates'][0][0]
print data['features'][0]['geometry']['coordinates'][0][1]
print data['features'][0]['geometry']['coordinates'][0][2]
print data['features'][0]['geometry']['coordinates'][0][3]
print data['features'][0]['geometry']['coordinates'][0][4]
print

# Print Longitude and Latitude Seperately

print data['features'][0]['geometry']['coordinates'][0][0][0]
print data['features'][0]['geometry']['coordinates'][0][0][1]

print


