- a = title_arch_arch(t)
- if a is None: return False
- return a == ocean
-
-firstarch = soup.find('a', attrs = {'title': title_arch_ok})
-print 'fa',`firstarch`
-
-archestable = firstarch.findParent(
- lambda u: u.name == 'table' and
- len(u.findAll('a', attrs = {'title': title_arch_ok})) > 1
- )
-
-print 'at',`archestable`
-
-arches = archestable.findAll('a', attrs = {'title': title_arch_ok})
-print 'ac', `arches`
-
-arches = map((lambda u: u.findParent(
- lambda v: len(v.findAll(text= regexp.compile('.*Large'))) > 0
- )), arches)
-print 'ac2', `arches`
-
-for arch in arches:
- links = arch.findAll('a', href=True)
- print 'links', `links`
- a = title_arch_arch(links[0]['title'])
- assert(a)
- print a
- for link in links[1:]:
- print 'link', `link`
- if href_img_re.search(link['href']): continue
- m = title_any_re.match(link['title'])
- assert(m.group(2) == ocean)
- print m.group(1)
+ (a,o) = title_arch_info(t)
+ if o is None: return False
+ return o == ocean
+
+def parse_chart():
+ ta = soup.find('textarea')
+ debug('ta',ta)
+ s = ta.string
+ 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():
+ content = soup.find('div', attrs = {'id': 'content'})
+
+ def findall_title_arch_ok(t):
+ return t.findAll('a', attrs = {'title': title_arch_ok})
+
+ def is_archestable(u):
+ if u.name != 'table': return False
+ return len(findall_title_arch_ok(u)) > 1
+
+ archestable = content.findChild('table', attrs={'border':'1'})
+ debug('at',archestable)
+
+ archsoups = []
+ for row in archestable.findAll('tr',recursive=False):
+ archsoups += row.findAll('td',recursive=False)
+ debug('ac',archsoups)
+
+ def is_island(v):
+ return len(v.findAll(text = regexp.compile('.*Large'))) > 0
+ def arch_up_map(u):
+ return u.findParent(is_island)
+
+ for arch in archsoups:
+ links = arch.findAll('a', href=True)
+ debug('links',links)
+ if not links: continue
+ (a,o) = title_arch_info(links[0]['title'])
+ debug('arch-ocean', (a,o))
+ assert(o == ocean)
+ assert(a not in arches)
+ isles = []
+ for link in links[1:]:
+ debug('link',link)
+ if href_img_re.search(link['href']): continue
+ m = title_any_re.match(link['title'])
+ assert(m.group(2) == ocean)
+ island = m.group(1)
+ debug('island', island)
+ isles.append(island)
+ isles.sort()
+ arches[a] = isles
+
+def output():
+ print 'ocean',ocean
+ al = arches.keys()
+ al.sort()
+ for a in al:
+ print '',a
+ for island in arches[a]:
+ print ' ',island
+
+def main():
+ global ocean
+ global opts
+
+ pa = OptionParser(
+'''usage: .../yppedia-ocean-scraper [--debug] [--chart] OCEAN''')
+ ao = pa.add_option
+
+ ao('--chart', action='store_true', dest='chart',
+ help='print chart source rather than arch/island info')
+ ao('--debug', action='count', dest='debug', default=0,
+ help='enable debugging output')
+
+ (opts,args) = pa.parse_args()
+ if len(args) != 1:
+ print >>sys.stderr, copyright_info
+ pa.error('need an ocean argument')
+ ocean = args[0]
+
+ fetch()
+ if opts.chart:
+ print parse_chart()
+ else:
+ parse_ocean()
+ output()
+
+main()