Ejemplo n.º 1
0
 def saveData(self, stud_number=None, stud_name=None, \
                 school_dept=None, major=None, expt_salary=None):
     '''
     # 以 append 附加的方式將資料存入檔案, 以逗點隔開
     檔案 = open("c1w10out.txt", 'a', encoding="utf-8")
     內容 = str(stud_number)+","+str(stud_name)+","\
     +str(school_dept)+","+str(major)+','+str(expt_salary)+"\n"
     檔案.write(內容)
     檔案.close()
     '''
     # 改為將資料透過 pybean 存入資料庫
     library = Store(SQLiteWriter(SQLite_data_dir+"/database.sqlite", frozen=False))
     # 動態建立 student 資料表
     student = library.new("student")
     # 改為以 pybean 儲存資料
     student.stud_number = stud_number
     student.stud_name = stud_name
     student.school_dept = school_dept
     student.major = major
     student.expt_salary = expt_salary
     # 儲存資料表內容
     library.save(student)
     # 配合 pybean 0.2.1 將 commit 移出, save 與 delete 必須要配合 commit 才能更新資料庫
     library.commit()
     # 設法改為 Mako based
     return str(stud_number)+","+str(stud_name)+","\
     +str(school_dept)+","+str(major)+','+str(expt_salary)+", 已經存檔"
Ejemplo n.º 2
0
    def doUpdate(self, id=None, stud_number=None, stud_name=None, \
                    school_dept=None, major=None, expt_salary=None, itemperpage=9, page=1):
        個人資料 = []
        資料計數 = 0
        # 以下改為以 pybean 儲存資料
        library = Store(SQLiteWriter(SQLite_data_dir+"/database.sqlite", frozen=False))
        # 動態建立 student 資料表
        student = library.new("student")

        # 以 find_one 找出所要更新的一筆資料
        # 配合 pybean 0.2.1 將 uuid 改為 id, 且將 UUID(uuid).bytes 改為 id
        更新資料 = library.find_one("student","id=?",[id])
        # 是否會發生更新資料為空的情況?
        if 更新資料 == None:
            outString = "沒有資料"
            return outString
        # 將更新資料存入 pybean
        更新資料.stud_number = stud_number
        更新資料.stud_name = stud_name
        更新資料.school_dept = school_dept
        更新資料.major = major
        更新資料.expt_salary = expt_salary
        # 儲存資料表內容
        library.save(更新資料)
        # 配合 pybean 0.2.1 將 commit 移出, save 與 delete 必須要配合 commit 才能更新資料庫
        library.commit()
        # 設法從資料庫中擷取所有資料, 以得到個人資料數列
        for 資料 in library.find("student","1"):
            學號 = 資料.stud_number
            姓名 = 資料.stud_name
            科系 = 資料.school_dept
            專長 = 資料.major
            薪水 = 資料.expt_salary
            # 配合 pybean 0.2.1 將 uuid 改為 id, 且將 UUID(uuid).bytes 改為 id
            更新連結 = "<a href=\"updateForm?id="+str(資料.id)+"\">"+學號+"</a>"
            # 增加更新與刪除連結
            #個人資料.append([更新連結,姓名,科系,專長,薪水])
            更新 = "<a href=\"updateForm?id="+str(資料.id)+"\">更新</a>"
            刪除 = "<a href=\"deleteForm?id="+str(資料.id)+"\">刪除</a>"
            個人資料.append([更新連結,姓名,科系,專長,薪水,更新,刪除])
        #
        # 根據數列中各 tuple 中的學號(亦即 key data[0])進行排序
        # 個人資料排列後, 必須加以指定成變數, 否則個人資料的內容排序後並未改變
        個人資料 = sorted(個人資料, key=lambda data: data[0], reverse=True)
        #print(個人資料)
        # 改用 HTML 進行資料列印
        #outString = self.htmlList(個人資料)
        totalitem = library.count("student")
        outString = self.pageList(個人資料,totalitem,itemperpage,page)
        return outString
Ejemplo n.º 3
0
    mylist = []
    # finallist 為最後擷取出來的資料內容
    finallist = []
    # 分別取得檔案名稱
    for filename in find_files('./', '*.txt'):
        # we go through all the files, and read file content in to my list
        mylist = read_lines(filename)
        # mylist 為各檔案中的所有資料
        # 取各檔案的各行內容, mylist[myindex]
        for myindex in range(len(mylist)):
            for lineindex in range(len(mylist[myindex])):
                # yes we print line by line for each file
                mycolumn = ((mylist[myindex][lineindex]).rstrip()).split('\t')
                # only list the first column is digit
                if mycolumn[0].isdigit():
                    #mycolumn[6] 為學號
                    # mycolumn[8] 為成績
                    course_title = filename.split('\\')[0][2:]
                    exam_title = filename.split('\\')[1]
                    # 動態建立 book 資料表
                    score = library.new("score")
                    score.title = course_title
                    score.exam = exam_title
                    score.student = mycolumn[6]
                    score.points = mycolumn[8]
                    library.save(score)
                    library.commit()
                    finallist.append(
                        [course_title, exam_title, mycolumn[6], mycolumn[8]])
                    #print(course_title,":", exam_title, ":", mycolumn[6],":",mycolumn[8])
