Created
May 12, 2014 12:22
-
-
Save zhwei/88ff04a6cc7f7dabdfaa to your computer and use it in GitHub Desktop.
计算学分绩点Python脚本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import re | |
import requests | |
data = {"post_xuehao": "111111789"} | |
page = requests.post('http://xkzx.sdut.edu.cn/cjcx/zcjcx_list.php', data=data) | |
par = re.compile('<td scope="col" align=".*" valign="middle" nowrap> (.*?)</td>') | |
ret = par.findall(page.content) | |
score_list = [] | |
for j in [ret[i:i + 16] for i in xrange(13, len(ret), 16)]: | |
dic = { | |
"year": j[1], # 学年 | |
"category": j[3], # 类别 | |
"name": j[5], # 课程名称 | |
"credit": float(j[7]), # 学分 | |
"model": j[8], # 考核方式 | |
"initial": j[10], # 原考成绩 | |
"makeup": j[11], # 补考成绩 | |
} | |
score_list.append(dic) | |
for item in score_list[:]: | |
if item['category'] in ("公选课",) or item['model'] in ("第二专业", ): | |
score_list.remove(item) | |
else: | |
# 处理其他分数形式 | |
convert_dict = { | |
'优秀': 95, '良好': 84, '良': 84, '中等': 73, '免修': 70, | |
'及格': 62, '已修': 60, '及': 62, '合格': 60, | |
'不及格': 0, '缺考': 0, '禁考': 0, '退学': 0, '-': 0, | |
'休学': 0, '未选': 0, '作弊': 0, '不合格': 0,'取消': 0, | |
} | |
for _t in ('initial', 'makeup'): | |
if item[_t] == "": item[_t] = 0 | |
if item[_t] in convert_dict.keys(): | |
item[_t] = convert_dict[item[_t]] | |
stay_list = {'缓考(时': 0, '缓考': 0,} | |
if item['initial'] in stay_list: | |
if item['makeup'] >= 60: item['initial'] = float(item['makeup']) | |
elif item['makeup'] in stay_list: | |
item["makeup"] = 0 | |
# 计算课程绩点 | |
item["initial"] = 0 if float(item['initial']) < 60 else float(item['initial']) | |
item["makeup"] = 60 if float(item['makeup']) >= 60 else 0 | |
score_dict = {} | |
for l in score_list: | |
if l['name'] in score_dict.keys(): | |
score_dict[l['name']]['initial'] = max(l['initial'], score_dict[l['name']]['initial']) | |
score_dict[l['name']]['makeup'] = max(l['makeup'], score_dict[l['name']]['makeup']) | |
else: | |
score_dict.update({l['name']:l}) | |
sum_course_gpa = float() | |
sum_course_credit = float() | |
for d in score_dict: | |
item = score_dict[d] | |
sum_course_gpa += float(max(item['initial'], item['makeup'])) * item['credit'] | |
sum_course_credit += item['credit'] | |
print sum_course_gpa / sum_course_credit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment