4 signal.signal(signal.SIGINT, signal.SIG_DFL)
10 #from optparse import OptionParser
12 from BeautifulSoup import BeautifulSoup
23 url = ('http://yppedia.puzzlepirates.com/%s_Ocean' %
24 urllib.quote(ocean,''))
25 dataf = urllib2.urlopen(url)
26 soup = BeautifulSoup(dataf)
29 title_arch_re = regexp.compile('(\\S+) Archipelago \\((\\S+)\\)$')
30 title_any_re = regexp.compile('(\\S.*\\S) \((\\S+)\\)$')
31 href_img_re = regexp.compile('\\.png$')
33 def title_arch_info(t):
34 # returns (arch,ocean)
36 if t is None: return (None,None)
37 m = title_arch_re.match(t)
38 if not m: return (None,None)
42 (a,o) = title_arch_info(t)
43 if o is None: return False
47 firstarch = soup.find('a', attrs = {'title': title_arch_ok})
50 def findall_title_arch_ok(t):
51 return t.findAll('a', attrs = {'title': title_arch_ok})
53 def is_archestable(u):
54 if u.name != 'table': return False
55 return len(findall_title_arch_ok(u)) > 1
57 archestable = firstarch.findParent(is_archestable)
58 debug('at',archestable)
60 arches = findall_title_arch_ok(archestable)
64 return len(v.findAll(text = regexp.compile('.*Large'))) > 0
66 return u.findParent(is_island)
67 arches = map(arch_up_map, arches)
71 links = arch.findAll('a', href=True)
73 (a,o) = title_arch_info(links[0]['title'])
76 for link in links[1:]:
78 if href_img_re.search(link['href']): continue
79 m = title_any_re.match(link['title'])
80 assert(m.group(2) == ocean)
81 print 'island', m.group(1)