Ejemplo n.º 1
0
def gettid(terminfos, ignore=False):
    termnumflag = not ignore
    config = Config('data/config.txt', '$')
    k = config.get('termnum')
    if not termnumflag and \
       k and \
       re.match(r'\d+$',k) and \
       0<=eval(k)<=len(terminfos)+1:
        if 1 <= int(k) <= len(terminfos) + 1:
            t = '第' + str(k)
        elif k == '0':
            t = '最新'
        termnum = int(k) - 1
        print('已自动配置下载{}学期课程'.format(t))
    else:
        for termnum in range(len(terminfos)):
            terminfo = terminfos[termnum]
            print('第%d次开课:' % (termnum + 1) + terminfo['text'] + ',课程号:' +
                  terminfo['id'])
        while True:
            k = input('想下哪个学期的课呢?(最新学期请输入0)')
            try:
                if 0 <= int(k) <= len(terminfos) + 1:
                    termnum = int(k) - 1
                    break
                else:
                    print('我可不会穿越哦~')
            except:
                print('这是啥?')
    config.termnum = str(termnum + 1)
    config.save()
    return terminfos[termnum]['id']
Ejemplo n.º 2
0
def getloadtype(ignore=False):
    def check_loadtype(k):
        if '1' in k or '3' in k or '4' in k or 'all' in k:
            if 'all' in k:
                loadtype = [1, 3, 4]
            else:
                loadtype = []
                for i in k:
                    if i in '134':
                        loadtype.append(int(i))
        else:
            print('不对不对,这个我不认识!')
            loadtype = []
        return loadtype

    loadtypeflag = not ignore
    config = Config('data/config.txt', '$')
    k = config.get('loadtype')
    if not loadtypeflag and \
       check_loadtype(k):
        loadtype = check_loadtype(k)
        print('已自动配置下载类型为:' + k + '(1:视频,3:pdf,4:附件,all:全部)')
    else:
        while True:
            k = input('您想下载哪种课件呐?(1:视频,3:pdf,4:附件,all:全部)')
            loadtype = check_loadtype(k)
            if loadtype:
                break
    config.loadtype = k
    config.save()
    return loadtype
Ejemplo n.º 3
0
def login(ignore=False):
    loginflag = not ignore
    config = Config('data/config.txt', '$')
    print('登录:(当前仅支持爱课程账号)')
    flag = 0
    if config.get('username') and config.get('passwd') and \
       gettoken(config.username,config.passwd)[1]==0:
        if loginflag:
            k = input('已检测到您上次使用账号:{},是否继续使用该账号?[y/n]'.format(config.username))
            if k[0] in 'Yy':
                flag = 1
        else:
            print('自动登录成功')
            flag = 1
    if flag:
        username = config.username
        passwd = config.passwd
        mob_token = gettoken(username, passwd)[0]
    else:
        while True:
            username = input('请输入账号:')
            password = input('请输入密码:')
            flag = hashlib.md5()
            flag.update(password.encode('utf-8'))
            passwd = flag.hexdigest()
            #############Sharing###############
            if username == 'sharing':
                username = '******'
                passwd = 'e10adc3949ba59abbe56e057f20f883e'
            ################################
            k = gettoken(username, passwd)
            if k[1] == 0:
                print('登陆成功!')
                mob_token = k[0]
                break
            elif k[1] == 100:
                print('账号或密码错误,请重新输入')
            else:
                print('发生未知错误!')
    config.username = username
    config.passwd = passwd
    config.save()
    return mob_token
Ejemplo n.º 4
0
def getsharpness(ignore=False):
    sharpnessflag = not ignore
    config = Config('data/config.txt', '$')
    k = config.get('sharpness')
    if not sharpnessflag and \
       k in ['sd','hd','shd']:
        sharpness = k
        print('已自动配置视频清晰度为:' + k + '(标清"sd",高清"hd",超高清"shd")')
    else:
        while True:
            k = input('选个清晰度吧(标清"sd",高清"hd",超高清"shd")')
            if k in ['sd', 'hd', 'shd']:
                sharpness = k
                break
            else:
                print('输错啦!')
    config.sharpness = k
    config.save()
    return sharpness
