Skip to content

Instantly share code, notes, and snippets.

@zodman
Created May 29, 2009 18:34
Show Gist options
  • Save zodman/120125 to your computer and use it in GitHub Desktop.
Save zodman/120125 to your computer and use it in GitHub Desktop.
a very basic command line frontend to the rbo package search
#!/usr/bin/python
#
# Copyright (c) 2009 Mark Trompell <[email protected]>
# This file is distributed under the terms of the MIT License.
# A copy is available at http://www.rpath.com/permanent/mit-license.html
#
# a very basic command line frontend to the rbo package search
import urllib2,sys,string,os
from HTMLParser import HTMLParser
class rboparser(HTMLParser):
def handle_starttag(self, tag, attrs):
if (tag == "td"):
for att in attrs:
if (att[1] == 'mainSearchItemDesc'):
print (str(self.rawdata.split('\n')[self.getpos()[0]]).strip())
if (len(sys.argv) != 2):
usage = "usage: "+ sys.argv[0] + " <search string>"
print (usage)
exit ()
searchstring = "http://www.rpath.org/search?type=Packages&search=" + sys.argv[1] + ";limit=100000"
searchstring = searchstring.replace(' ','+')
if os.getenv("HTTP_PROXY"):
proxy_support = urllib2.ProxyHandler({"http" :os.getenv("HTTP_PROXY")})
opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler)
urllib2.install_opener(opener)
f = urllib2.urlopen(searchstring)
rbo = rboparser()
rbo.feed(f.read())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment