import cgi import cgitb #开启浏览器追踪 cig 信息 import athletemodel import YATE cgitb.enable() #cgitb #开启浏览器追踪 cig 信息 #athletes = athletemodel.get_from_store()#从pickle获取信息 form_data = cgi.FieldStorage() #获取请求的form的内容 #athlete_name = form_data['which_athlete'].value#从内容中得到请求控件name 为:which_athlete的值 athlete_id = form_data['which_athlete'].value # radio 在 yate.py 里重写了 athletes = athletemodel.get_athlete_from_id(athlete_id) print(YATE.start_response()) print(YATE.include_header("NUAC's Timing Data")) print( YATE.header('Althlete:' + athletes['Name'] + ' ,DOB: ' + athletes['DOB'] + '.')) print(YATE.para('The top times for this athlete are:')) print(YATE.u_list(athletes['top3'])) print( YATE.para("The entire set of timing data is:" + str(athletes['data']) + " (duplicates removed).")) print( YATE.include_footer({ 'Home': '/index.html', 'Select another athlete': 'generate_list.py' }))
#创建ath_list页面,这里有运动员的列表 import athletemodel import YATE import glob #可以获取文件列表 data_files = glob.glob("data/*.txt")#获取data 目录下的所有txt athletes = athletemodel.put_to_store(data_files)#将txt的内容存入 pickle,并返回字典 print(YATE.start_response()) print(YATE.include_header('List of Athletes')) #web的头 print(YATE.start_form('generate_timing_data.py'))#需要进一步处理表单的表单,即submit后处理请求的页面 print(YATE.para('Select an Athlete!')) for each_ath in athletes: print(YATE.radio_button('which_athlete',athletes[each_ath].name))#which_athlete是radiobutton的name属性, print(YATE.end_form('Select')) print(YATE.include_footer({'Home':'/index.html'}))
import cgi import cgitb #开启浏览器追踪 cig 信息 import athletemodel import YATE cgitb.enable()#cgitb #开启浏览器追踪 cig 信息 athletes = athletemodel.get_from_store()#从pickle获取信息 form_data = cgi.FieldStorage()#获取请求的form的内容 athlete_name = form_data['which_athlete'].value#从内容中得到请求控件name 为:which_athlete的值 print(YATE.start_response()) print(YATE.include_header('Timing Data')) print(YATE.header('Althlete:'+athlete_name+' ,DOB: ' +athletes[athlete_name].dob+'.')) print(YATE.para('The top times for this athlete are:')) print(YATE.u_list(athletes[athlete_name].top3))#这里需要在top3方法那加入@property将类方法表现得像个类属性 print(YATE.include_footer({'Home':'/index.html', 'Select another athlete':'generate_list.py'}))
import cgi import os import time import sys import YATE import sqlite3 print (YATE.start_response('text/plain')) addr = os.environ['REMOTE_ADDR'] host = os.environ['REMOTE_HOST'] method = os.environ['REQUEST_METHOD'] cur_time = time.asctime(time.localtime()) print (host+", "+addr+", "+cur_time+": "+method, file=sys.stderr) form_data = cgi.FieldStorage() the_id = form_data['Athlete'].value the_time = form_data['Time'].value connection = sqlite3.connect('coachdata.sqlite') cursor = connection.cursor() cursor.execute("INSERT INTO timing_data (athlete_id,value) VALUES (?,?)", (the_id, the_time)) """ for each_form_item in form.keys(): print (each_form_item + '->' + form[each_form_item].value, end=' ', file=sys.stderr) print (file = sys.stderr) #在标准错误输出上换行 """ connection.commit() connection.close()
import cgi import json import athletemodel import YATE import sys #athletes = athletemodel.get_from_store() form_data = cgi.FieldStorage() athlete_name = form_data['which_athlete'].value athletes = athletemodel.get_athlete_from_id(athlete_name) print(athletes, file=sys.stderr) print(YATE.start_response('application/json')) #print(json.dumps(athletes[athlete_name].as_dict)) print(json.dumps(athletes))
import cgi import os import time import sys import YATE import sqlite3 print(YATE.start_response('text/plain')) addr = os.environ['REMOTE_ADDR'] host = os.environ['REMOTE_HOST'] method = os.environ['REQUEST_METHOD'] cur_time = time.asctime(time.localtime()) print(host + ", " + addr + ", " + cur_time + ": " + method, file=sys.stderr) form_data = cgi.FieldStorage() the_id = form_data['Athlete'].value the_time = form_data['Time'].value connection = sqlite3.connect('coachdata.sqlite') cursor = connection.cursor() cursor.execute("INSERT INTO timing_data (athlete_id,value) VALUES (?,?)", (the_id, the_time)) """ for each_form_item in form.keys(): print (each_form_item + '->' + form[each_form_item].value, end=' ', file=sys.stderr) print (file = sys.stderr) #在标准错误输出上换行 """ connection.commit() connection.close()
import athletemodel import YATE import json import cgitb #开启浏览器追踪 cig 信息 cgitb.enable()#cgitb #开启浏览器追踪 cig 信息 ath_names = athletemodel.get_namesID_from_store() print(YATE.start_response('application/json')) print(json.dumps(sorted(ath_names)))
#创建ath_list页面,这里有运动员的列表 import athletemodel import YATE import glob #可以获取文件列表 data_files = glob.glob("data/*.txt") #获取data 目录下的所有txt athletes = athletemodel.put_to_store(data_files) #将txt的内容存入 pickle,并返回字典 print(YATE.start_response()) print(YATE.include_header('List of Athletes')) #web的头 print( YATE.start_form('generate_timing_data.py')) #需要进一步处理表单的表单,即submit后处理请求的页面 print(YATE.para('Select an Athlete!')) for each_ath in athletes: print(YATE.radio_button( 'which_athlete', athletes[each_ath].name)) #which_athlete是radiobutton的name属性, print(YATE.end_form('Select')) print(YATE.include_footer({'Home': '/index.html'}))
import cgi import cgitb #开启浏览器追踪 cig 信息 import athletemodel import YATE cgitb.enable()#cgitb #开启浏览器追踪 cig 信息 #athletes = athletemodel.get_from_store()#从pickle获取信息 form_data = cgi.FieldStorage()#获取请求的form的内容 #athlete_name = form_data['which_athlete'].value#从内容中得到请求控件name 为:which_athlete的值 athlete_id = form_data['which_athlete'].value # radio 在 yate.py 里重写了 athletes = athletemodel.get_athlete_from_id(athlete_id) print(YATE.start_response()) print(YATE.include_header("NUAC's Timing Data")) print(YATE.header('Althlete:'+athletes['Name']+' ,DOB: ' +athletes['DOB']+'.')) print(YATE.para('The top times for this athlete are:')) print(YATE.u_list(athletes['top3'])) print(YATE.para("The entire set of timing data is:"+str(athletes['data'])+ " (duplicates removed).")) print(YATE.include_footer({'Home':'/index.html', 'Select another athlete':'generate_list.py'}))
import cgi import cgitb #开启浏览器追踪 cig 信息 import athletemodel import YATE cgitb.enable() #cgitb #开启浏览器追踪 cig 信息 athletes = athletemodel.get_from_store() #从pickle获取信息 form_data = cgi.FieldStorage() #获取请求的form的内容 athlete_name = form_data[ 'which_athlete'].value #从内容中得到请求控件name 为:which_athlete的值 print(YATE.start_response()) print(YATE.include_header('Timing Data')) print( YATE.header('Althlete:' + athlete_name + ' ,DOB: ' + athletes[athlete_name].dob + '.')) print(YATE.para('The top times for this athlete are:')) print(YATE.u_list( athletes[athlete_name].top3)) #这里需要在top3方法那加入@property将类方法表现得像个类属性 print( YATE.include_footer({ 'Home': '/index.html', 'Select another athlete': 'generate_list.py' }))
import YATE import cgitb cgitb.enable() print (YATE.start_response('text/html')) print (YATE.do_form('add_timing_data.py',['TimeValue'],text='Send'))