import glob #from athletemodel import put_to_store, get_names_from_store import athletemodel #the_files = ["sarah2.txt", "james2.txt", "mikey2.txt", "julie2.txt", ] the_files = glob.glob("../data/*2.txt") data = athletemodel.put_to_store(the_files) for one in data: print(data[one].name+":"+str(data[one])) print(athletemodel.get_names_from_store())
#! /usr/bin/env python3 import glob import athletemodel import yate data_files = glob.glob("data/*.txt") athletes = athletemodel.put_to_store(data_files) print(yate.start_response()) print(yate.include_header("Coach Kelly's List of Athletes")) print(yate.start_form("generate_timing_data.py")) print(yate.para("Select an athlete from the list to work with:")) for each_athlete in athletes: print(yate.radio_button("which_athlete", athletes[each_athlete].name)) print(yate.end_form("Select")) print(yate.include_footer({"Home": "/index.html"}))
import sqlite3 connect = sqlite3.connect("coachdata.sqlite") cursor = connect.cursor() import glob files = glob.glob("../data/*2.txt") import athletemodel athletes = athletemodel.put_to_store(files) for each_athletes in athletes: name = athletes[each_athletes].name dob = athletes[each_athletes].dob cursor.execute("insert into athletes(name, dob) values(?, ?)", (name, dob)) connect.commit() cursor.execute("select id from athletes where name=? and dob=?", (name, dob)) athlete_id = cursor.fetchone()[0] for time in athletes[each_athletes].clean_data: cursor.execute("insert into timing_data(athlete_id, value) values(?, ?)", (athlete_id, time)) connect.commit() connect.close()
#创建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'}))
#! /usr/bin/python3 import athletemodel import yate import glob data_files = glob.glob("data/*.txt") athletes = athletemodel.put_to_store(data_files) print(yate.start_response()) print(yate.include_header("Coach Kelly's List of Athletes")) print(yate.start_form("generate_timing_data.py")) print(yate.para("Select an athlete from the list to work with:")) for each_athlete in athletes: print(yate.radio_button("which_athlete", athletes[each_athlete].name)) print(yate.end_form("Select")) print(yate.include_footer({"Home": "/index.html"}))
import athletemodel import yate import glob #this module lets you query your operating system for a list of file names data_files = glob.glob( "data/*.txt" ) #creating a list of the file names of type '*.txt' within folder 'data' athletes = athletemodel.put_to_store( data_files) #creating a dictionary of athletes from the list of data files print(yate.start_response()) #always start with a Content-type line print(yate.include_header( "Coach Kelly's List of Athletes")) #provide a title for the page print( yate.start_form("generate_timing_data.py") ) #start generating the form providing the name of the server-side program to link to. print(yate.para("Select an athlete from the list to work with:")) for each_athlete in athletes: #generate a radio button for each athlete print(yate.radio_button("which_athlete", athletes[each_athlete].name)) print(yate.end_form( "Select")) # end the form with a custom text for the submit button print(yate.include_footer({"Home": "/index.html" })) # a link to go back to the Home page
from athletemodel import put_to_store, get_from_store # 선수들의 데이터가 담긴 파일 목 the_files = ["../data/james.txt", "../data/julie.txt", "../data/mikey.txt", "../data/sarah.txt"] # 선수들의 파일 목록을 읽어서 각 파일의 내용을 AthleteList 객체로 변환 후, 이름을 key로 하여 전체를 하나의 dictionary 객체로 만들고, # 이를 pickle로 저장하는 함수 put_to_store(the_files) # 저장된 pickle에서 dictionary 객체를 불러와 athletes 변수에 저장 athletes = get_from_store() # 확인 용 출력 print(athletes) print(athletes['Julie Jones'].clean_data) print(athletes['Julie Jones'].top3) # 생일 출력하기 for each in athletes: print(athletes[each].name + ' ' + athletes[each].dob)
name TEXT NOT NULL, dob DATE NOT NULL) """) cursor.execute(""" CREATE TABLE timing_data( athlete_id INTEGER NOT NULL, value TEXT NOT NULL, FOREIGN KEY (athlete_id) REFERENCES athletes) """) files = None if os.path.exists("data/james.txt"): files = glob.glob("data/*.txt") if os.path.exists("../data/james.txt"): files = glob.glob("../data/*.txt") plays = athletemodel.put_to_store(files) for athlete_name in plays: name = plays[athlete_name].name dob = plays[athlete_name].dob cursor.execute("INSERT INTO athletes (name, dob) VALUES (? ,?)", (name, dob)) cursor.execute("select last_insert_rowid() from athletes") athlete_id = cursor.fetchone()[0] for timing_data in plays[athlete_name].clean_data: cursor.execute( "INSERT INTO timing_data (athlete_id, value) VALUES (? ,?)", (athlete_id, timing_data)) cursor.execute("SELECT * FROM athletes WHERE name = ?", ("James Lee", )) print(cursor.fetchall(), file=sys.stderr)
from athletemodel import put_to_store the_files = ["Sarah.txt", "James.txt"] data = put_to_store(the_files) print(data)