Ejemplo n.º 1
0
def classList(cookies, AuthToken, host):
    debug = readCfg()["debug"]
    attempt = readCfg()["attempt"]
    timeout = readCfg()["requestTimeout"]
    headers = {
        "User-Agent": userAgent,
        "X-AUTH-TOKEN": AuthToken,
        "Cookie": cookies,
        "Content-Type": "application/json;charset=UTF-8",
        "Origin": "https://" + host + f".ebsoc.co.kr",
        "Referer": "https://" + host + f".ebsoc.co.kr/class"
    }
    payload = {
        "schoolAffairsYear": 2021,
        "tabType": "ALL",
        "searchType": "NONE",
        "searchWord": "",
        "orderType": "DESC"
    }
    for i in range(attempt):
        try:
            data = requests.post(
                "https://" + host +
                f".ebsoc.co.kr/cls/api/v1/mypage/myClassListByTabType",
                headers=headers,
                json=payload,
                timeout=timeout).content.decode("utf-8")
            break
        except requests.exceptions.ReadTimeout as e:
            if i - 1 == attempt:
                raise e
    if debug == "yes": print(data)
    jsonData = json.loads(data)
    return jsonData["data"]["list"]
Ejemplo n.º 2
0
def learnAPI(AuthToken, progress, memberSeq, lectureLearningSeq, schoolCode,
             key, IV, host):
    debug = readCfg()["debug"]
    import AEScrypt
    assembledData = AEScrypt.dataAssembly(str(memberSeq),
                                          str(lectureLearningSeq),
                                          str(progress))
    cryptData = AEScrypt.encrypt(key, IV, assembledData)
    headers = {
        "User-Agent": userAgent,
        "X-AUTH-TOKEN": AuthToken,
        "Content-Type": "application/json;charset=UTF-8"
    }
    payload = {
        "encriptedProgressRate": cryptData,
    }
    payload = json.dumps(payload)
    data = requests.post(
        f"https://" + host +
        f".ebsoc.co.kr/lecture/api/v1/student/learning/{lectureLearningSeq}/{schoolCode}/progress",
        headers=headers,
        data=payload)
    if debug == "yes":
        print(data.content.decode("utf-8"))
        print(assembledData)
        print(cryptData)
    jsonData = json.loads(data.content.decode("utf-8"))
    return jsonData
Ejemplo n.º 3
0
def userDetail(cookies, AuthToken, memberSeq, host):
    debug = readCfg()["debug"]
    attempt = readCfg()["attempt"]
    timeout = readCfg()["requestTimeout"]
    headers = {
        "User-Agent": userAgent,
        "X-AUTH-TOKEN": AuthToken,
        "Cookie": cookies
    }
    for i in range(attempt):
        try:
            data = requests.get(
                f"https://ebsoc.co.kr/auth/api/v1/member/detail/{memberSeq}",
                headers=headers,
                timeout=timeout).content.decode("utf-8")
            break
        except requests.exceptions.ReadTimeout as e:
            if i - 1 == attempt:
                raise e
    if debug == "yes": print(data)
    jsonData = json.loads(data)
    return jsonData["data"]
Ejemplo n.º 4
0
def finLessonList(cookies, AuthToken, host):
    debug = readCfg()["debug"]
    attempt = readCfg()["attempt"]
    timeout = readCfg()["requestTimeout"]
    headers = {
        "User-Agent": userAgent,
        "X-AUTH-TOKEN": AuthToken,
        "Cookie": cookies
    }
    for i in range(attempt):
        try:
            data = requests.get(
                f"https://" + host +
                f".ebsoc.co.kr/lecture/api/v1/student/learning",
                headers=headers,
                timeout=timeout).content.decode("utf-8")
            break
        except requests.exceptions.ReadTimeout as e:
            if i - 1 == attempt:
                raise e
    if debug == "yes": print(data)
    jsonData = json.loads(data)
    return jsonData["data"]["list"]
Ejemplo n.º 5
0
def newFileDownload(cookies, AuthToken, fileId, host):
    debug = readCfg()["debug"]
    headers = {
        "User-Agent": userAgent,
        "X-AUTH-TOKEN": AuthToken,
        "Cookie": cookies,
        "Content-Type": "application/json;charset=UTF-8"
    }
    #이걸 또 또 바꾸네
    req = requests.get(
        f"https://" + host +
        f".ebsoc.co.kr/common/api/v1/s3new/file/getDownLoadURL?fileId={fileId}",
        headers=headers).json()
    return req['data']
