import mechanize as ClientCookie
import urllib2, ClientCookie, re, sys, os
###linux users, use this instead:
#import urllib2, ClientCookie, re, sys, os
baseURL = 'http://www.geocaching.com/seek/cache_details.aspx?wp='
header = {'User-agent' : 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'}
ffcj = ClientCookie.MozillaCookieJar()
ffcj.load('/home/chg/.mozilla/firefox/646bt3ud.default/cookies.txt')
opener = urllib2.build_opener(ClientCookie.HTTPCookieProcessor(ffcj))
urllib2.install_opener(opener)
waypointfile = open('waypoints_base.txt', 'w')
tagstoascii = [['
','\n'], ['
','\n\n'], [' ',' ']] def clean(html): for old, new in tagstoascii: html = html.replace(old, new) html = re.sub('(?s)<.+?>', '', html) return html def fetchSite(url): req = urllib2.Request(url, None, header) return urllib2.urlopen(req).read() def printCache(gcid): html = fetchSite(baseURL + gcid) cachetype = re.findall('ALT="(.+?)" BORDER=0 WIDTH=32', html)[0] name = re.findall('(.+?)', html)[0] size = re.findall('(?s)Size: .+?alt="Size: (.+?)"', html)[0] diff = int(re.findall('.+?alt="(.+?) out of 5"', html)[0][0]) diffgraph = diff * '*' + (5-diff) * '-' terr = int(re.findall('.+?alt="(.+?) out of 5"', html)[0][0]) terrgraph = terr * '*' + (5-terr) * '-' coords = re.findall('(.*?)', html)[0] lati, longi = re.findall('/wpt/\?lat=(.+?)&lon=(.+?)&', html)[0] lati = str(round(float(lati), 5)) longi = str(round(float(longi), 5)) shortdesc = re.findall('(?s)(.+?)', html)[0] longdesc = re.findall('(?s)(.+?)\s+?
', html)[0] try: hints = re.findall('(.+?)', html)[0] hintsplain = hints.encode('rot13') except: hintsplain = 'no hints avaliable' found = re.findall('alt="Found it"/>(.+?)', html)[0] try: notfound = re.findall('alt="Didn\'t find it"/>(.+?)', html)[0] except: notfound = '0' logs = re.findall("class='logContainer(?:Alt)?Row'>.+?icon_(smile|sad).gif.+? (.+?)by.+?\((.+?)\)