X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-live.git;a=blobdiff_plain;f=yarrg%2Fyppedia-ocean-scraper;h=476c1cd9b381bb0d5d5ec1979cc4928bff9fa9f4;hp=30d0c4a8de8d895292879a074a6bf654ecdec4c5;hb=d7465beff921821bf120a25a30a35ef06bddfc0e;hpb=efeac1885cd0211754b34e173a5efb74b6cbedb2 diff --git a/yarrg/yppedia-ocean-scraper b/yarrg/yppedia-ocean-scraper index 30d0c4a..476c1cd 100755 --- a/yarrg/yppedia-ocean-scraper +++ b/yarrg/yppedia-ocean-scraper @@ -42,6 +42,23 @@ import re as regexp from optparse import OptionParser from BeautifulSoup import BeautifulSoup + +# For fuck's sake! +import codecs +import locale +def fix_stdout(): + sys.stdout = codecs.EncodedFile(sys.stdout, locale.getpreferredencoding()) + def null_decode(input, errors='strict'): + return input, len(input) + sys.stdout.decode = null_decode +# From +# http://ewx.livejournal.com/457086.html?thread=3016574 +# http://ewx.livejournal.com/457086.html?thread=3016574 +# lightly modified. +# See also Debian #415968. +fix_stdout() + + ocean = None soup = None opts = None @@ -89,13 +106,13 @@ def parse_chart(): debug('s',s) s = regexp.sub(r'\<\;', '<', s) s = regexp.sub(r'\>\;', '>', s) + s = regexp.sub(r'\"\;', '"', s) s = regexp.sub(r'\&\;', '&', s) debug('s',s) return s def parse_ocean(): - firstarch = soup.find('a', attrs = {'title': title_arch_ok}) - debug('fa',firstarch) + content = soup.find('div', attrs = {'id': 'content'}) def findall_title_arch_ok(t): return t.findAll('a', attrs = {'title': title_arch_ok}) @@ -104,7 +121,7 @@ def parse_ocean(): if u.name != 'table': return False return len(findall_title_arch_ok(u)) > 1 - archestable = firstarch.findParent('table', attrs={'border':'1'}) + archestable = content.findChild('table', attrs={'border':'1'}) debug('at',archestable) archsoups = []