from BeautifulSoup import BeautifulSoup
import re
import urllib2
import optparse
#Create the soup
base="http://montreal.fr.craigslist.ca/search/"
url=base+"/eng?addOne=telecommuting"
page=urllib2.urlopen(url)
soup = BeautifulSoup(page.read())

def out(sline):
	for word in sline:
		print word

#Search the soup
# print soup.prettify()
# print soup.findAll('p',{'class':'row'})
sline = soup.findAll('p',{'class':'row'})
# print slug lines
print('<p> Montreal </p>') 
# print('<base href="http://montreal.fr.craigslist.ca/search/"')  
# print soup.findAll('a',{'class':'l'})
print('<base href="'+base+'">')
for word in sline:
	print word



def main():
	''' 
	This is the main subroutine, any detail about this program belongs here.
	This program has two basic parts:
	1. data gathering from at pellergy furnace with a furmon installed and
	2. display of this data via mrtg.
Tue 02 Apr 2013 02:52:07 PM EDT this is the rewrite with the object right.
Fri 29 Mar 2013 07:02:36 AM EDT at this point the program depends on sample data
           This data is in the "New Haven Display" format and is basically binary.
Thu 04 Apr 2013 08:16:33 AM EDT new version of fm.py trying to clean up this code.
Mon 08 Apr 2013 02:17:18 PM EDT Continuing cleanup...
Fri 03 May 2013 08:46:50 AM EDT clean up serial routine
Tue 11 Jun 2013 01:48:23 PM EDT working on the file based system
Wed 12 Jun 2013 08:46:56 AM EDT cleaning up file and testing serial based system...
        '''
start_time = time.time()
# frfile = furmon() # instantiate the furmon class to frfile
# print "starting %s at %s " % (__file__, \
go_time=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
print "starting %s at %s " % (__file__, go_time)
if len(sys.argv) == 1:
	print "Welcome to the Furmon Support Package, fm.py. For operating information type '%s -h'" % __file__
	sys.exit()
#  Above handles no arguments
#
else:
# parse options and act
    	parser = optparse.OptionParser(description='Furmon Software Support Package',
                 prog=os.path.basename(__file__),
                 version='This code is version %s, and the code, %s is copyright 2013 by fits and licensed under GPLI	' % ( ver,os.path.basename(__file__) ),
                 usage= '%prog [option]')
   	#
	parser.add_option('-?', '--query',   dest='bool',default=False, action='store_true',help='print document string with extensive result',)
	parser.add_option('-s', '--serial',  dest='serialp',default=False, action='store_true',help='gather data from serial port',)
	parser.add_option("-f", "--file",    dest="filename",  default="USB",help="read test data from a file", metavar="FILE")
	parser.add_option("-p", "--port",    dest="serial_port",  default="/dev/ttyUSB0",help="set serial port; \tdefault=\"/dev/ttyUSB0\"", metavar="STRING")
	parser.add_option("-b", "--baud",    dest="port_baud",  default="9600",help="set port speed;  \tdefault=\"9600\"", metavar="STRING")
	parser.add_option("-t", "--timeout", dest="timeout",  default="6",help="set timeout value;  \tdefault=\"6\"", metavar="INT")
#
# Evaluates inbound arguments
	options, arguments = parser.parse_args()	# evaluate options
	if options.bool: 
		print len(sys.argv)
		intro()
		sys.exit()	
	elif options.serialp:
		print "You are at the serial routine"
		serial = furmon() # instantiate the furmon class to serial
		out=serial #enable the instance
		# mser=otrs()
		# print mser.__doc__rsdl(mser)
		# print dir(mser)
		#d print rsdl(mser) 
		doserial()
		sys.exit()	
	elif options.filename != "USB":
		print "You are at file routines"
		dline=otrf() # open file
		print "this is the end of opening"
		frfile = furmon() # instantiate the furmon class to frfile
		out=frfile #enable the instance
		# print frfile.system_temp
		# print dline.__doc__
		# print dir(dline)
		# print dline.readline()
		# print re.split("\xfeE",dline.readline())
		# print inf.__doc__
		# print dir(inf)
		# print rfdl(L) # read line from file
		# print rfdl(dline) # read line from file to out
		# print rfdl(dline) # read line from file to out
		dofile() # code to use for all object elements
		# dfscript("test.sh") # code to use for all object elements
		# tfile() # test individual object elements
		# expose(furmon)
		# expose(frfile)
		sys.exit()	
	elif options.serial_port != "/dev/ttyUSB0":
		print "You are at port selection"
		sys.exit()
	elif options.port_baud != "9600":
		print "You are at port selection"
		sys.exit()	
	elif options.timeout != "6":
		print "You are at timeout selection"
		sys.exit()	
# More junk
	# print 'file name %s' % options.filename
	# print 'Hello %s' % options.person


if __name__ == '__main__':
	main()
	print "that's it"



