diff --git a/call.cgi b/call.cgi index 61e9ae4..da2b11e 100755 --- a/call.cgi +++ b/call.cgi @@ -25,19 +25,19 @@ if ip[2] == 116: prefix = "GRL" elif ip[2] == 117: prefix = "ML1" elif ip[2] == 118: prefix = "ML2" - elif ip[2] == 119: prefix = "HSJ" + elif ip[2] == 119: prefix = "IML" else: return ip_str - if prefix != "HSJ" and 151 <= ip[3] <= 150 + 49 or\ - prefix == "HSJ" and 151 <= ip[3] <= 150 + 63: + if prefix != "IML" and 151 <= ip[3] <= 150 + 49 or\ + prefix == "IML" and 151 <= ip[3] <= 150 + 63: return "%s-%02d" % (prefix, ip[3]-150) - if prefix != "HSJ" and 81 <= ip[3] <= 81 + 49 or\ - prefix == "HSJ" and 81 <= ip[3] <= 81 + 63: + if prefix != "IML" and 81 <= ip[3] <= 81 + 49 or\ + prefix == "IML" and 81 <= ip[3] <= 81 + 63: return "%s-%02d" % (prefix, ip[3]-80) if 220 <= ip[3] <= 220 + 5: - return "%s-K%02d" % (prefix, ip[3]-220) + return "%s-T%02d" % (prefix, ip[3]-220) if 226 <= ip[3] <= 226 + 5: - return "%s-K%02d" % (prefix, ip[3]-225) + return "%s-T%02d" % (prefix, ip[3]-225) else: return ip_str fr = datetime.strptime(form["date"].value + " " + form["from"].value, "%Y/%m/%d %H:%M") @@ -151,7 +151,7 @@ json.dump(lines, sys.stdout) else: - sys.path.append("/home/tkuro/.local/lib/python2.7/site-packages/") + sys.path.append("/home/tkuro/.local/lib/python3.9/site-packages/") from openpyxl import load_workbook from openpyxl.worksheet.table import Table, TableStyleInfo from openpyxl.styles import Alignment @@ -159,19 +159,21 @@ wb = load_workbook("./attendancebook_template.xlsx") - lines.sort(lambda x,y: cmp(x[4]+x[1],y[4]+y[1])) + lines.sort(key=lambda x: x[4]+x[1]) for room in ["GRL", "ML1", "ML2", "IML"]: wb.remove(wb[room+"出席表"]) if room in form: ws = wb.create_sheet(title = room+"出席表") ws.sheet_properties.pageSetUpPr.fitToPage = True if room == "IML": - prefix = "HSJ" + prefix = "IML" + table_prefix = "HSJ" else: prefix = room + table_prefix = room extract = [[host, str(student_no),logon[:5],logoff[-5:], name, reading, dep, pos] for host, logon, logoff, _, _, - student_no, name, reading, dep, pos in lines if host.startswith(prefix)] + student_no, name, reading, dep, pos in lines if host != None and host.startswith(prefix)] ws.column_dimensions["A"].width =9.0; ws.column_dimensions["B"].width =11.0; ws.column_dimensions["C"].width =6.0; ws.column_dimensions["D"].width =6.0; @@ -215,14 +217,14 @@ ws['G'+row].alignment = align # TODO need refactor: maybe it can be integrated else: stafflist.append(e[:-1]) prev = e[1] - tab = Table(displayName="StudentTable"+prefix, ref="A2:G"+str(ws.max_row)) + tab = Table(displayName="StudentTable"+table_prefix, ref="A2:G"+str(ws.max_row)) style = TableStyleInfo(name="TableStyleLight1", showFirstColumn=False, showLastColumn=False, showRowStripes=True, showColumnStripes=False) tab.tableStyleInfo = style ws.add_table(tab) ws.append([]) - ws.append(['合計', '=COUNTA(StudentTable'+prefix+'[学籍番号])', '人']) + ws.append(['合計', '=COUNTA(StudentTable'+table_prefix+'[学籍番号])', '人']) ws.append([]) ws.append(["スタッフ"]) ws.append(["ホスト名", "ユーザ名", "開始", "終了", "名前", "よみ", "所属"]) @@ -236,7 +238,7 @@ ws['G'+row].alignment = align # TODO need refactor: maybe it can be integrated if ws.max_row == staff_start: ws.append(["-","-","-","-","-","-","-"]) - tab = Table(displayName="StaffTable"+prefix, ref="A"+str(staff_start)+":G"+str(ws.max_row)) + tab = Table(displayName="StaffTable"+table_prefix, ref="A"+str(staff_start)+":G"+str(ws.max_row)) style = TableStyleInfo(name="TableStyleLight2", showFirstColumn=False, showLastColumn=False, showRowStripes=True, showColumnStripes=False) tab.tableStyleInfo = style @@ -249,9 +251,8 @@ wb.save(tname) with open(tname,"rb") as f: finfo = os.stat(tname) - print("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") - print('Content-Disposition: attachment; filename="'+filename+'"') - print('Content-Length: '+str(finfo.st_size)) - print("") - sys.stdout.write(f.read()) + sys.stdout.buffer.write(b"Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\n") + sys.stdout.buffer.write(('Content-Disposition: attachment; filename="'+filename+'"\n').encode("ascii")) + sys.stdout.buffer.write(('Content-Length: '+str(finfo.st_size)+"\n\n").encode("ascii")) + sys.stdout.buffer.write(f.read())