コード例 #1
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}
コード例 #2
0
ファイル: test_redis.py プロジェクト: zlgz/school-api
class TestStudent(unittest.TestCase):
    redis = Redis()
    session = RedisStorage(redis)
    conf = {
        'name': '广东科技学院',
        'code': 'gdst',
        'login_url_path': '/default2.aspx', # 登录地址
        # 'exist_verify': False,            # 是否存在验证码
        'session': session,
    }

    STUDENT_ACCOUNT = os.getenv('GDST_STUDENT_ACCOUNT', '')
    STUDENT_PASSWD = os.getenv('GDST_STUDENT_PASSWD', '')

    GdstApi = SchoolClient('http://61.142.33.204', **conf)
    student = GdstApi.user_login(STUDENT_ACCOUNT, STUDENT_PASSWD, timeout=3)
    # 第二次 触发会话登录
    student = GdstApi.user_login(STUDENT_ACCOUNT, STUDENT_PASSWD, timeout=3)

    def setUp(self):
        print('正在执行\033[1;35m %s \033[0m函数。' % self._testMethodName)

    def tearDown(self):
        pass

    def test_info(self):
        info_data = self.student.get_info(timeout=5)
        print(info_data)
コード例 #3
0
ファイル: test_bm_teacher.py プロジェクト: tcjj3/school-api
class TestBmTeacher(unittest.TestCase):
    BM_TEACHER_ACCOUNT = os.getenv('GDST_BM_TEACHER_ACCOUNT', '')
    BM_TEACHER_PASSWD = os.getenv('GDST_BM_TEACHER_PASSWD', '')
    GdstApi = SchoolClient('http://61.142.33.204')
    bm_teacher = GdstApi.user_login(BM_TEACHER_ACCOUNT,
                                    BM_TEACHER_PASSWD,
                                    user_type=2,
                                    timeout=3)

    def setUp(self):
        print('正在执行\033[1;35m %s \033[0m函数。' % self._testMethodName)

    def tearDown(self):
        pass

    def test_schedule(self):
        schedule_data = self.bm_teacher.get_schedule(class_name='15软件本科2班',
                                                     timeout=5)
        print(schedule_data)

    def test_place_schedule(self):
        for schedule_data in self.bm_teacher.get_place_schedule(
                campus_list=[u"本部"], timeout=5):
            print(schedule_data)
            break
コード例 #4
0
class TestStudent(unittest.TestCase):
    redis = Redis()
    session = RedisStorage(redis)
    conf = {
        'name': '广东科技学院',
        'code': 'gdst',
        'login_url_path': '/default2.aspx', # 登录地址
        # 'exist_verify': False,            # 是否存在验证码
        'session': session,
        'login_view_state': {           # 登录的view_state(可空)
            'http://61.142.33.204/default2.aspx': 'dDw3OTkxMjIwNTU7Oz5vJ/yYUi9dD4fEnRUKesDFl8hEKA==',
            'http://61.142.33.204/default4.aspx': 'dDwxMTE4MjQwNDc1Ozs+MzFt0h81g6NGHTq1L9P2NfWUGLA='
        },
    }

    STUDENT_ACCOUNT = os.getenv('GDST_STUDENT_ACCOUNT', '')
    STUDENT_PASSWD = os.getenv('GDST_STUDENT_PASSWD', '')

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

    def setUp(self):
        print('正在执行\033[1;35m %s \033[0m函数。' % self._testMethodName)

    def tearDown(self):
        pass

    def test_info(self):
        info_data = self.student.get_info(timeout=5)
        print(info_data)
コード例 #5
0
class TestStudent(unittest.TestCase):

    STUDENT_ACCOUNT = os.getenv('GDOU_STUDENT_ACCOUNT', '')
    STUDENT_PASSWD = os.getenv('GDOU_STUDENT_PASSWD', '')
    GdouApi = SchoolClient('http://210.38.137.126:8016')
    student = GdouApi.user_login(STUDENT_ACCOUNT, STUDENT_PASSWD, timeout=3)

    def setUp(self):
        print('正在执行\033[1;35m %s \033[0m函数。' % self._testMethodName)

    def tearDown(self):
        pass

    def test_schedule(self):
        schedule_data = self.student.get_schedule(schedule_year='2017-2018',
                                                  schedule_term='1',
                                                  timeout=5)
        print(schedule_data)

    def test_score(self):
        score_data = self.student.get_score(score_year='2017-2018',
                                            score_term='1',
                                            timeout=5)
        print(score_data)

    def test_info(self):
        info_data = self.student.get_info(timeout=5)
        print(info_data)
コード例 #6
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
コード例 #7
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)
コード例 #8
0
ファイル: Main.py プロジェクト: Pragmatism0220/Score-Notice
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
コード例 #9
0
class TestStudent(unittest.TestCase):

    conf = {
        'code': 'gdst',
        'name': '广东科技学院',
        'lan_url': 'http://172.16.1.8',  # 内网地址
        'login_url_path': '/default4.aspx',  # 登录地址
        'exist_verify': False,  # 是否存在验证码
        # 'priority_proxy': True,        # 是否优先使用代理
        # 'proxies': {"http": "http://*****:*****@xxxx.xxxx.xxxx:xxxx/", }  # 代理
    }

    STUDENT_ACCOUNT = os.getenv('GDST_STUDENT_ACCOUNT', '')
    STUDENT_PASSWD = os.getenv('GDST_STUDENT_PASSWD', '')
    GdstApi = SchoolClient('http://61.142.33.204', **conf)
    student = GdstApi.user_login(STUDENT_ACCOUNT, 'error_pwd', timeout=3)
    student = GdstApi.user_login(STUDENT_ACCOUNT, STUDENT_PASSWD, timeout=3)
    # 第二次 触发会话登录
    student = GdstApi.user_login(STUDENT_ACCOUNT, STUDENT_PASSWD, timeout=3)

    def setUp(self):
        print('正在执行\033[1;35m %s \033[0m函数。' % self._testMethodName)

    def tearDown(self):
        pass

    def test_schedule(self):
        schedule_data = self.student.get_schedule(schedule_year='2017-2018',
                                                  schedule_term='1')
        schedule_data = self.student.get_schedule(schedule_year='2017-2018',
                                                  schedule_term='1',
                                                  schedule_type=1)
        print(schedule_data)

    def test_score(self):
        score_data = self.student.get_score(score_year='2017-2018',
                                            score_term='1',
                                            use_api=2,
                                            timeout=5)
        score_data = self.student.get_score(score_year='2017-2018',
                                            score_term='1',
                                            timeout=5)
        print(score_data)

    def test_info(self):
        info_data = self.student.get_info(timeout=5)
        print(info_data)
コード例 #10
0
ファイル: school.py プロジェクト: vanillacoffee/school-api
class School():
    conf = {'session': session}
    GdstApi = SchoolClient('http://61.142.33.204', **conf)

    def __init__(self, user, password):
        self.student = self.GdstApi.user_login(user, password)

    def info(self):
        return self.student.get_info()

    def schedule(self, schedule_year=None, schedule_term=None):
        return self.student.get_schedule(schedule_year,
                                         schedule_term,
                                         schedule_type=1)

    def score(self, score_year=None, score_term=None):
        return self.student.get_score(score_year, score_term)
コード例 #11
0
class TestStudent(unittest.TestCase):

    conf = {
        'name': '广东科技学院',
        'login_view_state': {  # 登录的view_state(可空)
            'http://61.142.33.204/default2.aspx':
            'dDw3OTkxMjIwNTU7Oz5vJ/yYUi9dD4fEnRUKesDFl8hEKA==',
            'http://61.142.33.204/default4.aspx':
            'dDwxMTE4MjQwNDc1Ozs+h4dTkZuJcYarQdE7xNFUBMsLO/w='
        },
        'lan_url': 'http://172.16.1.8',  # 内网地址
        'login_url_path': '/default2.aspx',  # 登录地址
        'exist_verify': True,  # 是否存在验证码
        'priority_porxy': False,  # 是否优先使用代理
        'url_endpoint': None,  # 教务系统链接
        # 'proxies': {"http": "http://*****:*****@xxxx.xxxx.xxxx:xxxx/", }  # 代理
    }

    STUDENT_ACCOUNT = os.getenv('GDST_STUDENT_ACCOUNT', '')
    STUDENT_PASSWD = os.getenv('GDST_STUDENT_PASSWD', '')
    GdstApi = SchoolClient('http://61.142.33.204', **conf)
    student = GdstApi.user_login(STUDENT_ACCOUNT, STUDENT_PASSWD, timeout=3)

    def setUp(self):
        print('正在执行\033[1;35m %s \033[0m函数。' % self._testMethodName)

    def tearDown(self):
        pass

    def test_schedule(self):
        schedule_data = self.student.get_schedule(schedule_year='2017-2018',
                                                  schedule_term='1',
                                                  timeout=5)
        print(schedule_data)

    def test_score(self):
        score_data = self.student.get_score(score_year='2017-2018',
                                            score_term='1',
                                            timeout=5)
        print(score_data)

    def test_info(self):
        info_data = self.student.get_info(timeout=5)
        print(info_data)