Ejemplo n.º 5
0
def getweeknum(chapters, ignore=False):
    def check_weeknum(k):
        if k == '0' or k == 'all':
            weeknum = list(range(len(chapters)))
        elif re.search(r'\d+-\d+', k):
            se = re.search(r'\d+-\d+', k).group(0).split('-')
            if 0 < eval(se[0]) <= len(chapters) and 0 < eval(
                    se[1]) <= len(chapters):
                weeknum = list(range(eval(se[0]) - 1, eval(se[1])))
            else:
                print('这个数字不在范围内呀')
                weeknum = ''
        elif re.match(r'\d+$', k):
            if 0 < eval(k) <= len(chapters):
                weeknum = [eval(k) - 1]
            else:
                print('这个数字不在范围内呀')
                weeknum = ''
        return weeknum

    weeknumflag = not ignore
    config = Config('data/config.txt', '$')
    k = config.get('weeknum')
    if not weeknumflag and \
       check_weeknum(k):
        weeknum = check_weeknum(k)
        print('已自动配置下载周次为:' + k)
    else:
        print('以下课程已开放:')
        for chapter in chapters:
            print(chapter.get('name'))
        while True:
            k = input('您想下载哪几周的呀?(单个数字 or 起-止 or 0和all)')
            if check_weeknum(k):
                weeknum = check_weeknum(k)
                break
            else:
                print('输错啦!')
    config.weeknum = k
    config.save()
    return weeknum
Ejemplo n.º 6
0
def getroot(ignore=False):
    rootflag = not ignore
    config = Config('data/config.txt', '$')
    flag = 0
    rootname = platform.system() + 'Root'
    if config.get(rootname) and os.path.exists(config.get(rootname)):
        if rootflag:
            k = input('您上次把课件存到了:{},要不要继续使用这个路径呀?[y/n]'.format(
                config.get(rootname)))
            if k[0] in 'Yy':
                flag = 1
        else:
            print('路径已自动配置:' + config.get(rootname))
            flag = 1
    if flag:
        root = config.get(rootname)
    else:
        while True:
            root = input('想存到哪里呢?:')
            if os.path.exists(root):
                print('嗯嗯,我记住啦')
                break
            else:
                print('这个路径不存在呀!')
    config.set(rootname, root)
    config.save()
    return root
Ejemplo n.º 7
0
if __name__ == '__main__':

    def isignore(config, attr):
        try:
            if eval(config.get(attr)) == True:
                return True
            else:
                config.set(attr, 'False')
                return False
        except:
            config.set(attr, 'False')
            return False
        finally:
            config.save()

    config = Config('data/config.txt', '$')
    ignoreconfig = Config('data/IgnoreOptions.txt', ' is ignore? ')

    mob_token = login(isignore(ignoreconfig, 'login'))  #登录
    root = getroot(isignore(ignoreconfig, 'root'))  #设置下载路径

    while True:
        while True:
            cid = input('课程号课程号!')
            try:
                coursename, terminfos = getterminfos(cid)
                if coursename:
                    print('课程名是 {} 吧?'.format(coursename))
                    k = input('我找的对不对对不对![y/n]')
                    if k and k[0] in 'Yy':
                        break
Ejemplo n.º 8
0
if __name__ == '__main__':

    def isignore(config, attr):
        try:
            if eval(config.get(attr)) == True:
                return True
            else:
                config.set(attr, 'False')
                return False
        except:
            config.set(attr, 'False')
            return False
        finally:
            config.save()

    config = Config('data/config.txt', '$')
    ignoreconfig = Config('data/IgnoreOptions.txt', ' is ignore? ')

    mob_token = gettoken(config.username, config.passwd)[0]
    root = config.get(platform.system() + 'Root')
    #####################################
    tids = [
        '1002700003',  #人工智能实践:Tensorflow笔记
        '1002788142',  #Web信息系统应用开发
        '1002644012',  #计算机网络
        '1002784135',  #计算机操作系统
        '1002654021',  #数据结构
        '1002791028',  #计算机组成原理(上)
        '1002790026',  #计算机组成原理(下)
        '1002774001',  #程序设计入门——C语言
        '1002775002',  #C语言程序设计进阶