Ejemplo n.º 6
0
def lessonList(cookies, AuthToken, classUrlPath, host):
    debug = readCfg()["debug"]
    attempt = readCfg()["attempt"]
    timeout = readCfg()["requestTimeout"]
    headers = {
        "User-Agent": userAgent,
        "X-AUTH-TOKEN": AuthToken,
        "Cookie": cookies
    }
    for i in range(attempt):
        try:
            data = requests.get(
                f"https://" + host +
                f".ebsoc.co.kr/lecture/api/v1/{classUrlPath}/lesson/list?atltStsCd=&orderBy=3&",
                headers=headers,
                timeout=timeout)
            break
        except requests.exceptions.ReadTimeout as e:
            if i - 1 == attempt:
                raise e
    if debug == "yes": print(data.content.decode("utf-8"))
    print(data.url)
    jsonData = json.loads(data.content.decode("utf-8"))
    return jsonData["data"]["list"]
Ejemplo n.º 7
0
def createAPICheck(cookies, AuthToken, contentsSeq, contentsTypeCode,
                   lectureSeq, lessonAttSeq, lessonSeq, officeEduCode,
                   schoolCode, lectureLearningSeq, host):
    debug = readCfg()["debug"]
    headers = {
        "User-Agent": userAgent,
        "X-AUTH-TOKEN": AuthToken,
        "Cookie": cookies.replace("<", "")
    }
    payload = {
        "contentsSeq": int(contentsSeq),
        "contentsTypeCode": str(contentsTypeCode),
        "lectureSeq": str(lectureSeq),
        "lessonAttendanceSeq": lessonAttSeq,
        "lessonSeq": int(lessonSeq),
        "officeEduCode": str(officeEduCode),
        "schoolCode": str(schoolCode)
    }
    if lectureLearningSeq == None:
        data = requests.post(
            f"https://" + host +
            f".ebsoc.co.kr/lecture/api/v1/lesson/lecture/attend/create",
            headers=headers,
            json=payload)
        if debug == "yes":
            print(f"create: {data.content.decode('utf-8')}")
            print(f"create: {data.headers}")
    else:
        data = ""
    jsonData = json.loads(data.content.decode("utf-8"))
    try:
        if jsonData["code"] != "OK":
            return jsonData["data"]
        else:
            return jsonData
    except KeyError:
        return jsonData