コード例 #12
0
class TestTeacher(unittest.TestCase):
    TEACHER_ACCOUNT = os.getenv('GDST_TEACHER_ACCOUNT', '')
    TEACHER_PASSWD = os.getenv('GDST_TEACHER_PASSWD', '')
    GdstApi = SchoolClient('http://61.142.33.204')
    teacher = GdstApi.user_login(TEACHER_ACCOUNT,
                                 TEACHER_PASSWD,
                                 user_type=1,
                                 timeout=3)

    def setUp(self):
        print('正在执行\033[1;35m %s \033[0m函数。' % self._testMethodName)

    def tearDown(self):
        pass

    def test_schedule(self):
        schedule_data = self.teacher.get_schedule(schedule_year='2017-2018',
                                                  schedule_term='1',
                                                  timeout=5)
        print(schedule_data)

    def test_info(self):
        info_data = self.teacher.get_info(timeout=5)
        print(info_data)
コード例 #13
0
from school_api import SchoolClient


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学期的 班级课表
コード例 #14
0
 def __init__(self, url):
     self.school_client = SchoolClient(url,
                                       session=session,
                                       use_ex_handle=False)
コード例 #15
0
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals

from school_api import SchoolClient
from school_api.exceptions import SchoolException, LoginException, IdentityException

school = SchoolClient('http://61.142.33.204', use_ex_handle=False)


def service_resp():
    def decorator(func):
        def warpper(*args, **kwargs):
            try:
                client = school.user_login(*args, **kwargs)
                data = func(client)
            except IdentityException as reqe:
                # 账号密码错误
                return {'error': reqe}
            except LoginException as reqe:
                # 登录失败 (包含以上错误)
                return {'error': reqe}
            except SchoolException as reqe:
                # 请求失败 (包含以上错误)
                return {'error': reqe}
            except Exception:
                # 模块报错 (包含以上错误)
                return {'error': '教务请求失败'}
            else:
                # 数据处理 (如:缓存)
                return data
コード例 #16
0
from school_api import SchoolClient
from school_api.session.redisstorage import RedisStorage
from redis import Redis

redis = Redis()
session = RedisStorage(redis)
conf = {
    "url": 'http://jws.hebiace.edu.cn/default2.aspx',
    "session": session,
    'name': '河北建筑工程学院',
    'code': 'hbjg'
}

school = SchoolClient(**conf)


class SchoolApiGet(object):
    def get_student(self, account, password):
        i = 0
        user = school.user_login(account, password)
        student_info = user.get_student_info()
        while 'error' in student_info:
            student_info = user.get_student_info()
            i = i + 1
            if i >= 4:
                return student_info
        return student_info

    def get_score_info(self, account, password, score_year=0, score_term=0):
        user = school.user_login(account, password)
        school_data = user.get_score(score_year, score_term, use_api=3)
コード例 #17
0
ファイル: Main.py プロジェクト: Pragmatism0220/Score-Notice
SEC_INTERVAL = config['DEFAULT']['SEC_INTERVAL']
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()

コード例 #18
0
ファイル: use_redis.py プロジェクト: dayidson/school-api
#!/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)
コード例 #19
0
    'name': '广东科技学院',
    'code': 'gdst',
    'exist_verify': True,          # 是否存在验证码
    'login_url': '/default2.aspx',
    'login_view_state': {           # login_view_state 的存在可以避免 初始化学校时的获取
        'http://61.142.33.204/default2.aspx': 'dDw3OTkxMjIwNTU7Oz5vJ/yYUi9dD4fEnRUKesDFl8hEKA==',
        'http://61.142.33.204/default4.aspx': 'dDwxMTE4MjQwNDc1Ozs+MzFt0h81g6NGHTq1L9P2NfWUGLA=',
    },
    'lan_url': 'http://172.16.1.8',  # 内网地址
    'use_proxy': False,             # 是否优先使用代理
    'url_endpoint': None,           # 教务系统链接
    # 'proxies': {"http": "http://*****:*****@XXXX:3120/", }  # 代理存在时,请求失败则会切换成代理
}

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


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学期的 班级课表
コード例 #20
0
from school_api import SchoolClient
from fastapi import FastAPI
from pydantic import BaseModel
from school_api.exceptions import SchoolException, LoginException, IdentityException
import requests
import json

app = FastAPI()
school = SchoolClient('http://202.115.80.211/', use_ex_handle=False)


class User(BaseModel):
    account: str
    password: str
    year: str = None
    term: str = None


def saveInfo(data):
    url = 'https://api2.bmob.cn/1/classes/userInfo'
    header = {
        "X-Bmob-Application-Id": "160a9b19cb9a1bedce5c0f48d2fd8ce5",
        "X-Bmob-REST-API-Key": "63e64b5539026cfe34ac1f38542cda9e",
        "Content-Type": "application/json"
    }
    data = json.dumps(data)
    r = requests.post(url=url, data=data, headers=header)
    res = json.loads(r.content)
    if (res['objectId']):
        return '保存成绩成功'
    else: