背景:
很多小型的的培訓(xùn)學(xué)校通常涉及到幾位到十幾位老師與幾十名到上百名學(xué)生的課程安排谷饿。從成本出發(fā),聘請專業(yè)人員去編寫由于管理的軟件是非常不現(xiàn)實(shí)的妈倔〔┩叮可行可靠的做法通常是使用個(gè)人電腦office中的excel之類的軟件來進(jìn)行管理。
由于上述這些教育機(jī)構(gòu)的主管沒有IT相關(guān)背景盯蝴,同時(shí)由于office軟件的局限毅哗,一些能夠增進(jìn)管理和服務(wù)水平的IT方案往往不了解听怕,也無法采用。
設(shè)想下面的場景:學(xué)校采取小班授課虑绵,常常是一對一或者一對N的形式尿瞭。對于有經(jīng)驗(yàn)的工作人員,使用excel翅睛,只要規(guī)模不是超大声搁,完全沒有問題。甚至是面對老師學(xué)生請假捕发,調(diào)課等等情況的加入也能夠處理得妥貼疏旨。同時(shí),這項(xiàng)工作還要面臨很多與學(xué)生家長的溝通扎酷。尤其是在因?yàn)榉ǘ倨陂芾浴⒁驗(yàn)椴∈录佟⒁驗(yàn)槠渌酝馇闆r導(dǎo)致課程時(shí)間變更法挨。這個(gè)情況下谁榜,學(xué)校方面會面臨大量與家長們溝通。比如在微信群中家長會一個(gè)接一個(gè)與校方確認(rèn)更新的課表坷剧,每一次詢問校方都要專門去查詢并回應(yīng)惰爬。這樣即影響了工作效率,也耽誤了時(shí)間惫企。那么有沒有辦法在不增加校方本身的工作量的基礎(chǔ)上,能夠隨時(shí)將最新的課程安排發(fā)布到網(wǎng)絡(luò)上陵叽,家長和學(xué)生老師如果只需要確認(rèn)課程安排的話狞尔,隨時(shí)瀏覽某一個(gè)網(wǎng)頁就可以。校方和工作人員則可以把更多的精力放到其它事情上面巩掺。
解決方案:
很多商業(yè)軟件都會提供上述功能偏序,但我們在這里尋求的是零成本提供這個(gè)解決方案。下面我來使用一個(gè)模擬的場景來事例這個(gè)解決方案是如何一步一步實(shí)現(xiàn)這個(gè)功能的胖替。同時(shí)在最后會展示工作人員如何通過僅僅一步操作就將信息更新到網(wǎng)絡(luò)上供隨時(shí)查閱研儒。
準(zhǔn)備
我假設(shè)下面是一個(gè)學(xué)校的課程安排excel表格,里面會看到課程独令、老師端朵、學(xué)生、上課時(shí)間燃箭、上課地點(diǎn)等信息冲呢。
數(shù)據(jù)導(dǎo)出
我們首先將數(shù)據(jù)從上面的excel表格中導(dǎo)出到本地的json文件。這里我們使用python語言和以下方法:
Python語言我們可以免費(fèi)下載和安裝到本地計(jì)算機(jī)中招狸。
import pandas as pd
# Load the Excel file into a pandas DataFrame
df = pd.read_excel('./schoolSchedual.xls')
# Remove completely blank rows
df_cleaned = df.dropna(how='all')
# Extract the titles from the first row
titles = df_cleaned.iloc[0].to_dict()
# Use titles as keys and subsequent rows as values
records = []
for index, row in df_cleaned.iterrows():
if index > 0: # Skip the first row since it contains titles
# Create a record dictionary with the correct titles
record = {title: row[key] for key, title in titles.items()}
records.append(record)
# Convert the list of record dictionaries to a JSON string
json_data = pd.Series(records).to_json(orient='records', indent=4)
# Output the JSON data to a file
json_output_path = './schedule.json'
with open(json_output_path, 'w') as json_file:
json_file.write(json_data)
數(shù)據(jù)過濾
因?yàn)閷W(xué)校的內(nèi)部文件信息中包括學(xué)生姓名等信息敬拓,我們從保護(hù)隱私的角度出發(fā)不能將這些信息發(fā)布到網(wǎng)絡(luò)上邻薯。數(shù)據(jù)過濾的作用是將這些信息從導(dǎo)出的json中刪除,僅僅保留我們可以公開發(fā)布的消息乘凸。
因?yàn)槊恳晃粚W(xué)生都有自己唯一的學(xué)生編號厕诡,只有學(xué)校和學(xué)生及家長知道哪一個(gè)學(xué)生編號是自己。這樣學(xué)生家長可以通過顯示在網(wǎng)頁上的學(xué)生編號來核實(shí)孩子的課時(shí)安排营勤。
import json
# Path to the original JSON file
json_file_path = './schedule.json'
# Load the JSON data from the file
with open(json_file_path, 'r') as file:
data = json.load(file)
# Remove the first item from the data
data.pop(0)
# Remove the 'Student' key and its value from each remaining item
for item in data:
if 'Student' in item:
item.pop('Student')
# Path for the new JSON file
new_json_file_path = './updated_schedule.json'
# Save the updated data to the new JSON file
with open(new_json_file_path, 'w') as file:
json.dump(data, file, indent=4)
生成網(wǎng)頁
我們現(xiàn)在將上面過濾之后的json轉(zhuǎn)化為網(wǎng)頁文件:
from jinja2 import Environment, BaseLoader
# Load the JSON data from the generated file
with open('./updated_schedule.json', 'r') as json_file:
records = json.load(json_file)
# HTML template using Jinja2 syntax
html_template = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Schedule</title>
<style>
......
{% endfor %}
</tbody>
</table>
</body>
</html>
"""
# Initialize Jinja2 environment
env = Environment(loader=BaseLoader())
template = env.from_string(html_template)
# Extract titles for table headers
titles = records[0].keys()
# Render the HTML with the JSON data
html_output = template.render(titles=titles, records=records)
# Define the path for the HTML file
html_file_path = 'schoolSchedual.html'
# Save the rendered HTML to a file
with open(html_file_path, 'w') as file:
file.write(html_output)
發(fā)布網(wǎng)頁
在這里我們使用了可以免費(fèi)申請的GITHub木人。其中Github Page可以提供簡單的靜態(tài)網(wǎng)頁功能,并且完全免費(fèi)冀偶。
#!/bin/bash
#Set the path to your local GitHub Pages repository
REPO_PATH='/path/to/your/local/repo'
#Set the path to the HTML file you want to upload
HTML_FILE_PATH='/path/to/your/schoolSchedual.html'
#Set the commit message
COMMIT_MESSAGE='Update schoolSchedual.html'
#Change to the repository directory
cd "$REPO_PATH"
#Copy the HTML file to the repository
cp "$HTML_FILE_PATH" .
#Add all new and changed files to git
git add .
#Commit the changes
git commit -m "$COMMIT_MESSAGE"
#Push the changes to GitHub
git push origin main
查看網(wǎng)頁
現(xiàn)在就可以進(jìn)入瀏覽器檢查一下剛剛發(fā)布的更新課表了醒第。以下我使用個(gè)人的github網(wǎng)站作為例子:https://toronto-andrew.github.io/AndrewBlogger/others/schoolschedual.html
校方工作人員的“一鍵操作”
以上是這個(gè)解決方案的原理講解。這里介紹一下學(xué)校的工作人員如何“一鍵發(fā)布”課表信息的进鸠。由于本人的電腦是linux稠曼,見到的界面會有所不同,在windows電腦下的操作將很類似客年。
andrew@andrew-OptiPlex-Ubuntu:~/PycharmProjects/exportExcel$ publicSchedual2Web.sh schoolSchedual.xls