Beispiel #1
0
class School(object):
    def __init__(self, url):
        self.school_client = SchoolClient(url,
                                          session=session,
                                          use_ex_handle=False)

    @service_resp()
    def get_login(self, account, password):
        '''首次登陆验证'''
        self.user = self.school_client.user_login(account,
                                                  password,
                                                  use_cookie=False)
        return {"token": random_string(16)}

    @service_resp()
    def get_auth_user(self, account):
        '''使用会话,免密码登陆'''
        auth_user = self.school_client.user_login(account, None)
        return auth_user
Beispiel #2
0
def score(user: User):
    school = SchoolClient('http://202.115.80.211/', use_ex_handle=False)
    try:
        clint = school.user_login(account=user.account,
                                  password=user.password,
                                  use_cookie_login=False)
        data = clint.get_score(score_year=user.year, score_term=user.term)
    except:
        return {'code': 400, 'message': '获取成绩数据失败', 'data': []}
    else:
        return {'code': 200, 'message': '获取成绩数据失败', 'data': data}
Beispiel #3
0
class School(object):
    def __init__(self, url):
        self.school_client = SchoolClient(url,
                                          session=session,
                                          use_ex_handle=False)

    @service_resp()
    def get_login(self, account, password, user_type=0):
        '''首次登陆验证'''
        return self.school_client.user_login(account,
                                             password,
                                             user_type=user_type,
                                             use_login_cookie=False)
Beispiel #4
0
def main():
    global school, user, total_lesson
    try:
        score_data = user.get_score()
        lesson = score_data[CURRENT_YEAR][CURRENT_TERM]
        if not total_lesson:
            total_lesson = lesson
        elif len(lesson) > len(total_lesson):
            diff = [item for item in lesson if item not in total_lesson]
            total_lesson = lesson
            title, content, mem_content = u'【期末】出新的成绩了!', u'', u'课程名:'
            for item in diff:
                content += u'课程名:%s,学分:%s,绩点:%s,成绩:%s.\n' % \
                           (item['lesson_name'], item['credit'], item['point'], item['score'])
                mem_content += u'%s、' % item['lesson_name']
            mem_content = mem_content.rstrip(u'、') + u'\n已经出分了,快去查看吧!'
            bot.set_email(title=title, content=content)
            bot.send_email()
            send_to_members(title=title, content=mem_content)
        elif len(lesson) < len(total_lesson):
            diff = [item for item in total_lesson if item not in lesson]
            total_lesson = lesson
            title, content, mem_content = u'【期末】有成绩被撤回了!', u'', u'课程名:'
            for item in diff:
                content += u'课程名:%s,学分:%s,绩点:%s,成绩:%s.\n' % \
                           (item['lesson_name'], item['credit'], item['point'], item['score'])
                mem_content += u'%s、' % item['lesson_name']
            mem_content = mem_content.rstrip(u'、') + u'\n以上课程成绩被老师撤回了!'
            bot.set_email(title=title, content=content)
            bot.send_email()
            send_to_members(title=title, content=mem_content)
        else:
            pass
    except Exception as e:
        school = SchoolClient(url=ZHENGFANG_URL)
        user = school.user_login(USERNAME, PASSWORD)
        rootLogger.error(str(e))
        raise Exception
Beispiel #5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from redis import Redis

from school_api import SchoolClient
from school_api.session.redisstorage import RedisStorage

redis = Redis()
session = RedisStorage(redis)
conf = {
    'name': '广东科技学院',
    'code': 'gdst',
    'login_url_path': '/default2.aspx',  # 登录地址
    'session': session,
}

GdstApi = SchoolClient('http://61.142.33.204', **conf)
student = GdstApi.user_login('user', 'password', timeout=3)

info_data = student.get_info(timeout=5)
print(info_data)
Beispiel #6
0
conf = {
    'name': '广东科技学院',
    'code': 'gdst',
    'exist_verify': True,          # 是否存在验证码
    'login_url': '/default2.aspx',
    'lan_url': 'http://172.16.1.8',  # 内网地址
    'priority_proxy': False,             # 是否优先使用代理
    'url_path_list': None,           # 教务系统链接
    # 'proxies': {"http": "http://*****:*****@XXXX:3120/", }  # 代理存在时,请求失败则会切换成代理
}

# 先实例化一个学校,再实例化用户
GdstApi = SchoolClient('http://61.142.33.204', **conf)  # 注册一个学校A


client_a = GdstApi.user_login('user', 'password', timeout=2)  # 学校A实例化一个学生a
client_b = GdstApi.user_login('user', 'password', user_type=1, timeout=2)  # 学校A实例化一个教师b
client_c = GdstApi.user_login('user', 'password', user_type=2)  # 学校A实例化一个部门教师c

# 获取 2017-2018学年1学期的 课表
schedule_data = client_b.get_schedule(
    schedule_year='2017-2018', schedule_term='1', timeout=5)
print(schedule_data)

# 获取 获取最新的 个人课表
schedule_data = client_a.get_schedule()

# 获取 2017-2018学年2学期的 班级课表
schedule_data = client_a.get_schedule(
    timeout=5, schedule_type=1, schedule_year='2017-2018', schedule_term='1')
Beispiel #7
0
MEMBERS = list(map(str.strip, config['GROUP']['MEMBERS'].split(',')))

logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s-%(name)s-%(levelname)s: %(message)s',
                    datefmt='%Y-%m-%d %H:%M:%S',
                    filename=os.path.join(
                        os.path.dirname(os.path.realpath(__file__)),
                        'error.log'))
rootLogger = logging.getLogger()

bot = Bot(from_addr=FROM_ADDR,
          auth_code=AUTH_CODE,
          to_addr=TO_ADDR,
          smtp_server=SMTP_SERVER)
school = SchoolClient(url=ZHENGFANG_URL)
user = school.user_login(USERNAME, PASSWORD)
total_lesson = [
]  # [{'lesson_name': '创业与投融资', 'credit': 2.0, 'point': 4.0, 'score': 90.0}]


def send_to_members(title, content):
    for add in MEMBERS:
        member_bot = Bot(from_addr=FROM_ADDR,
                         auth_code=AUTH_CODE,
                         to_addr=add,
                         smtp_server=SMTP_SERVER)
        member_bot.set_email(title=title, content=content)
        member_bot.send_email()


def err_listener(ev):