Ejemplo n.º 4
0
    finallist = []
    # 分別取得檔案名稱
    for filename in find_files('./', '*.txt'):
        # we go through all the files, and read file content in to my list
        mylist = read_lines(filename)
        # mylist 為各檔案中的所有資料
        # 取各檔案的各行內容, mylist[myindex]
        for myindex in range(len(mylist)):
            for lineindex in range(len(mylist[myindex])):
                # yes we print line by line for each file
                mycolumn = ((mylist[myindex][lineindex]).rstrip()).split('\t')
                # only list the first column is digit
                if mycolumn[0].isdigit():
                    #mycolumn[6] 為學號
                    # mycolumn[8] 為成績
                    course_title = filename.split('\\')[0][2:]
                    exam_title = filename.split('\\')[1]
                    # 動態建立 book 資料表
                    score = library.new("score")
                    score.title = course_title
                    score.exam = exam_title
                    score.student = mycolumn[6]
                    score.points = mycolumn[8]
                    library.save(score)
                    library.commit()
                    finallist.append([course_title, exam_title, mycolumn[6],mycolumn[8]])
                    #print(course_title,":", exam_title, ":", mycolumn[6],":",mycolumn[8])
#@nonl
#@-node:amd_yen.20130501090735.2391:@shadow c2/get_score.py
#@-leo
Ejemplo n.º 5
0
# 利用 for 迴圈逐一進行分組資料列印
for i in range(0, total):
    學生分組資料.append(st_array[i][0] + st_array[i][1].strip() + "," +
                  str(seat2(10)[i][0]) + "," + str(seat2(10)[i][1]) + "," +
                  str(order))
    # 以 pybean 儲存資料, 若非在每次存檔之前都執行下兩行,  資料庫只會儲存最後一筆資料 (會進行資料覆蓋?)
    library = Store(SQLiteWriter("student.sqlite", frozen=False))
    # 動態建立 student 資料表
    grouping = library.new("st908306")
    grouping.stud_number = st_array[i][0]
    grouping.stud_name = st_array[i][1].strip()
    grouping.col = seat2(10)[i][0]
    grouping.row = seat2(10)[i][1]
    grouping.grp = order
    # 儲存資料表內容
    library.save(grouping)
    if (i % num == 0):
        fileout2.write("第" + str(order) + "組:------\n")
    count = count + 1
    # 寫出學號, 姓名
    fileout2.write(st_array[i][0] + st_array[i][1].strip())
    # 寫出座號, seat2 為電腦教室編號, seat 則為 spread sheet 上的編號
    fileout2.write(" - 座號:" + str(seat2(10)[i]) + "\n")
    st_dict[seat2(10)[i]] = str(
        order) + " " + st_array[i][0] + " " + st_array[i][1].strip()
    if ((i + 1) % (num) == 0):
        order = order + 1
檔案標頭 = '''<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
</head>
Ejemplo n.º 6
0
count = 0
 
# 利用 for 迴圈逐一進行分組資料列印
for i in range(0,total):
    學生分組資料.append(st_array[i][0]+st_array[i][1].strip()+","+str(seat2(10)[i][0])+","+str(seat2(10)[i][1])+","+str(order))
    # 以 pybean 儲存資料, 若非在每次存檔之前都執行下兩行,  資料庫只會儲存最後一筆資料 (會進行資料覆蓋?)
    library = Store(SQLiteWriter("student.sqlite", frozen=False))
    # 動態建立 student 資料表
    grouping = library.new("st908306")
    grouping.stud_number = st_array[i][0]
    grouping.stud_name = st_array[i][1].strip()
    grouping.col= seat2(10)[i][0]
    grouping.row = seat2(10)[i][1]
    grouping.grp = order
    # 儲存資料表內容
    library.save(grouping)
    if(i%num == 0):
        fileout2.write("第"+str(order)+"組:------\n")
    count = count + 1
    # 寫出學號, 姓名
    fileout2.write(st_array[i][0]+st_array[i][1].strip())
    # 寫出座號, seat2 為電腦教室編號, seat 則為 spread sheet 上的編號
    fileout2.write(" - 座號:"+str(seat2(10)[i])+"\n")
    st_dict[seat2(10)[i]] = str(order)+" "+st_array[i][0]+" "+st_array[i][1].strip()
    if((i+1)%(num) == 0):
        order = order + 1
檔案標頭 = '''<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
</head>
<body>
Ejemplo n.º 7
0
from pybean import Store, SQLiteWriter

library = Store(SQLiteWriter(":memory:", frozen=False))

book = library.new("book")
book.title = "Boost development with pybean"
book.author = "Charles Xavier"
library.save(book)

for book in library.find("book", "author like ?", ["Charles Xavier"]):
    print book.title

library.delete(book)
library.commit()