import requests import string import cgi import urllib import time import regsub true = 1 false = 0 path = 'C:\\Users\\Fred\\Webpages\\search\\' # # EngineData # EngineData = [ # AltaVista { 'machine':'www.altavista.digital.com', 'uri':'/cgi-bin/query', 'form':{ 'pg':'q', 'what':'web', 'fmt':'.' }, 'queryName':'q', 'method':'GET', 'Xarph':true, 'filter': { 'change_font':true } }, # Aussie AltaVista { 'machine':'www.altavista.yellowpages.com.au', 'uri':'/cgi-bin/telstra', 'form':{ 'pg':'q', 'what':'web', 'fmt':'.' }, 'queryName':'q', 'method':'GET', 'Xarph':true, 'filter': {} }, # Euro AltaVista { 'machine':'www.altavista.telia.com', 'uri':'/cgi-bin/query', 'form':{ 'mss':'gb/search', 'pg':'q', 'what':'web', 'kl':'' }, 'queryName':'q', 'method':'GET', 'Xarph':true, 'filter': {} }, # News US AltaVista { 'machine':'www.altavista.digital.com', 'uri':'/cgi-bin/query', 'form':{ 'pg':'q', 'what':'news', 'fmt':'.' }, 'queryName':'q', 'method':'GET', 'Xarph':true, 'filter': {} }, # News Aussie AltaVista { 'machine':'www.altavista.yellowpages.com.au', 'uri':'/cgi-bin/telstra', 'form':{ 'pg':'q', 'what':'news', 'fmt':'.' }, 'queryName':'q', 'method':'GET', 'Xarph':true, 'filter': {} }, # News Euro AltaVista { 'machine':'www.altavista.telia.com', 'uri':'/cgi-bin/telia', 'form':{ 'pg':'q', 'what':'news', 'fmt':'.' }, 'queryName':'q', 'method':'GET', 'Xarph':true, 'filter': {} }, # CNF { 'machine':'www2.cnf.cornell.edu', 'uri':'/htbin/schd/show1dayastable', 'form':{ 'SUBMIT':'Show', 'Year':'0' }, 'queryName':'', 'method':'POST', 'Xarph':false, 'Special':'CNF', 'filter': {} }, # Infoseek { 'machine':'guide.infoseek.com', 'uri':'/Titles', 'form':{ }, 'queryName':'qt', 'method':'GET', 'Xarph':true, 'filter': {} }, # New DejaNews { 'machine':'search.dejanews.com', 'uri':'/dnquery.xp', 'form':{ 'defaultOp':'AND', 'svcclass':'dncurrent', 'maxhits':'40' }, 'queryName':'query', 'method':'POST', 'Xarph':false, 'filter': {} }, # Old DejaNews { 'machine':'search.dejanews.com', 'uri':'/dnquery.xp', 'form':{ 'defaultOp':'AND', 'svcclass':'dnold', 'maxhits':'40' }, 'queryName':'query', 'method':'POST', 'Xarph':false, 'filter': {} }, # Yahoo { 'machine':'av.yahoo.com', 'uri':'/bin/query', 'form':{ }, 'queryName':'p', 'method':'GET', 'Xarph':false, 'filter': {} }, # Street Maps { 'machine':'www.vicinity.com', 'uri':'/yt.hm', 'form':{ 'FAM':'yahoo', 'CMD':'geo', 'SEC':'geo' }, 'queryName':'AD2', 'method':'GET', 'Xarph':false, 'Special':'StreetMaps', 'filter': {} }, # WeatherUnderground { 'machine':'www.wunderground.com', 'uri':'/forecasts/', 'form':{ }, 'queryName':'', 'method':'GET', 'Xarph':false, 'Special':'Weather', 'filter': {} }, # Filez.com { 'machine':'search.filez.com', 'uri':'/search.cgi', 'form':{ 'search':'1', 'type':'1', 'key':'', 'rows':'90' }, 'queryName':'key', 'method':'GET', 'Xarph':false, 'filter': {} }, # Websters { 'machine':'www.m-w.com', 'uri':'/cgi-bin/netdict', 'form':{ 'book':'Dictionary' }, 'queryName':'va', 'method':'POST', 'Xarph':false, 'filter': {} } ] # # GetFile # def GetFile( strFileName ): file = open( strFileName, 'r' ) strFile = '' strLine = file.readline() while strLine != '': strFile = strFile + strLine strLine = file.readline() file.close() return strFile # # PrintHeader # # This prints the necessary header info for a html file. # def PrintHeader(): print 'Content-type: text/html\n\n' # # SpecialCNF # def SpecialCNF( engine, query ): EquipList = { 'pg':'Mann PG Pattern Generator', 'mann':'Mann PG Pattern Generator', 'mann pg':'Mann PG Pattern Generator', '10x':'10x i-line Stepper', '10x stepper':'10x i-line Stepper', 'stepper':'10x i-line Stepper', '5x':"5x g-line Stepper", '5x stepper':'5x g-line Stepper', 'htg':'HTG Contact Aligner', 'contact aligner':'HTG Contact Aligner', 'suss':'Karl Suss MA6', 'karl suss':'Karl Suss MA6', 'ma6':'Karl Suss MA6', 'cee 6000':'CEE 6000 Spin Coater', 'spin coater':'CEE 6000 Spin Coater', 'spinner':'CEE 6000 Spin Coater', 'yes':'YES Oven', 'yes oven':'YES Oven', 'ebmf':'EBMF E-Beam', 'vb6':'Leica VB6 E-Beam', 'leica vb6':'Leica VB6 E-Beam', 'zeiss':'Leo DSM 982 SEM #1', 'leo':'Leo DSM 982 SEM #1', 'leo 1':'Leo DSM 982 SEM #1', 'leo #1':'Leo DSM 982 SEM #1', '982':'Leo DSM 982 SEM #1', '982 1':'Leo DSM 982 SEM #1', '982 #1':'Leo DSM 982 SEM #1', 'leo 2':'Leo DSM 982 SEM #2 (Nabity)', 'leo #2':'Leo DSM 982 SEM #2 (Nabity)', '982 2':'Leo DSM 982 SEM #2 (Nabity)', '982 #2':'Leo DSM 982 SEM #2 (Nabity)', 'nabity':'Leo DSM 982 SEM #2 (Nabity)', 'amray':'Amray 1830 SEM', 'amray sem':'Amray 1830 SEM', 'pecvd':'IPE PECVD', 'ipe pecvd':'IPE PECVD', 'sputterer':'CVC Sputter Deposition', 'sputter':'CVC Sputter Deposition', 'cha':'CHA Thermal Evaporator', 'thermal evaporator':'CHA Thermal Evaporator', 'ebeam':'CVC SC4500 Evaporator', 'ebeam evaporator':'CVC SC4500 Evaporator', 'egun':'CVC SC4500 Evaporator', 'egun evaporator':'CVC SC4500 Evaporator', 'cvc':'CVC SC4500 Evaporator', 'cvc evaporator':'CVC SC4500 Evaporator', 'dual e-gun':'Dual E-Gun Evaporator', 'grandson':'PlasmaTherm SSL720 RIE', 'new cl2':'PlasmaTherm SSL720 RIE', 'ssl720':'PlasmaTherm SSL720 RIE', '720':'PlasmaTherm SSL720 RIE', 'old man':'PlasmaTherm PK1250 RIE [Cl]', 'pk1250':'PlasmaTherm PK1250 RIE [Cl]', 'jr':'PlasmaTherm PT72 RIE [F]', '72':'PlasmaTherm PT72 RIE [F]', 'jr.':'PlasmaTherm PT72 RIE [F]', 'release':'PlasmaTherm PT72 RIE [F]', 'slr':'PlasmaTherm 770 ICP', 'bosch':'PlasmaTherm 770 ICP', 'slr 770':'PlasmaTherm 770 ICP', 'slr-770':'PlasmaTherm 770 ICP', '770':'PlasmaTherm 770 ICP', 'ecr':'PlasmaQuest ECR', 'caibe':'Techniks CAIBE', 'mie':'MRC MIE', 'applied materials':'Applied Materials RIE [F]', 'applied':'Applied Materials RIE [F]', 'ion mill':'Ion Mill', 'branson':'Branson Barrel Etcher', 'poly':'Polysilicon', 'poly tube':'Polysilicon', 'tft poly':'TFT Polysilicon', 'tft poly tube':'TFT Polysilicon', 'nitride':'Nitride', 'nitride tube':'Nitride', 'lpcvd nitride':'Nitride', 'lpcvd nitride tube':'Nitride', 'dry oxide':'HCL Oxide', 'dry oxide tube':'HCL Oxide', 'hcl oxide':'HCL Oxide', 'hcl oxide tube':'HCL Oxide', 'tca':'TCA Wet Oxide', 'tca tube':'TCA Wet Oxide', 'wet oxide':'TCA Wet Oxide', 'wet oxide tube':'TCA Wet Oxide', 'tca anneal':'TCA Anneal', 'tca anneal tube':'TCA Anneal', 'tca dry oxide':'TCA Dry Oxide', 'mos clean':'MOS Clean', 'clean':'MOS Clean', 'tft mos clean':'TFT MOS Clean', 'tft clean':'TFT MOS Clean', 'anneal':'Annealing', 'annealling':'Annealing', 'lto':'LTO 410', 'lto tube':'LTO 410', 'vlto':'LTO 410', 'vlto tube':'LTO 410', 'auger':'Scanning Auger Microprobe', 'topometrix':'Topometrix AFM/STM', 'afm':'Topometrix AFM/STM', 'stm':'Topometrix AFM/STM', 'iv':'Keithley I-V', 'probe':'Keithley I-V', 'probe station':'Keithley I-V', 'test':'Keithley I-V', 'testing':'Keithley I-V', 'ion implanter':'Varian Ion Implanter', 'implanter':'Varian Ion Implanter', 'rta':'AG Heatpulse RTA', 'ag heatpulse':'AG Heatpulse RTA', 'ag heatpulse rta':'AG Heatpulse RTA', 'help':'help' } if( EquipList.has_key( string.lower( query ) ) ): machine = EquipList[ string.lower( query ) ] else: machine = 'help' if( machine == 'help' ): engine[ 'file' ] = path + 'CNFHelp.html' return engine timeNow = time.localtime( time.time() ) engine[ 'form' ][ 'Month' ] = `timeNow[1]` engine[ 'form' ][ 'Day' ] = `timeNow[2]` engine[ 'form' ][ 'ECode' ] = machine return engine # # SpecialWeather # def SpecialWeather( engine, query ): query = string.upper( string.strip( query ) ) if( len( query ) == 3 ): engine[ 'uri' ] = '/forecasts/' + query + '.html' elif( query == 'GUNKS' ): engine[ 'uri' ] = '/forecasts/POU.html' elif( query == '' ): engine[ 'uri' ] = '/' elif( query == 'ITHACA' ): engine[ 'uri' ] = '/forecasts/ITH.html' elif( query == 'RADAR' ): engine[ 'uri' ] = '/weather/syr/radarloop/' engine[ 'machine' ] = 'www1.intellicast.com' else: engine[ 'uri' ] = '/cgi-bin/findweather/getForecast' engine[ 'queryName' ] = 'query' return engine # # SpecialStreetMaps # def SpecialStreetMaps( engine, query ): lWords = string.split( query ) if( lWords.length == 4 ): engine[ 'queryName' ] = lWords[0] engine[ 'form' ][ 'AD3' ] = lWords[1] + ',' + lWords[2] + ',' + lWords[3] elif( lWords.length == 3 ): engine[ 'queryName' ] = lWords[0] engine[ 'form' ][ 'AD3' ] = lWords[1] + ',' + lWords[2] else: if( query == '' ): engine[ 'form' ] = { 'CMD':'FILL', 'FAM':'yahoo', 'client':'yahoomap', 'SEC':'startym', 'stex':'-y' } else: engine[ 'file' ] = 'MapsHelp.html' # # Xarph # def Xarph( engine, query ): lWords = string.split( query ) lNewWords = [] quote = false for strWord in lWords: if( len( strWord ) > 0 ): if( not quote ): if( strWord[0] == '|' or strWord[0] == '/' ): if( len( strWord ) > 1 and strWord[1] == '"' ): quote = true lNewWords.append( strWord[1:] ) elif( strWord[0] == '+' or strWord[0] == '-' ): if( len( strWord ) > 1 and strWord[1] == '"' ): quote = true lNewWords.append( strWord ) else: if( strWord[0] == '"' ): quote = true lNewWords.append( '+' + strWord ) if( strWord[ len( strWord )-1 ] == '"' ): quote = false else: lNewWords.append( strWord ) if( (len( strWord ) > 1) and (strWord[ len( strWord )-1 ] == '"') ): quote = false return ( string.join( lNewWords ), engine, false ) # # FilterPage # def FilterPage( page, machine, uri, form, method, filterOptions ): if( filterOptions.has_key( 'change_font' ) ): page = regsub.gsub( '', '', page ) page = regsub.gsub( '', '', page ) return page # # GetPage # def GetPage( machine, uri, form, method, filterOptions ): if( method == 'POST' ): request = requests.POSTRequest( machine, uri, form, 80 ) elif( method == 'GET' ): request = requests.GETRequest( machine, uri, form, 80 ) else: return None Looper = requests.Read_Event_Loop() Looper.start_item( request ) startTime = time.time() while not Looper.all_done(): if( time.time() - startTime > 300 ): data = GetFile( path + 'Timeout.html' ) return data Looper.try_all_readables() data = request.data upperData = string.upper( data ) htmlIndex = string.find( upperData, '' ) data = data[ htmlIndex: ] upperData = string.upper( data ) if( string.find( upperData, '' ) if( headIndex == -1 ): headIndex = string.find( upperData, '' data = data[:headIndex] + base + data[headIndex:] data = FilterPage( data, machine, uri, form, method, filterOptions ) return data # # RunEngine # def RunEngine( engine, query ): if( engine.has_key( 'Special' ) ): special = engine[ 'Special' ] else: special = 'None' if( special == 'CNF' ): engine = SpecialCNF( engine, query ) elif( special == 'Weather' ): engine = SpecialWeather( engine, query ) elif( special == 'StreetMaps' ): engine = SpecialStreetMaps( engine, query ) if( engine.has_key( 'file' ) ): htmlPage = GetFile( engine[ 'file' ] ) else: if( engine[ 'queryName' ] != '' ): engine[ 'form' ][ engine[ 'queryName' ] ] = query htmlPage = GetPage( engine[ 'machine' ], engine[ 'uri' ], engine[ 'form' ], engine[ 'method' ], engine[ 'filter' ] ) return htmlPage # # RunSearch # def RunSearch( form ): data = {} if( form.has_key( 'keywords' ) ): data[ 'keywords' ] = form[ 'keywords' ].value else: data[ 'keywords' ] = '' if( form.has_key( 'WhichOne' ) ): data[ 'WhichOne' ] = form[ 'WhichOne' ].value else: data[ 'WhichOne' ] = '0' if( form.has_key( 'Xarph' ) ): data[ 'Xarph' ] = true else: data[ 'Xarph' ] = false whichOne = string.atoi( data[ 'WhichOne' ] ) engine = EngineData[ whichOne ] if( engine[ 'Xarph' ] == true and data[ 'Xarph' ] ): fRunAgain = true while( fRunAgain ): ( keywords, engine, fRunAgain ) = Xarph( engine, data[ 'keywords' ] ) else: keywords = data[ 'keywords' ] htmlPage = RunEngine( engine, keywords ) return htmlPage # # main # PrintHeader() form = cgi.FieldStorage() htmlPage = RunSearch( form ) print htmlPage