[Planetlab-users] Getting geographical data on nodes

Emil Sit sit at MIT.EDU
Thu Feb 21 14:57:23 EST 2008


On Thu, 21 February 2008 at 11:17 (-0800), Sedayao, Jeff wrote:
> geographical areas" but I don't see a queryable hook for that.  If
> anyone can help with a pointer at getting this data out, I'd appreciate
> it.

#!/usr/bin/env python
#
import xml.dom.minidom
from urllib import urlopen
# Requires geopy from http://exogen.case.edu/projects/geopy/
from geopy import distance

# Print things that are range miles from the center.
center = (32.877, -117.237)
range  = 100

fh = urlopen("https://www.planet-lab.org/xml/sites.xml")
sites = xml.dom.minidom.parse (fh)

assert sites.childNodes[0].nodeType == sites.childNodes[0].DOCUMENT_TYPE_NODE
assert sites.childNodes[1].nodeType == sites.childNodes[1].ELEMENT_NODE
assert sites.childNodes[1].nodeName == u"PLANETLAB_SITES"

for e in sites.childNodes[1].childNodes:
    if e.nodeType != e.ELEMENT_NODE and e.nodeName != u"SITE":
	continue
    try:
	lat = float (e.getAttribute ("LATITUDE"))
	long = float (e.getAttribute ("LONGITUDE"))
    except:
	continue

    # Filter for those sites that are in the Lower48-ish.
    if lat < 23 or lat > 48:
	continue
    if long < -135 or long > -65:
	continue
    a = (lat, long)

    d = distance.distance (center, a).miles

    for h in e.childNodes:
	if h.nodeType != h.ELEMENT_NODE and h.nodeName != u"HOST":
	    continue
	name = h.getAttribute("NAME").lower ()
	status = h.getAttribute("STATUS").lower ()
	if status != "production":
	    continue
	if name.find ("dsl") >= 0:
	    continue

	if d < range:
	    print name


-- 
Emil Sit / http://www.emilsit.net/



More information about the Users mailing list