Exemple #1
0
def login():
    try:
        print time(), u'正在尝试登录选课系统,请稍候...'
        res = config.SESSION.post(config.LOGIN_URL,
                                  login_data,
                                  timeout=config.TIMEOUT)

        status = res.status_code

        if status == 200:
            html = res.text
            doc = pq(html)
            login_status = doc('span.t').text()
            if not login_status:
                print time(), doc.text()
                return False
            else:
                print time(), login_status
                return True
        else:
            print time(), u'登录失败,请稍后重试'
            return False
    except RequestException:
        print time(), u'登录网页请求失败'
        return False
Exemple #2
0
def main():
    signal.signal(signal.SIGINT, quit)
    signal.signal(signal.SIGTERM, quit)
    print time(), u"欢迎使用山东大学刷课系统"
    login_result = login()
    login_result or reLogin() or exit()
    thread()
    print time(), u"程序执行完毕, 感谢您使用山东大学刷课系统"
Exemple #3
0
def main():
    signal.signal(signal.SIGINT, quit)
    signal.signal(signal.SIGTERM, quit)
    print time(), u'欢迎使用山东大学刷课系统'
    login_result = login()
    login_result or reLogin() or exit()
    thread()
    print time(), u'程序执行完毕, 感谢您使用山东大学刷课系统'
Exemple #4
0
def thread():
    threads = []
    for i in range(config.THREAD_NUMBER):
        threads.append(threading.Thread(target=loop))

    for i, t in enumerate(threads):
        t.setDaemon(True)
        print time(), u'正在启动第', i + 1, u'个线程'
        sleep(i)
        t.start()

    for t in threads:
        t.join()
Exemple #5
0
def login():
    try:
        print time(), u'正在尝试登录选课系统,请稍候...'
        res = config.SESSION.post(config.LOGIN_URL, login_data, timeout=config.TIMEOUT)

        status = res.status_code

        if status == 200:
            html = res.text
            doc = pq(html)
            login_status = doc('span.t').text()
            if not login_status:
                print time(), doc.text()
                return False
            else:
                print time(), login_status
                return True
        else:
            print time(), u'登录失败,请稍后重试'
            return False
    except RequestException:
        print time(), u'登录网页请求失败'
        return False
Exemple #6
0
def reLogin(fail_time=0):
    login_result = login()
    if fail_time >= config.MAX_LOGIN_TIME:
        print time(), u'登录重试次数过多,请检查网络状态'
        return False
    if not login_result:
        print time(), u'登录失败,正在重试...'
        fail_time += 1
        return reLogin(fail_time)
    else:
        print time(), u'登录成功,继续刷课...'
    return login_result
Exemple #7
0
def reLogin(fail_time=0):
    login_result = login()
    if fail_time >= config.MAX_LOGIN_TIME:
        print time(), u'登录重试次数过多,请检查网络状态'
        return False
    if not login_result:
        print time(), u'登录失败,正在重试...'
        fail_time += 1
        return reLogin(fail_time)
    else:
        print time(), u'登录成功,继续刷课...'
    return login_result
Exemple #8
0
def select():
    try:
        for course in config.COURSE:
            course = dict(course)
            course_data = {
                'p_qxrxk': course.get('KCH'),
                'p_qxrxk_kxh': course.get('KXH')
            }
            print time(), u'正在尝试选', course.get('KCH'), u'课程,第', config.SELECT_COUNT, u'次选课尝试,请稍候...'
            config.SELECT_COUNT += 1
            try:
                res = config.SESSION.post(config.SELECT_URL, course_data, timeout=config.TIMEOUT)
                html = res.text
                if not html.strip() or needLogin(html):
                    print time(), u'用户登录会话无效,正在重新登录...'
                    reLogin() or exit()
                doc = pq(html)
                result = doc('span.t').text()
                print time(), result
                if selected(result):
                    config.SELECTED = True
                    print time(), u'恭喜你已经选中该门课程'
            except RequestException:
                print time(), u'网页请求失败,继续重试'
            except XMLSyntaxError:
                print time(), u'继续刷课...'
    except AttributeError:
        print u'课程号课序号错误,请检查'
        exit()