#!/usr/bin/python3 def printHTML(str): print("
====|%s|" % str) def FindString(x, str1, str2): pos1 = x.find(str1) pos2 = x.find(str2, pos1+1) if( str2 == ''): pos2 = len(x) offset = len(str1) if( pos1 > -1 and pos2 > -1): haha = x[pos1+offset:pos2].strip() #printHTML(haha) return haha else: return '404' isotope = '404' preacc = '404' inflector = '404' LEB_Voltage = '404' LEB_Feedback = '404' tandam_pot = '404' beam_energy = '404' charge = '404' charge_frac = '404' beta = '404' analysisMagnet = '404' beamLine = '404' switchingMagnet = '404' file = open("beam.txt") print("Content-type:text/html\r\n\r\n") print('') print('') for x in file: #print("
" + x) if( isotope == '404') : isotope = FindString(x, 'nucleus is', 'and') if( preacc == '404'): preacc = FindString(x, 'is at', 'kV') if( inflector == '404'): inflector = FindString(x, 'magnet is', 'A') if( LEB_Voltage == '404'): LEB_Voltage = FindString(x, 'Voltage is', 'V') if( LEB_Feedback == '404'): LEB_Feedback = FindString(x, 'Feedback is', 'V') if( tandam_pot == '404'): tandam_pot = FindString(x, 'Potential =', 'MV') if( beam_energy == '404'): beam_energy = FindString(x, 'Energy =', 'MeV') if( charge == '404'): charge = FindString(x, 'charge=', 'Fraction') if( charge_frac == '404'): charge_frac = FindString(x, 'Fraction =', 'Beta') if( beta == '404'): beta = FindString(x, 'Beta =', '') if( analysisMagnet == '404'): analysisMagnet = FindString(x, 'field is', 'G') if( beamLine == '404'): beamLine = FindString(x, '\"', '\"') if( switchingMagnet == '404'): switchingMagnet = FindString(x, 'Current is', 'A') #print('

===================

') print("Isotope: " + isotope.upper() + "
") print("PreAcceleration: " + preacc + " kV
") print("Inflector: " + inflector + " A
") print("LEB Voltage: " + LEB_Voltage + " V
") print("LEB feedback: " + LEB_Feedback + " V
") print("Tandem Pot.: " + tandam_pot + " MV
") print("Beam Energy: " + beam_energy + " MeV
") print("Beam Charge: " + charge + "
") print("Frac. Charge: " + charge_frac + "
") print("Beta: " + beta + "
") print("Analyzing Magnet: " + analysisMagnet + " G
") print("Beam Line: " + beamLine + "
") print("Switching Magnet: " + switchingMagnet + " A
") # #file = open("test.txt") # #for x in file: # print("
") # print(x) # #print('

===================

') print('') print('')