Job Offer: Python Ninja or Pirate!

J

jay

Etsy is an online marketplace for buying and selling all things
handmade: clothing, music, furniture,
software, jewelry, robots. We launched on June 18, 2005, and ever
since then have been empowering our
users to make a living doing what they love most.

Just a few months ago, we found a few amazingly talented ninjas and
even a few swarthy pirates. The team is doing wonderfully, and we're
hoping to add a few more adventure-loving souls to our ranks. You'll
be using python, javascript and other technologies to whip up
innovative web applications in many challenging and interesting
domains: social and community, ecommerce, search, and even software
development.

We're also in the process of redesigning and developing our web stack
to allow us to scale into outer space
while still providing a fun and productive programming environment.
You'll likely end up working on our: in-house orm, customized cherrypy
environment, jinja templates, django-like form processing library,
lucene integration, twisted-based communications protocol, or kick-ass
high-performance memcached library.

Required:
* 5+ years of web development experience
* 3+ years of writing production-level code with a dynamic language
(python, ruby, lisp, smalltalk,

OO javascript, etc)
* Strong OOP skills
* Understanding of dynamic language idioms and patterns
* Ability and willingness to pick up other languages and technologies

Desired:
* Ability to write python code idiomatically
* Lives in New York City
* Experience with javascript
* Experience with java, postgresql and/or php

Neat:
* Plays guitar hero


Challenge:
A valid response will be either a solution to the problem below, or a
link to some code of which you
are particularly proud.

Problem: In the dynamic language of your choice, write a short program
that will:
1. define a list of the following user ids 42346, 77290, 729 (you can
hardcode these, but it should
still work with more or less ids)
2. retrieve an xml document related to each user at this url "http://
api.etsy.com/feeds/xml_user_details.php?id="
3. retrieve the data contained in the city element from each xml
document
4. keep a running total of how many users are found in each city
5. display the total count of users living in each city

You can assume user ids are valid and that the url is available. The
output should look something
like:

Charlotte: 1
New York: 2

You can find out more about etsy at http://www.etsy.com or
http://blog.etsy.com/jobs/index.html
 
N

Nikos Vergas

Challenge:
A valid response will be either a solution to the problem below, or a
link to some code of which you
are particularly proud.

Problem: In the dynamic language of your choice, write a short program
that will:
1. define a list of the following user ids 42346, 77290, 729 (you can
hardcode these, but it should
still work with more or less ids)
2. retrieve an xml document related to each user at this url "http://
api.etsy.com/feeds/xml_user_details.php?id="
3. retrieve the data contained in the city element from each xml
document
4. keep a running total of how many users are found in each city
5. display the total count of users living in each city

You can assume user ids are valid and that the url is available. The
output should look something
like:

Charlotte: 1
New York: 2

i wanted to make it a one liner, but i had to import modules :(

import sys, xml, urllib

dummy = [sys.stdout.write(city + ': ' + str(num) + '\n') for city, num in
set([[(a, o.count(a)) for a in p] for o, p in [2*tuple([[city for city in
((xml.dom.minidom.parseString(urllib.urlopen('http://api.etsy.com/feeds/xml_user_details.php?id='
+ str(id)).read()).getElementsByTagName('city')[0].childNodes + [(lambda
t: (setattr(t, 'data', 'no city'),
t))(xml.dom.minidom.Text())[1]])[0].data.lower().replace(' ', ' ') for id
in [71234, 71234, 71234, 71234, 71234, 71234, 42792])]])]][0])]
 
S

Simon Forman

Challenge:
A valid response will be either a solution to the problem below, or a
link to some code of which you
are particularly proud.
Problem: In the dynamic language of your choice, write a short program
that will:
1. define a list of the following user ids 42346, 77290, 729 (you can
hardcode these, but it should
still work with more or less ids)
2. retrieve an xml document related to each user at this url "http://
api.etsy.com/feeds/xml_user_details.php?id="
3. retrieve the data contained in the city element from each xml
document
4. keep a running total of how many users are found in each city
5. display the total count of users living in each city
You can assume user ids are valid and that the url is available. The
output should look something
like:
Charlotte: 1
New York: 2

i wanted to make it a one liner, but i had to import modules :(

import sys, xml, urllib

dummy = [sys.stdout.write(city + ': ' + str(num) + '\n') for city, num in
set([[(a, o.count(a)) for a in p] for o, p in [2*tuple([[city for city in
((xml.dom.minidom.parseString(urllib.urlopen('http://api.etsy.com/feeds/xml_user_details.php?id='
+ str(id)).read()).getElementsByTagName('city')[0].childNodes + [(lambda
t: (setattr(t, 'data', 'no city'),
t))(xml.dom.minidom.Text())[1]])[0].data.lower().replace(' ', ' ') for id
in [71234, 71234, 71234, 71234, 71234, 71234, 42792])]])]][0])]


Cute, now can you make it readable? ;-)

~S
 
S

Stargaming

On Mon, 10 Dec 2007 16:10:16 +0200, Nikos Vergas wrote:

[snip]
Problem: In the dynamic language of your choice, write a short program
that will:
1. define a list of the following user ids 42346, 77290, 729 (you can
hardcode these, but it should
still work with more or less ids)
2. retrieve an xml document related to each user at this url "http://
api.etsy.com/feeds/xml_user_details.php?id="
3. retrieve the data contained in the city element from each xml
document
4. keep a running total of how many users are found in each city 5.
display the total count of users living in each city
[snip]

i wanted to make it a one liner, but i had to import modules :(

import sys, xml, urllib

dummy = [sys.stdout.write(city + ': ' + str(num) + '\n') for city, num
in set([[(a, o.count(a)) for a in p] for o, p in [2*tuple([[city for
city in
((xml.dom.minidom.parseString(urllib.urlopen('http://api.etsy.com/feeds/ xml_user_details.php?id='
+ str(id)).read()).getElementsByTagName('city')[0].childNodes + [(lambda
t: (setattr(t, 'data', 'no city'),
t))(xml.dom.minidom.Text())[1]])[0].data.lower().replace(' ', ' ') for
id in [71234, 71234, 71234, 71234, 71234, 71234, 42792])]])]][0])]

I suggest `__import__` in such cases.

Even though I do not qualify for the job, I came up with this (<wink>)
code (modified list values for demonstration, mixed together from
previous post and original task):

print '\n'.join('%s: %d'%(x,len(list(y))) for x,y in __import__
('itertools').groupby(sorted(__import__('xml').dom.minidom.parse
(__import__('urllib').urlopen('http://api.etsy.com/feeds/
xml_user_details.php?id=%d'%i)).getElementsByTagName('city')
[0].lastChild.data.title() for i in (71234, 729, 42346, 77290, 729,
729))))

I still find this rather readable, though, and there is no bad side-
effect magic! :)

Output should be:

| Chicago: 3
| Fort Lauderdale: 1
| Jersey City And South Florida: 1
| New York: 1

Cheers,
 
K

kromakey

On Mon, 10 Dec 2007 16:10:16 +0200, Nikos Vergas wrote:

[snip]
Problem: In the dynamic language of your choice, write a short program
that will:
1. define a list of the following user ids 42346, 77290, 729 (you can
hardcode these, but it should
still work with more or less ids)
2. retrieve an xml document related to each user at this url "http://
api.etsy.com/feeds/xml_user_details.php?id="
3. retrieve the data contained in the city element from each xml
document
4. keep a running total of how many users are found in each city 5.
display the total count of users living in each city
[snip]

i wanted to make it a one liner, but i had to import modules :(
import sys, xml, urllib
dummy = [sys.stdout.write(city + ': ' + str(num) + '\n') for city, num
in set([[(a, o.count(a)) for a in p] for o, p in [2*tuple([[city for
city in
((xml.dom.minidom.parseString(urllib.urlopen('http://api.etsy.com/feeds/
xml_user_details.php?id='

+ str(id)).read()).getElementsByTagName('city')[0].childNodes + [(lambda
t: (setattr(t, 'data', 'no city'),
t))(xml.dom.minidom.Text())[1]])[0].data.lower().replace(' ', ' ') for
id in [71234, 71234, 71234, 71234, 71234, 71234, 42792])]])]][0])]

I suggest `__import__` in such cases.

Even though I do not qualify for the job, I came up with this (<wink>)
code (modified list values for demonstration, mixed together from
previous post and original task):

print '\n'.join('%s: %d'%(x,len(list(y))) for x,y in __import__
('itertools').groupby(sorted(__import__('xml').dom.minidom.parse
(__import__('urllib').urlopen('http://api.etsy.com/feeds/
xml_user_details.php?id=%d'%i)).getElementsByTagName('city')
[0].lastChild.data.title() for i in (71234, 729, 42346, 77290, 729,
729))))

I still find this rather readable, though, and there is no bad side-
effect magic! :)

Output should be:

| Chicago: 3
| Fort Lauderdale: 1
| Jersey City And South Florida: 1
| New York: 1

Cheers,

A simpleton's version:

#!/usr/local/bin/python

import urllib
from elementtree import ElementTree as et

userids = [71234,729,42346,77290,729,729]
url = 'http://api.etsy.com/feeds/xml_user_details.php?id='

if __name__ == "__main__":

city = {}
for userid in userids:
feed = urllib.urlopen(url+str(userid))
tree = et.parse(feed)
for elem in tree.getiterator('city'):
if not city.has_key(elem.text):city[elem.text] = 1
else: city[elem.text] += 1
for k,v in city.items():
if not k == None:print k,':\t',v


Output:

Fort Lauderdale : 1
new york : 1
Jersey City and South Florida : 1
Chicago : 3

Cheers
 
G

George Sakkis

On Mon, 10 Dec 2007 16:10:16 +0200, Nikos Vergas wrote:

[snip]
Problem: In the dynamic language of your choice, write a short program
that will:
1. define a list of the following user ids 42346, 77290, 729 (you can
hardcode these, but it should
still work with more or less ids)
2. retrieve an xml document related to each user at this url "http://
api.etsy.com/feeds/xml_user_details.php?id="
3. retrieve the data contained in the city element from each xml
document
4. keep a running total of how many users are found in each city 5.
display the total count of users living in each city
[snip]

i wanted to make it a one liner, but i had to import modules :(
import sys, xml, urllib
dummy = [sys.stdout.write(city + ': ' + str(num) + '\n') for city, num
in set([[(a, o.count(a)) for a in p] for o, p in [2*tuple([[city for
city in
((xml.dom.minidom.parseString(urllib.urlopen('http://api.etsy.com/feeds/
xml_user_details.php?id='

+ str(id)).read()).getElementsByTagName('city')[0].childNodes + [(lambda
t: (setattr(t, 'data', 'no city'),
t))(xml.dom.minidom.Text())[1]])[0].data.lower().replace(' ', ' ') for
id in [71234, 71234, 71234, 71234, 71234, 71234, 42792])]])]][0])]

I suggest `__import__` in such cases.

Even though I do not qualify for the job, I came up with this (<wink>)
code (modified list values for demonstration, mixed together from
previous post and original task):

print '\n'.join('%s: %d'%(x,len(list(y))) for x,y in __import__
('itertools').groupby(sorted(__import__('xml').dom.minidom.parse
(__import__('urllib').urlopen('http://api.etsy.com/feeds/
xml_user_details.php?id=%d'%i)).getElementsByTagName('city')
[0].lastChild.data.title() for i in (71234, 729, 42346, 77290, 729,
729))))

I still find this rather readable, though, and there is no bad side-
effect magic! :)

Output should be:

| Chicago: 3
| Fort Lauderdale: 1
| Jersey City And South Florida: 1
| New York: 1

Alas, it's not:

AttributeError: 'module' object has no attribute 'dom'

Here's a working version, optimized for char length (one line, 241
chars):

import urllib as U,elementtree.ElementTree as
E;c=[E.parse(U.urlopen('http://api.etsy.com/feeds/xml_user_details.php?
id=%d'%u)).findtext('//city')for u in
71234,729,42346,77290,729,729];print'\n'.join('%s: %s'%
(i,c.count(i))for i in set(c))

George
 
S

Stargaming

On Mon, 10 Dec 2007 16:10:16 +0200, Nikos Vergas wrote:

[snip]
Problem: In the dynamic language of your choice, write a short
program that will:
1. define a list of the following user ids 42346, 77290, 729 (you
can
hardcode these, but it should
still work with more or less ids)
2. retrieve an xml document related to each user at this url
"http://
api.etsy.com/feeds/xml_user_details.php?id="
3. retrieve the data contained in the city element from each xml
document
4. keep a running total of how many users are found in each city 5.
display the total count of users living in each city [snip]

i wanted to make it a one liner, but i had to import modules :(
import sys, xml, urllib
dummy = [sys.stdout.write(city + ': ' + str(num) + '\n') for city,
num in set([[(a, o.count(a)) for a in p] for o, p in [2*tuple([[city
for city in
((xml.dom.minidom.parseString(urllib.urlopen('http://api.etsy.com/
feeds/

xml_user_details.php?id='
+ str(id)).read()).getElementsByTagName('city')[0].childNodes +
[(lambda t: (setattr(t, 'data', 'no city'),
t))(xml.dom.minidom.Text())[1]])[0].data.lower().replace(' ', ' ')
for id in [71234, 71234, 71234, 71234, 71234, 71234,
42792])]])]][0])]

I suggest `__import__` in such cases.

Even though I do not qualify for the job, I came up with this (<wink>)
code (modified list values for demonstration, mixed together from
previous post and original task):

print '\n'.join('%s: %d'%(x,len(list(y))) for x,y in __import__
('itertools').groupby(sorted(__import__('xml').dom.minidom.parse
(__import__('urllib').urlopen('http://api.etsy.com/feeds/
xml_user_details.php?id=%d'%i)).getElementsByTagName('city')
[0].lastChild.data.title() for i in (71234, 729, 42346, 77290, 729,
729))))

I still find this rather readable, though, and there is no bad side-
effect magic! :)

Output should be:

| Chicago: 3
| Fort Lauderdale: 1
| Jersey City And South Florida: 1
| New York: 1

Alas, it's not:

AttributeError: 'module' object has no attribute 'dom'

Here's a working version, optimized for char length (one line, 241
chars):

import urllib as U,elementtree.ElementTree as
E;c=[E.parse(U.urlopen('http://api.etsy.com/feeds/xml_user_details.php?
id=%d'%u)).findtext('//city')for u in
71234,729,42346,77290,729,729];print'\n'.join('%s: %s'%
(i,c.count(i))for i in set(c))

George

Heh, yes. I did the same error as the participant before me -- test it in
a premodified environment. A fix is easy, __import__ 'xml.dom.minidom'
instead of 'xml'. :)

;-is-cheating'ly yours,
 
B

Bruno Desthuilliers

kromakey a écrit :
On Mon, 10 Dec 2007 16:10:16 +0200, Nikos Vergas wrote:

[snip]
Problem: In the dynamic language of your choice, write a short program
that will:
1. define a list of the following user ids 42346, 77290, 729 (you can
hardcode these, but it should
still work with more or less ids)
2. retrieve an xml document related to each user at this url "http://
api.etsy.com/feeds/xml_user_details.php?id="
3. retrieve the data contained in the city element from each xml
document
4. keep a running total of how many users are found in each city 5.
display the total count of users living in each city [snip]
(snip)

A simpleton's version:

#!/usr/local/bin/python

import urllib
from elementtree import ElementTree as et

userids = [71234,729,42346,77290,729,729]
url = 'http://api.etsy.com/feeds/xml_user_details.php?id='

if __name__ == "__main__":

city = {}
for userid in userids:
feed = urllib.urlopen(url+str(userid))
tree = et.parse(feed)
for elem in tree.getiterator('city'):
if not city.has_key(elem.text):city[elem.text] = 1
else: city[elem.text] += 1
for k,v in city.items():
if not k == None:print k,':\t',v


def count_users_by_city(url, userids):
urlopen = urllib.urlopen
parse = et.parse
cities = {}
for userid in map(str, userids):
feed = urlopen(url+userid)
tree = parse(feed)
for elem in tree.getiterator('city'):
key = elem.text
if key in cities:
cities[key] += 1
else:
cities[key] = 1
return cities

if __name__ == '__main__':
cities = count_users_by_city(url, userids)
print "\n".join("%s:%s" % item for item in cities.items())


Not tested !-)
 
G

George Sakkis

On Mon, 10 Dec 2007 16:10:16 +0200, Nikos Vergas wrote:
[snip]
Problem: In the dynamic language of your choice, write a short
program that will:
1. define a list of the following user ids 42346, 77290, 729 (you
can
hardcode these, but it should
still work with more or less ids)
2. retrieve an xml document related to each user at this url
"http://
api.etsy.com/feeds/xml_user_details.php?id="
3. retrieve the data contained in the city element from each xml
document
4. keep a running total of how many users are found in each city 5.
display the total count of users living in each city
[snip]
i wanted to make it a one liner, but i had to import modules :(
import sys, xml, urllib
dummy = [sys.stdout.write(city + ': ' + str(num) + '\n') for city,
num in set([[(a, o.count(a)) for a in p] for o, p in [2*tuple([[city
for city in
((xml.dom.minidom.parseString(urllib.urlopen('http://api.etsy.com/
feeds/
xml_user_details.php?id='
+ str(id)).read()).getElementsByTagName('city')[0].childNodes +
[(lambda t: (setattr(t, 'data', 'no city'),
t))(xml.dom.minidom.Text())[1]])[0].data.lower().replace(' ', ' ')
for id in [71234, 71234, 71234, 71234, 71234, 71234,
42792])]])]][0])]
I suggest `__import__` in such cases.
Even though I do not qualify for the job, I came up with this (<wink>)
code (modified list values for demonstration, mixed together from
previous post and original task):
print '\n'.join('%s: %d'%(x,len(list(y))) for x,y in __import__
('itertools').groupby(sorted(__import__('xml').dom.minidom.parse
(__import__('urllib').urlopen('http://api.etsy.com/feeds/
xml_user_details.php?id=%d'%i)).getElementsByTagName('city')
[0].lastChild.data.title() for i in (71234, 729, 42346, 77290, 729,
729))))
I still find this rather readable, though, and there is no bad side-
effect magic! :)
Output should be:
| Chicago: 3
| Fort Lauderdale: 1
| Jersey City And South Florida: 1
| New York: 1
Alas, it's not:
AttributeError: 'module' object has no attribute 'dom'
Here's a working version, optimized for char length (one line, 241
chars):
import urllib as U,elementtree.ElementTree as
E;c=[E.parse(U.urlopen('http://api.etsy.com/feeds/xml_user_details.php?
id=%d'%u)).findtext('//city')for u in
71234,729,42346,77290,729,729];print'\n'.join('%s: %s'%
(i,c.count(i))for i in set(c))

Heh, yes. I did the same error as the participant before me -- test it in
a premodified environment. A fix is easy, __import__ 'xml.dom.minidom'
instead of 'xml'. :)

Closer, but still wrong; for some weird reason, __import__ for modules
in packages returns the top level package by default; you have to use
the 'fromlist' argument:
<module 'xml.dom.minidom' from '/usr/local/lib/python2.5/xml/dom/
minidom.pyc'>


George
 
S

Stargaming

Even though I do not qualify for the job, I came up with this
(<wink>) code (modified list values for demonstration, mixed
together from previous post and original task):
print '\n'.join('%s: %d'%(x,len(list(y))) for x,y in __import__
('itertools').groupby(sorted(__import__('xml').dom.minidom.parse
(__import__('urllib').urlopen('http://api.etsy.com/feeds/
xml_user_details.php?id=%d'%i)).getElementsByTagName('city')
[0].lastChild.data.title() for i in (71234, 729, 42346, 77290, 729,
729))))
[snip]
Alas, it's not:
AttributeError: 'module' object has no attribute 'dom'
[snip]
Heh, yes. I did the same error as the participant before me -- test it
in a premodified environment. A fix is easy, __import__
'xml.dom.minidom' instead of 'xml'. :)

Closer, but still wrong; for some weird reason, __import__ for modules
in packages returns the top level package by default; you have to use
the 'fromlist' argument:
<module 'xml.dom.minidom' from '/usr/local/lib/python2.5/xml/dom/
minidom.pyc'>


George

No, it's perfectly right::
<module 'xml.dom.minidom' from
'/usr/lib/python2.5/xml/dom/minidom.pyc'>

You can observe the change pretty well in `sys.modules`::

The result will be a few core modules and the module `xml`. When
importing `xml.dom.minidom`, though, this imports a lot more files::

Among them, there are `xml`, `xml.dom` and `xml.dom.minidom`. Having
these modules imported, `__import__('xml.dom.minidom').dom.minidom`
becomes a perfectly valid access to the xml/xml.dom packages.

So, your check is correct, importing xml.dom.minidom and xml both give a
reference to `xml` but the import machinery is invoked to import its
contents, as well, when explicitly told to.
 
G

George Sakkis

No, it's perfectly right::

<module 'xml.dom.minidom' from
'/usr/lib/python2.5/xml/dom/minidom.pyc'>

Sure, if you remember to repeat all.the.subpackages.after.the.top.
Instead of __import__ I use a more intuitive and general version that
doesn't stop at module boundaries but acts as getattr() within a
module:

for name in ['xml',
'xml.dom',
'xml.dom.minidom',
'xml.dom.minidom.parse',
'xml.dom.minidom.parse.__name__']:
print '%s: %r\n' % (name, import_name(name))


#### output

xml: <module 'xml' from '/usr/local/lib/python2.5/xml/__init__.pyc'>

xml.dom: <module 'xml.dom' from '/usr/local/lib/python2.5/xml/dom/
__init__.pyc'>

xml.dom.minidom: <module 'xml.dom.minidom' from '/usr/local/lib/
python2.5/xml/dom/minidom.pyc'>

xml.dom.minidom.parse: <function parse at 0xb7d40614>

xml.dom.minidom.parse.__name__: 'parse'


#=== import_name =============================

def import_name(name, globals={}, locals={}):
prefix,sep,tail = name.partition('.')
obj = __import__(prefix, globals, locals)
is_module = True
while sep:
head,sep,tail = tail.partition('.')
if is_module:
prefix += '.' + head
try: __import__(prefix, globals, locals)
except ImportError: is_module = False
try: obj = getattr(obj,head)
except AttributeError:
raise ImportError('No name %s' % name)
return obj


George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,979
Messages
2,570,185
Members
46,727
Latest member
FelicaTole

Latest Threads

Top