Suddenly I wanted to get a list of packages I registered on PyPI. When you log in to PyPI, your package list will appear in the menu.
But if you have to log in, you can't get the list of packages of other users. If you enter a user name in a PyPI search, it will hit the search to some extent, but it will also narrow down packages that happen to include the user name.
According to https://wiki.python.org/moin/PyPIXmlRpc, it seems that you can use xmlrpc.
>>> import xmlrpc.client as xmlrpclib
>>> client = xmlrpclib.ServerProxy('https://pypi.python.org/pypi')
>>> client.user_packages('t2y')
[['Owner', 'ikazuchi'],
['Owner', 'ikazuchi.plugins.pofile'],
['Owner', 'ikazuchi.plugins.speech'],
['Owner', 'ikazuchi.plugins.blockdiag'],
['Owner', 'pyrtm'],
['Owner', 'TracTicketReferencePlugin'],
['Owner', 'LittleHTTPServer'],
['Owner', 'pytest-quickcheck'],
['Owner', 'kotti_mapreduce'],
['Maintainer', 'TracCronPlugin'],
['Owner', 'TracCronPlugin'],
['Owner', 'TracMultiSelectBoxPlugin'],
['Owner', 'TracChangeFileBiffPlugin'],
['Owner', 'unotools'],
['Owner', 'TracAutocompleteUsersPlugin'],
['Owner', 'TracMovieMacro']]
I see, it's done.
But it's a hassle to launch an interactive shell to get a list of packages, isn't it? It would be a little easier if you hit xmlrpc directly from the command line. Let's try using curl.
$ user="t2y"; curl -s -X POST -H "Content-Type: text/xml" https://pypi.python.org/pypi -d "<?xml version='1.0'?><methodCall><methodName>user_packages</methodName><params><name>$user</name></params></methodCall>" | python -c "import sys; import xml.dom.minidom; print(xml.dom.minidom.parseString(sys.stdin.read()).toprettyxml(indent=' '))"
<?xml version="1.0" ?>
<methodResponse>
<params>
<param>
<value>
<array>
<data>
<value>
<array>
<data>
<value>
<string>Owner</string>
</value>
<value>
<string>ikazuchi</string>
</value>
</data>
</array>
</value>
...
I see, it's done.
However, displaying the xmlrpc response as it is is redundant, and the line feed code is included here and there, so it is not easy to see at all.
I wonder if there is no choice but to parse and display the response of xmlrpc. Let's try using ElementTree.
$ user="t2y"; curl -s -X POST -H "Content-Type: text/xml" https://pypi.python.org/pypi -d "<?xml version='1.0'?><methodCall><methodName>user_packages</methodName><params><name>$user</name></params></methodCall>" | python -c "import sys; from xml.etree import ElementTree; print('\n'.join(j for j in sorted(['{} ({})'.format(i[1][0].text, i[0][0].text) for i in ElementTree.parse(sys.stdin).iter('data') if i[1][0].text])))"
LittleHTTPServer (Owner)
TracAutocompleteUsersPlugin (Owner)
TracChangeFileBiffPlugin (Owner)
TracCronPlugin (Maintainer)
TracCronPlugin (Owner)
TracMovieMacro (Owner)
TracMultiSelectBoxPlugin (Owner)
TracTicketReferencePlugin (Owner)
ikazuchi (Owner)
ikazuchi.plugins.blockdiag (Owner)
ikazuchi.plugins.pofile (Owner)
ikazuchi.plugins.speech (Owner)
kotti_mapreduce (Owner)
pyrtm (Owner)
pytest-quickcheck (Owner)
unotools (Owner)
I see, it's done.
・ ・ ・
I honestly don't know what to do: sweat:
Recommended Posts