Skip to content

Instantly share code, notes, and snippets.

@monsieurp
Last active September 26, 2015 10:15
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 monsieurp/1a5c461e490aa8e43a2a to your computer and use it in GitHub Desktop.
Save monsieurp/1a5c461e490aa8e43a2a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2, random
from xml.etree import ElementTree
# Turn an XML document into a string.
def fetch_document(my_url):
return [l.strip() for l in urllib2.urlopen(my_url).readlines()]
def main():
# Get the list of herds.
url = 'https://api.gentoo.org/packages/herds.xml'
# Fetch the XML document.
document_as_list = fetch_document(url)
# Turn it into a list.
document_as_string = '\n'.join(document_as_list)
# Parse the mother fucker.
tree = ElementTree.fromstring(document_as_string)
# We're only interested in the "herd" nodes.
herds = tree.findall('herd')
python_herd = []
# Walk them.
for herd in herds:
# Get all children.
children = herd.getchildren()
# The 1st child contains the herd name.
first_child = children[0]
# Is it equal to 'python' ?
if first_child.tag == 'name' and first_child.text == 'python':
# Walk the list of maintainers.
for child in children[3::]:
# And fetch their email address.
python_herd.append(child.getchildren()[0].text)
# Shuffle that list around a bit (only 50 times :p).
for r in range(0, 50):
random.shuffle(python_herd)
# Vote for the lead!
lead = random.randint(0, len(python_herd))
# Tada!
print(python_herd[lead])
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment