### # Copyright (c) 2008, Terence Simpson # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # ### import sys, re, urllib2, RDF def striphtml(data): '''striphtml(data) -> list Try to strip away the HTML tags in the list "data" ''' start = re.compile('<[a-z]+.*>') # opening HTML tag <...> end = re.compile('[a-z]+>') # closing HTML tag # find and replace code for i in range(0, len(data)): # replace the closing tag first, as the starting regex will match up to the closing other wise r = end.search(data[i]) while r: data[i] = data[i].replace(data[i][r.start():r.end()], '', 1) r = end.search(data[i]) r = start.search(data[i]) while r: data[i] = data[i].replace(data[i][r.start():r.end()], '', 1) r = start.search(data[i]) # return the list back return data def getIRCNick(user, errors=True): '''getIRCNick(user, errors) -> list Try to get the IRC nick(s) from the LP account "user". If errors is True print any errors to stderr, defaults to True ''' # Get the HTML data from LP try: data = urllib2.urlopen('https://launchpad.net/~%s' % user).read() except Exception, e: if errors: print >> sys.stderr, "Could not get user info (%s)" % e return details = '