예제 #1
0
def generate():
    config = app.config
    user = config['users'][0]
    apis = app.getCpdailyApis(user)
    session = app.getSession(user, apis['login-url'])
    print(app.queryForm(session, apis))
    form = dict(app.queryForm(session, apis))['form']
    app.log(form)
    defaults = []
    sort = 1
    for formItem in form:
        if formItem['isRequired'] == 1:
            default = {}
            one = {}
            default['title'] = formItem['title']
            default['type'] = formItem['fieldType']
            print('问题%d:' % sort + default['title'])
            if default['type'] == 1:
                default['value'] = input("请输入文本:")
            if default['type'] == 2:
                fieldItems = formItem['fieldItems']
                num = 1
                for fieldItem in fieldItems:
                    print('\t%d ' % num + fieldItem['content'])
                    num += 1
                choose = int(input("请输入序号:"))
                if choose < 1 or choose > num:
                    print('输入错误,请重新执行此脚本')
                    exit(-1)
                default['value'] = fieldItems[choose - 1]['content']
            if default['type'] == 3:
                fieldItems = formItem['fieldItems']
                num = 1
                for fieldItem in fieldItems:
                    print('\t%d ' % num + fieldItem['content'])
                    num += 1
                chooses = list(map(int, input('请输入序号(可输入多个,请用空格隔开):').split()))
                default['value'] = ''
                for i in range(0, len(chooses)):
                    choose = chooses[i]
                    if choose < 1 or choose > num:
                        print('输入错误,请重新执行此脚本')
                        exit(-1)
                    if i != len(chooses) - 1:
                        default['value'] += fieldItems[choose -
                                                       1]['content'] + ','
                    else:
                        default['value'] += fieldItems[choose - 1]['content']
            if default['type'] == 4:
                default['value'] = input("请输入图片名称:")
            one['default'] = default
            defaults.append(one)
            sort += 1
    print('======================分隔线======================')
    print(yaml.dump(defaults, allow_unicode=True))
예제 #2
0
def main():
    while True:
        app.log('脚本开始执行。。。')
        cookies = app.getCookies()
        if str(cookies) != 'None':
            app.log('模拟登陆成功。。。')
            app.log('正在查询最新待填写问卷。。。')
            params = app.queryForm(cookies)
            if str(params) == 'None':
                app.log('获取最新待填写问卷失败,可能是辅导员还没有发布。。。')
                app.log('无需重启脚本,1小时后,脚本将自动重新尝试。。。')
                time.sleep(60 * 60 * 1)
                continue
            app.log('查询最新待填写问卷成功。。。')
            app.log('正在自动填写问卷。。。')
            form = app.fillForm(params['form'])
            app.log('填写问卷成功。。。')
            app.log('正在自动提交。。。')
            msg = app.submitForm(params['formWid'],
                                 app.config['user']['address'],
                                 params['collectWid'], params['schoolTaskWid'],
                                 form, cookies)
            if msg == 'SUCCESS':
                app.log('自动提交成功!24小时后,脚本将再次自动提交。。。')
                time.sleep(24 * 60 * 60)
            elif msg == '该收集已填写无需再次填写':
                app.log('今日已提交!24小时后,脚本将再次自动提交。。。')
                app.sendMessage()
                time.sleep(24 * 60 * 60)
            else:
                app.log('自动提交失败。。。')
                app.log('错误是' + msg)
                exit(-1)
        else:
            app.log('模拟登陆失败。。。')
            app.log('原因可能是学号或密码错误,请检查配置后,重启脚本。。。')
            exit(-1)