#! /usr/bin/python
import random
import urllib2
import traceback,sys
keywords=("Elvis","Presley","the King","The King","Big E","Presly","Pressley","Pressly"," E.")
newwords=("Chess","Griffin","Chess Griffin","Chess Griffin","Big C","Griffin","Griffin","Griffin"," Chess.")
def getblock():
'''get's a page from the Elvis Sightings page'''
page=random.randint(1,94)*8
req = urllib2.Request('http://www.elvissightingbulletinboard.com/cgi-bin/vizbook.cgi?nxtfrm=y&strt_is=%d'%page)
req.add_header('Referer', 'http://www.elvissightingbulletinboard.com/SightingLog.shtml')
r = urllib2.urlopen(req)
return r.read()
def testblock():
'''only called for testing'''
f=open("testdata","r")
d=f.read()
f.close()
return d #r.read()
def main():
data=getblock()
#data=testblock()
data=data[data.index('
" in sighting and ', Helvetica' in sighting and '' in sighting:
start=sighting.index('Sighting:')
start=sighting.index(', Helvetica',start+1)
finish=sighting.index("",start)
quote=sighting[start+len(', Helvetica >'):finish]
for i in range(0,len(keywords)):
quote=quote.replace(keywords[i],newwords[i])
quote=quote.replace(keywords[i].upper(),newwords[i])
quote=quote.replace(keywords[i].lower(),newwords[i])
quotes.append(quote)
if "Submitted " in sighting and ', Helvetica' in sighting and '' in sighting:
person="anonymous"
#get a person
start=sighting.index("Submitted ")
start=sighting.index(', Helvetica',start+1)
finish=sighting.index("",start)
person = sighting[start+len(', Helvetica >'):finish]
#and their location
try:
start=sighting.index("Of: <",finish)
start=sighting.index(', Helvetica',start+1)
finish=sighting.index('',start)
person+= " "+ sighting[start+len(', Helvetica >'):finish]
except:
pass
submittedby.append(person.replace(" ","").replace("<",""))
if len(submittedby)