东南大学课表查询系统

社团作业,每人做了一个东南大学课表查询系统,不得不感叹,python确实厉害(那我还学MFC干什么。。)!

这是搜索的主窗体,用来获取用户输入的信息(search.py)。

import tkinter as tk
import tkinter.messagebox
from course import *
from tkinter import ttk
from table import *


#展示搜索界面
window = tk.Tk()
window.title('东南大学课表查询系统')
window.geometry('300x150')
window.resizable(False, False)


#学号或一卡通号
student_id = tk.StringVar()
student_id.set('')
label_student_id = tk.Label(window, text='一卡通号或学号:', justify=tkinter.RIGHT)
label_student_id.place(x=30, y=20, width=80, height=20)
entry_student_id = tk.Entry(window, width=80, textvariable=student_id)
student_id.set("213173182")
entry_student_id.place(x=120, y=20, width=110, height=20)


#学年
academic_year = tkinter.StringVar()
academic_year.set('')
label_academic_year = tk.Label(window, text='学年 学期:', justify=tkinter.RIGHT)
label_academic_year.place(x=40, y=50, width=80, height=20)
entry_academic_year = ttk.Combobox(window, width=80, textvariable=academic_year)
entry_academic_year['values'] = (
    "18-19-2",
    "18-19-1",
    "17-18-3",
    "17-18-2",
    "17-18-1",
    "16-17-3",
    "16-17-2",
    "16-17-1",
    "15-16-3",
    "15-16-2",
    "15-16-1",
    "14-15-3",
    "14-15-2",
    "14-15-1",
    "13-14-3",
    "13-14-2",
    "13-14-1",
    "12-13-3",
    "12-13-2",
    "12-13-1",
)
entry_academic_year.current(0)
entry_academic_year.place(x=120, y=50, width=110, height=20)


#按钮关联函数
def search():
    Student_id = entry_student_id.get()
    Academic_year = entry_academic_year.get()
    Course = parse_course(get_course(Student_id, Academic_year))
    get_table(Student_id, Academic_year, Course)

#创建按钮
button_click = tkinter.Button(window, text='查询', command=search)
button_click.place(x=110, y=90, width=80, height=30)


window.mainloop()

下面就是获取课程信息了,命名为course.py


import requests
from urllib.parse import urlencode
from bs4 import BeautifulSoup
import re


def get_course(card_no, academic_year):
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
    }
    data = {
        'queryStudentId': card_no,
        'queryAcademicYear': academic_year
    }
    url = "http://xk.urp.seu.edu.cn/jw_service/service/stuCurriculum.action?"+urlencode(data)
    response = requests.post(url=url, headers=headers)
    return response.text


def help(content):
    a = re.findall("<td.+rowspan=\".\">(.+)</td>", str(content))
    b = a[0].split("<br/>")
    print(b)
    if b.count("\xa0") == 0:
        return
    return b


def parse_course(html):
    bs = BeautifulSoup(html, 'html.parser')
    course = list()
    for i in bs.findAll("td", {"class": "line_topleft", "rowspan": "5", "align": "center"}):
        c = help(i)
        if c:
            course.append(c[:-1])
    for i in bs.findAll("td", {"class": "line_topleft", "rowspan": "2", "align": "center"}):
        c = help(i)
        if c:
            course.append(c[:-1])
    return course



紧接着就是将获取到的课程信息可视化返回给用户,就命名为table.py 8

import tkinter as tk
from tkinter import *


def get_table(id, year, course):
    #绘制主窗体
    window = tk.Tk()
    window.title('课表详情页')
    window.geometry('1500x750')
    window.resizable(False, False)
    #绘制边界线
    canvas = tk.Canvas(window, width=1500, height=750)
    canvas.create_line((50, 50), (50, 700))
    canvas.create_line((50, 50), (1450, 50))
    canvas.create_line((1450, 50), (1450, 700))
    canvas.create_line((1450, 700), (50, 700))
    canvas.create_line((50, 600), (1450, 600))
    for i in range(0, 5):
        canvas.create_line((50 + 1400 * (1 + i * 3) / 16, 50), (50 + 1400 * (1 + i * 3) / 16, 700))
    for i in range(0, 2):
        canvas.create_line((50, 100 + 250 * i), (1450, 100 + 250 * i))
    canvas.create_line((50 + 1400 / 24, 100), (50 + 1400 / 24), 700)
    for i in range(1, 13):
        canvas.create_text(50 + 1400 / 96 * 5, 75 + i * 50, text=i)
    for i in range(3, 14):
        canvas.create_line((50 + 1400 / 24, 50 * i), (50 + 1400 / 16, 50 * i))
    #添加标题内容
    canvas.create_text(1400 / 16 / 3 + 50, 200, text="上午")
    canvas.create_text(1400 / 16 / 3 + 50, 450, text="下午")
    canvas.create_text(1400 / 16 / 3 + 50, 650, text="晚上")
    canvas.create_text(50 + 1400 / 16 * 2.5, 75, text="星期一")
    canvas.create_text(50 + 1400 / 16 * 5.5, 75, text="星期二")
    canvas.create_text(50 + 1400 / 16 * 8.5, 75, text="星期三")
    canvas.create_text(50 + 1400 / 16 * 11.5, 75, text="星期四")
    canvas.create_text(50 + 1400 / 16 * 14.5, 75, text="星期五")
    canvas.create_text(750, 25, text="东南大学 "+id+" 的 "+year+" 学期课表")
    #添加课程内容
    content = list()
    for i in range(0, 15):
        content.append('\n'.join(course[i]))
    for i in range(0, 4):
        canvas.create_text(50 + 1400 / 16 * (2.6 + i * 3), 200, text=content[i])
    for i in range(5, 9):
        canvas.create_text(50 + 1400 / 16 * (2.6 + (i - 5) * 3), 450, text=content[i])
    for i in range(10, 11):
        canvas.create_text(50 + 1400 / 16 * (2.6 + (i - 10) * 3), 650, text=content[i])
    canvas.pack()
    window.mainloop()

展示效果

用户输入界面

出错了

课表界面

出错了

这是暑假就做好的,最近一直在忙着做短学期课程设计和校史竞赛系统,所以现在才发。。。

猜你喜欢

转载自blog.csdn.net/weixin_41106545/article/details/82227208