Get your Wu-name in six lines of Python

I recently had a need to generate screen-names for a bunch of test users. I remembered the wonderful Wu-name generator and it was too tempting to pass up.

import urllib
from lxml.html import fromstring
def get_wu_name(first_name, last_name):
    >>> get_wu_name("Jeff", "Elmore")
    'Ultra-Chronic Monstah'
    w = urllib.urlopen("",
                       urllib.urlencode({'fname':first_name, 'sname': last_name}))
    doc = fromstring(
    return [d for d in doc.iter('span') if d.get('class') == 'newname'][0].text

Okay, technically it’s more than six if you count the docstring and linewrap but still. Also, I felt like there should be a better way to do the last line, but this works well enough.


3 Responses to “Get your Wu-name in six lines of Python”

  1. 1 Lazer ₫ February 21, 2011 at 6:35 pm

    You have been lazerdong’ed.

  2. 2 Tony March 25, 2014 at 7:56 pm

    You could do something like this for the last line:

    return doc.xpath(‘//span[@class=”newname”]/text()’)[0]

  1. 1 Don’t waste your iterators! « Cliff Dyer’s Blog Trackback on August 28, 2011 at 1:40 pm

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: