9 from BeautifulSoup import BeautifulSoup
17 cache_corename = urllib.quote_plus(url)
18 cache_basename = "#%s#" % cache_corename
19 try: f = file(cache_basename, 'r')
20 except (OSError,IOError), oe:
21 if oe.errno != errno.ENOENT: raise
24 s = os.fstat(f.fileno())
25 if now > s.st_mtime + max_age:
31 stream = urllib2.urlopen(url)
33 cache_ourname = "#%s~%d#" % (cache_corename, os.getpid())
34 f = file(cache_ourname, 'w')
37 os.rename(cache_ourname, cache_basename)
40 def yoweb_fetch(kind, tail):
41 url = 'http://%s.puzzlepirates.com/yoweb/%s%s' % (ocean, kind, tail)
44 def get_pirate_info(pirate):
45 html = yoweb_fetch('pirate.wm?target=', pirate)
46 soup = BeautifulSoup(html)
50 os.chdir(os.getenv('HOME'))
51 cache_dir = '.yoweb-scrape-cache'
54 except (OSError,IOError), oe:
55 if oe.errno != errno.ENOENT: raise
59 for path in os.listdir('.'):
60 if not path.startswith('#'): continue
62 if '~' in path: max_time = 10
65 if now > s.st_mtime + max_time:
67 except (OSError,IOError), oe:
68 if oe.errno != errno.ENOENT: raise
73 test = get_pirate_info('Aristarchus')