About <<
Previous Next >> Tasks
list
from browser import html, document, ajax
# 設定學員資料的 URL
url = "https://mde.tw/list/2b.txt"
# 定義載入資料的回呼函式
def on_data(response):
if response.status != 200:
print("資料載入失敗,請檢查網絡或 URL 是否正確")
return
data = response.text.strip().splitlines()
if not data or len(data) < 2:
print("學員資料格式異常,請檢查來源文件")
return
all_stud = data[1:] # 跳過標題行
print(f"總共有 {len(all_stud)} 名學員")
# 取得網頁中的 brython_div1
brython_div1 = document["brython_div1"]
brython_div1.clear()
# 插入標題
title = html.H3("學員 GitHub 作業列表", Class="title")
brython_div1 <= title
# 建立無序清單
ul = html.UL(Class="student-list")
for i, student in enumerate(all_stud, 1):
student_data = student.split(None, 1) # 只分割一次,確保學號和 GitHub 帳號正確
if len(student_data) < 2:
continue
student_id, github_account = student_data # 取得學號 和 GitHub 帳號
# 創建學號的超連結,指向 GitHub Repo
student_link = html.A(student_id, href=f"https://github.com/mdecd2025/hw-{github_account}", target="_blank", Class="student-id-link")
# 創建 repo 的超連結,指向 GitHub.io
repo_link = html.A("repo", href=f"https://mdecd2025.github.io/hw-{github_account}", target="_blank", Class="repo-link")
# 建立列表項目,格式為 學號 (repo)
list_item = html.LI()
list_item <= student_link # 超連結學號
list_item <= " (" # 在學號和 repo 之間加上括號
list_item <= repo_link # 超連結 repo
list_item <= ")" # 關閉括號
ul <= list_item # 加入清單
brython_div1 <= ul
# 發送 AJAX 請求
request = ajax.ajax()
request.bind('complete', on_data)
request.open('GET', url, True)
request.send()
# 加入 CSS 樣式
style = html.STYLE("""
.title {
font-size: 24px;
font-weight: bold;
text-align: center;
margin-bottom: 15px;
}
.student-list {
list-style-type: none;
padding: 0;
text-align: center;
}
.student-list li {
font-size: 18px;
margin: 5px 0;
}
.student-id-link {
color: #0366d6;
text-decoration: none;
font-weight: bold;
}
.student-id-link:hover {
text-decoration: underline;
}
.repo-link {
color: #28a745;
text-decoration: none;
font-weight: bold;
}
.repo-link:hover {
text-decoration: underline;
}
""")
document <= style
全部學員的作業網址
from browser import html, document, ajax
# 設定學員資料的 URL
url = "https://mde.tw/list/2b.txt"
# 定義載入資料的回呼函式
def on_data(response):
if response.status != 200:
print("資料載入失敗,請檢查網絡或 URL 是否正確")
return
data = response.text.strip().splitlines()
if not data or len(data) < 2:
print("學員資料格式異常,請檢查來源文件")
return
all_stud = data[1:] # 跳過標題行
print(f"總共有 {len(all_stud)} 名學員")
# 要顯示的學號列表
target_ids = ["41223206", "41223215", "41223226", "41223227", "41223228", "41223235"]
# 取得網頁中的 brython_div1
brython_div1 = document["brython_div1"]
brython_div1.clear()
# 插入標題
title = html.H3("學員 GitHub 作業列表", Class="title")
brython_div1 <= title
# 建立無序清單
ul = html.UL(Class="student-list")
for student in all_stud:
student_data = student.split(None, 1) # 只分割一次,確保學號和 GitHub 帳號正確
if len(student_data) < 2:
continue
student_id, github_account = student_data # 取得學號 和 GitHub 帳號
# 只顯示目標學號
if student_id not in target_ids:
continue
# 創建學號的超連結,指向 GitHub Repo
student_link = html.A(student_id, href=f"https://github.com/mdecd2025/hw-{github_account}", target="_blank", Class="student-id-link")
# 創建 repo 的超連結,指向 GitHub.io
repo_link = html.A("repo", href=f"https://mdecd2025.github.io/hw-{github_account}", target="_blank", Class="repo-link")
# 建立列表項目,格式為 學號 (repo)
list_item = html.LI()
list_item <= student_link # 超連結學號
list_item <= " (" # 在學號和 repo 之間加上括號
list_item <= repo_link # 超連結 repo
list_item <= ")" # 關閉括號
ul <= list_item # 加入清單
brython_div1 <= ul
# 發送 AJAX 請求
request = ajax.ajax()
request.bind('complete', on_data)
request.open('GET', url, True)
request.send()
# 加入 CSS 樣式
style = html.STYLE("""
.title {
font-size: 24px;
font-weight: bold;
text-align: center;
margin-bottom: 15px;
}
.student-list {
list-style-type: none;
padding: 0;
text-align: center;
}
.student-list li {
font-size: 18px;
margin: 5px 0;
}
.student-id-link {
color: #0366d6;
text-decoration: none;
font-weight: bold;
}
.student-id-link:hover {
text-decoration: underline;
}
.repo-link {
color: #28a745;
text-decoration: none;
font-weight: bold;
}
.repo-link:hover {
text-decoration: underline;
}
""")
document <= style
組員連結
製作影片
ipv6製作影片
# 學員編號列表 (您提供的編號)
student_numbers = [
"40923137", "41023114", "41023205", "41023206", "41023210", "41023213", "41023215", "41023216",
"41023218", "41023232", "41023237", "41071202", "41071203", "41071204", "41223201", "41223202",
"41223203", "41223205", "41223206", "41223207", "41223208", "41223209", "41223210", "41223211",
"41223212", "41223214", "41223215", "41223216", "41223217", "41223218", "41223219", "41223220",
"41223221", "41223222", "41223223", "41223224", "41223225", "41223226", "41223227", "41223228",
"41223229", "41223230", "41223231", "41223232", "41223233", "41223234", "41223235", "41223236",
"41223237", "41223239", "41223240", "41223242", "41223243", "41223244", "41223245", "41223246",
"41223247", "41223248", "41223249", "41223250", "41223251", "41223252", "41223253", "41271217",
"41271236", "41271237"
]
# 使用學號生成連結
for i, student_id in enumerate(student_numbers, 1): # 從 1 開始計數
# 格式化序號為三位數 (001-066)
student_num = f"{i:03d}"
# 完整的 IPv6 位址
full_ip = f"{base_ip}{student_num}" # 使用學號的最後三個數字生成IPv6地址
# 完整的 URL
url = f"http://[{full_ip}]:{port}"
# 建立連結元素
link = html.A(f"{student_id}", href=url, target="_blank") # 顯示學員的學號
# 每個連結後加入換行
div <= link
div <= html.BR()
全學員ipv6列表
About <<
Previous Next >> Tasks