Ejemplo n.º 8
0
def learn(lectureData,cookies,auth,memberSeq,percent=0):
    import glob
    import shutil
    config = readCfg()
    if config['debug'] == 'yes': print(lectureData)
    import wget
    lectureDetail = APIWrapper.lectureDetail(cookies,auth,lectureData['lessonSeq'],host)
    schoolCode = lectureData['schoolCode']
    print(f"\033[92m 강의 정보 받기에 성공했습니다.\033[0m")
    try:
        print(lectureDetail['lectureContentsDto']['lectureContentsTextDto']['textContents'])
    except:
        try:
            print(lectureDetail['lectureContentsDto']['contentsContents'])
        except TypeError:
            pass
    try:
        for i in lectureDetail['lectureContentsDto']['lectureContentsDocImageDtoList']['lectureContentsDocImageDtoList']:
            if config['saveFile'] == 'yes':
                try:
                    wget.download(i['fileleDto']['fileStoragePath'],out=os.path.join(os.path.dirname(__file__),f"downloads/{i['fileleDto']['originalFileName'].replace('/','').replace('?','')}"))
                    print('\n')
                except:
                    #이렇게 예외처리 하라고 메일도 보냈는데 처리 대충대충하는건 EBS종특이냐?
                    print('\033[95m Fall back to newFileDownloadAPI\033[0m')
                    print('Downloading...')
                    data = APIWrapper.newFileDownload(cookies,auth,i['fileleDto']['fileDetailId'],host)
                    #Work in progress
                    try:
                        wget.download(data,out=os.path.join(os.path.dirname(__file__),f"downloads/{i['fileleDto']['originalFileName'].replace('/','').replace('?','')}"))
                    except:
                        try:
                            downloadFile(data,os.path.join(os.path.dirname(__file__),f"downloads/{i['fileleDto']['originalFileName'].replace('/','').replace('?','')}"))
                        except:
                            print('\n\033[91m 강의 다운로드에 실패했습니다.\033[0m')
        playTime = None
        runcount = 1
    except:
        try:
            lecturl = lectureDetail['lectureContentsDto']['lectureContentsMvpDto']['mvpFileUrlPath']
            playTime = lectureDetail['lectureContentsDto']['lectureContentsMvpDto']['playTime']
            try:
                runcount = round(int((playTime*(100 - percent)/100)/config['playSpd'])/30)
            except:
                runcount = 1
            if runcount == 0:
                runcount = 1
            try:
                os.mkdir(os.getcwd()+'/downloads')
            except FileExistsError:
                pass
            if 'youtu' in lecturl and config['saveYTVideo'] == 'yes':
                import youtube_dl
                ydl_opts = {
                    'format': 'best/best',
                }
                with youtube_dl.YoutubeDL(ydl_opts) as ydl:
                    try:
                        ydl.download([lecturl])
                    except:
                        print('youtube-dl 오류가 발생했습니다')
                try: 
                    for f in glob.glob(os.getcwd()+r'/*.mp4'):
                        shutil.move(f,os.getcwd()+'/downloads')
                except:
                    print('shutil 오류가 발생했습니다 [대체로 심각한 문제가 아닙니다.]')
                    try:
                        for f in glob.glob(os.getcwd()+r'/*.mp4'):
                            os.remove(f)
                    except:
                        print('파일 핸들링 오류가 발생했습니다')
            else:
                if config['saveEBSVideo'] == 'yes':
                    try:
                        wget.download(lecturl,out=os.path.join(os.path.dirname(__file__),f"downloads/{lectureDetail['lectureName'].replace('/','').replace('?','')}.mp4"))
                        print('\n')
                    except:
                        print('\n\033[91m 강의 다운로드에 실패했습니다.\033[0m')
        except TypeError:
            playTime = None
            runcount = 1
    if lectureData['lectureLearningSeq'] == None:
        try:
            createAPI = APIWrapper.createAPICheck(cookies,auth,lectureData['contentsSeq'],lectureData['contentsTypeCode'],lectureData['lectureSeq'],\
                lectureData['lessonAttendanceSeq'],lectureData['lessonSeq'],lectureData['officeEduCode'],lectureData['schoolCode'],lectureData['lectureLearningSeq'],host)
            lrnseq = createAPI['data']
            if config['debug'] == 'yes': print(f"lectCrt: {createAPI}")
        except:
            print('강의 정보 등록에 실패했습니다.')
            if config['debug'] == 'yes': print(createAPI)
            return
    else:
        lrnseq = lectureData['lectureLearningSeq']
    if lectureData['rtpgsRt'] == 100:
        runcount = 1
    for i in range(runcount):
        if i == runcount - 1:
            print('진도율 100% 입니다')
            for p in range(10):
                p
                try:
                    result = APIWrapper.learnAPI(auth,'100',memberSeq,lrnseq,schoolCode,'l40jsfljasln32uf','asjfknal3bafjl23',host)
                    break
                except:
                    pass
        else:
            try:
                for p in range(10):
                    try:
                        if int(100*(i+1)/runcount)+percent >= 100:
                            progress = 99
                        else:
                            progress = int(100*(i+1)/runcount)+percent
                        APIWrapper.learnAPI(auth,str(progress),memberSeq,lrnseq,schoolCode,'l40jsfljasln32uf','asjfknal3bafjl23',host)
                        break
                    except APIWrapper.json.JSONDecodeError:
                        progress = 0
                        pass
                print(f"진도율이 저장되었습니다 ({i+1}/{runcount}) [{progress}%]")
                time.sleep(30)
            except KeyboardInterrupt:
                APIWrapper.learnAPI(auth,str(progress),memberSeq,lrnseq,schoolCode,'l40jsfljasln32uf','asjfknal3bafjl23',host)
                print('\n강의 수강이 중단되었습니다.')
                return
    try: 
        if result['code'] == 'OK': 
            print('\n강의 수강이 완료되었습니다.')
        else:
            print('\n강의 수강에 실패했습니다.')
    except: 
        print('\n강의 수강에 실패했습니다.')