Created
May 14, 2014 22:08
-
-
Save hannorein/2a069763cf114f66641c to your computer and use it in GitHub Desktop.
Yes, it's that simple. Querying the Open Exoplanet Catalogue.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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