chiark / gitweb /
Remove test chart
[ypp-sc-tools.db-live.git] / yarrg / yppedia-ocean-scraper
index 9105f19..30d0c4a 100755 (executable)
@@ -53,8 +53,12 @@ def debug(k,v):
 
 def fetch():
        global soup
-       url = ('http://yppedia.puzzlepirates.com/%s_Ocean' %
-               urllib.quote(ocean,''))
+       if opts.chart:
+               url_base = 'index.php?title=Template:Map:%s_Ocean&action=edit'
+       else:
+               url_base = '%s_Ocean'
+       url = ('http://yppedia.puzzlepirates.com/' +
+                       (url_base % urllib.quote(ocean,'')))
        debug('fetching',url)
        dataf = urllib2.urlopen(url)
        debug('fetched',dataf)
@@ -78,7 +82,18 @@ def title_arch_ok(t):
        if o is None: return False
        return o == ocean
 
-def parse():
+def parse_chart():
+       ta = soup.find('textarea')
+       debug('ta',ta)
+       s = ta.string
+       debug('s',s)
+       s = regexp.sub(r'\&lt\;', '<', s)
+       s = regexp.sub(r'\&gt\;', '>', s)
+       s = regexp.sub(r'\&amp\;', '&', s)
+       debug('s',s)
+       return s
+
+def parse_ocean():
        firstarch = soup.find('a', attrs = {'title': title_arch_ok})
        debug('fa',firstarch)
 
@@ -136,8 +151,11 @@ def main():
        global opts
 
        pa = OptionParser(
-               '''usage: .../yppedia-ocean-scraper [--debug] OCEAN''')
+'''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')
 
@@ -148,7 +166,10 @@ def main():
        ocean = args[0]
 
        fetch()
-       parse()
-       output()
+       if opts.chart:
+               print parse_chart()
+       else:
+               parse_ocean()
+               output()
 
 main()