Skip to content

Instantly share code, notes, and snippets.

@hannorein
Created May 14, 2014 22:08
Show Gist options
  • Save hannorein/2a069763cf114f66641c to your computer and use it in GitHub Desktop.
Save hannorein/2a069763cf114f66641c to your computer and use it in GitHub Desktop.
Yes, it's that simple. Querying the Open Exoplanet Catalogue.
#!/usr/bin/python
import xml.etree.ElementTree as ET, urllib, gzip, io
url = "https://github.com/OpenExoplanetCatalogue/oec_gzip/raw/master/systems.xml.gz"
oec = ET.parse(gzip.GzipFile(fileobj=io.BytesIO(urllib.urlopen(url).read())))
# Output mass and radius of all planets
for planet in oec.findall(".//planet"):
print [planet.findtext("mass"), planet.findtext("radius")]
# Find all circumbinary planets
for planet in oec.findall(".//binary/planet"):
print planet.findtext("name")
# Output distance to planetary system (in pc, if known) and number of planets in system
for system in oec.findall(".//system"):
print system.findtext("distance"), len(system.findall(".//planet"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment