Пример #1
0
    def download_m3u8(self):
        course_info = self.get_course_info(forceDownload=True)
        course_name = course_info["title"]
        for chapter in course_info['chapters']:
            chapter_name = chapter['chapter_title']
            for lesson in chapter["lessons"]:
                lesson_name = lesson['lesson_name']
                media_id = lesson['media_id']
                lesson_type = lesson['type_icon']

                course_name = tools.filename_reg_check(course_name)
                chapter_name = tools.filename_reg_check(chapter_name)
                lesson_name = tools.filename_reg_check(lesson_name)

                chapter_path = tools.join_path(self.root_path, chapter_name)
                tools.check_or_make_dir(self.root_path)

                lesson_path = tools.join_path(chapter_path, lesson_name)
                tools.check_or_make_dir(lesson_path)
                print(lesson_path)
                downloader = JzwLessonM3u8Downloader(self.session,
                                                     self.course_id, media_id,
                                                     lesson_name, chapter_path)
                if "-video" in lesson_type:
                    downloader.download_m3u8()
                else:
                    downloader.download_media_info()
Пример #2
0
    def get_jzw_info(self, forceDownload=False):
        html = self.get_html()
        html_xpath = etree.HTML(html)
        jzw_title = html_xpath.xpath(
            '//h1[@class="stage-title"]/a/text()')[0].strip()

        jzw_title = tools.filename_reg_check(jzw_title)
        if not self.root_path:
            self.root_path = tools.join_path(self.path, jzw_title)
        tools.check_or_make_dir(self.root_path)
        self.jzw_info_json_path = tools.join_path(self.root_path,
                                                  self.JZW_INFO_JSON)
        if not forceDownload and os.path.exists(self.jzw_info_json_path):
            with open(self.jzw_info_json_path, "r", encoding="utf8") as f:
                content = f.read()
                if content:
                    info = json.loads(content)
                    return info

        stages_xpath = html_xpath.xpath(
            '//div[contains(@class,"stage-box js-stage-box")]')
        stage_infos = []
        jzw = dict(jzw_title=jzw_title, stage_infos=stage_infos)
        for stage_xpath in stages_xpath:
            state_title = stage_xpath.xpath(
                'div[contains(@class,"stage-title")]/text()')[0].strip()
            weeks_xpath = stage_xpath.xpath(
                'div/div[contains(@class,"week-box")]')
            week_infos = []
            stage_info = dict(state_title=state_title, week_infos=week_infos)
            stage_infos.append(stage_info)
            for week_xpath in weeks_xpath:
                week_title = week_xpath.xpath(
                    'div[contains(@class,"week-title")]/text()')[0].strip()
                courses_xpath = week_xpath.xpath(
                    'div[contains(@class,"class-box")]/a[@class="class def"]')
                course_infos = []
                week_info = dict(week_title=week_title,
                                 course_infos=course_infos)
                week_infos.append(week_info)
                index = 0
                for course_xpath in courses_xpath:
                    course_name = course_xpath.xpath(
                        'div/div[@class="class-name"]/text()')[0].strip()
                    href = "https://class.imooc.com" + \
                        course_xpath.attrib['href']  # /course/1330
                    course_id = int(href.split("/")[-1])
                    index += 1
                    course_info = dict(course_name=course_name,
                                       href=href,
                                       course_id=course_id,
                                       index=index)
                    course_infos.append(course_info)
        data_json = json.dumps(jzw, ensure_ascii=False, indent=2)
        with open(self.jzw_info_json_path, "w", encoding="utf8") as f:
            f.write(data_json)
        return jzw
Пример #3
0
def updateSrv(*args):
    """
	unzip the zip file for deployserver or copyXml to /app/update/ of remote IP 
	args:
		srv:designate deploy service name like 'monevent'
		zipfilepath:designate source *.zip directory like '/home/test/console/temp/monevent.linux64.zip.21344'
		md5filepath:designate source *.md5 directory like '/home/test/console/temp/monevent.linux64.zip.md5.21344'
		cfg.XML_CONFIG: only for exec 'copyXml' indicate directory like '/home/test/app/update/monevent/config/'

	returns:
		0 indicate succ
		1 indicate failed
	"""
    try:
        back_flag = False
        ## check ZIP and MD5
        if not md5check(args[1], args[2]):
            print("FILE [" + zipfilepath + "] MD5 check error")
            return 1
        ## Backup
        if len(args) == 4:
            unzip_path = join_path(cfg.DEPLOY_PATH_UPDATE, args[0])
            dest_path = join_path(unzip_path, args[3])
        elif len(args) == 3:
            dest_path = join_path(cfg.DEPLOY_PATH_UPDATE, args[0])
        if os.path.isdir(dest_path):
            back_path = dest_path + '_bak.' + cfg.PID
            if not os.path.exists(back_path):
                shutil.move(dest_path, back_path)
                back_flag = True
        ## Unzip
        if len(args) == 4:
            print("unzip:" + args[1] + "to" + unzip_path)
            make_dirs(unzip_path)
            unzip_file(args[1], unzip_path)
        elif len(args) == 3:
            print("unzip:" + args[1] + "to" + cfg.DEPLOY_PATH_UPDATE)
            unzip_file(args[1], cfg.DEPLOY_PATH_UPDATE)
    except Exception as e:  ###!!! opt no key
        ## Restore
        if back_flag:
            if os.path.isdir(dest_path):
                shutil.rmtree(dest_path)
            shutil.move(back_path, dest_path)
        print(traceback.format_exc())
        return 1
    else:
        ## Drop backup
        if back_flag:
            shutil.rmtree(back_path)
        return 0
Пример #4
0
def download2():
    session = Login().login()
    save_path = tools.join_path(tools.main_path(), "下载")
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1160", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第1周.认识大前端,开启无限可能").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1163", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第1.5周.前端框架分类及选型").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1159", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第2周.企业标准的开发环境搭建").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1161", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第3周.必会的前端工程化工具").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1167", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第4周.NoSQL数据库的设计与集成").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1168", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第5周.JWT登录鉴权—通用登录模块后端开发").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1162", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="5.5选修周.深入理解Vue2框架知识(选修)").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1759", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第6周.团队协作-文档管理与缺陷控制").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1164", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第7周.团队协作-版本管理").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1165", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第8周.团队协作-自动化流程").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1169", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第9周.全栈开发—首页模块").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1284", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第10周.全栈开发—用户中心").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1761", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第11周.全栈开发—发贴/回帖模块").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1182", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第12周.消息中间件开发(WebSocket通信)").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1170", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第13周.性能优化--服务端渲染").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1171", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第14周.组件化思想进阶:iview上手文章管理").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1172", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第15周.中后台权限系统:前端权限设计方案").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1173", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第16周.中后台权限系统:基于角色&菜单权限设计").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1174", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第17周.首页可视化图表与日志服务").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1175", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第18周.WebApp页面设计与开发").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1176", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第19周.WebApp前后端联调").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1177", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第20周.小程序基础与进阶").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1179", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第21周.小程序首页/菜单定制/登录开发").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1180", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第22周.小程序详情面/个人中心开发").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1178", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第23周.小程序编辑与发贴开发").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1181", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第24周.项目部署、运维与展望").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1751", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第25周.Vue3带来的新特性").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1752", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第26周.Vue3全家桶+Vite开发工具").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1753", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第27周.PC端项目Vue3首页重构").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1754", path=save_path+"\大前端:前端全栈加强版!前端全栈+全周期+多端(升级Vue3.0)",course_name="第28周.管理后台&WebApp代码重构").download_m3u8()
Пример #5
0
    def download_m3u8(self):
        jzw_info = self.get_jzw_info()
        jzw_title = jzw_info["jzw_title"]
        stage_infos = jzw_info["stage_infos"]
        for stage_info in stage_infos:
            state_title = stage_info["state_title"]
            week_infos = stage_info["week_infos"]
            for week_info in week_infos:
                week_title = week_info["week_title"]
                course_infos = week_info["course_infos"]
                for course_info in course_infos:
                    course_name = course_info['course_name']
                    course_url = course_info['href']
                    index = course_info['index']

                    jzw_title = tools.filename_reg_check(jzw_title)
                    state_title = tools.filename_reg_check(state_title)
                    week_title = tools.filename_reg_check(week_title)
                    course_name = tools.filename_reg_check(course_name)

                    course_path = tools.join_path(self.path, jzw_title,
                                                  state_title, week_title)
                    tools.check_or_make_dir(course_path)
                    # 有些课程是考试, url是/exam/123
                    if "course/" in course_url:
                        downloader = JzwCourseM3u8Downloader(
                            self.session, course_url, course_path,
                            str(index) + ". " + course_name)
                        downloader.download_m3u8()
Пример #6
0
 def __init__(self, session, jzw_url, path, jzw_name=""):
     self.session = session
     self.jzw_url = jzw_url
     self.path = path
     if jzw_name:
         jzw_name = tools.filename_reg_check(jzw_name)
         self.root_path = tools.join_path(self.path, jzw_name)
Пример #7
0
def copyFiles(file_tuplist, filepath_src, filepath_dst):
    """
	copy 
	拷贝文件到中继以及目的主机上update目录下
	args:
		file_tuplist:[('/home/test/app/update/monevent/bin/monevent.ini', 'monevent.ini'), \
			('/home/test/app/update/monevent/bin/monevent.linux', 'monevent'), \
			('/home/test/app/update/monevent/bin/monevent.xml', 'monevent.xml')]
		filepath_src:/home/test/app/update/monevent
		filepath_dst:/home/test/app/run/monevent1
		
	returns:
	"""
    for file_src, filename in file_tuplist:
        file_srcpath = os.path.dirname(file_src)
        file_dst = join_path(filepath_dst, file_srcpath[len(filepath_src):],
                             filename)
        if cfg.FLAG_DEBUG:
            print("copy %s %s" % (file_src, file_dst))
        try:
            file_base, ext = os.path.splitext(file_src)
            shutil.copyfile(file_src, file_dst)
            if ext == cfg.FILE_SUF_LINUX:
                os.chmod(file_dst, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP
                         | stat.S_IROTH)  ###修改run目录下的执行程序的执行权限
        except IOError:
            print(traceback.format_exc())
            print('copy file failed!please sure you exec stop!')
 def __init__(self, session, course_id, media_id, lesson_name, path):
     self.session = session
     self.course_id = course_id
     self.media_id = media_id
     self.lesson_name = lesson_name
     # 视频保存的绝对路径
     self.path = path
     lesson_name = tools.filename_reg_check(lesson_name)
     self.lesson_path = tools.join_path(self.path,
                                        lesson_name)  #key、m3u8保存的位置
Пример #9
0
def deploySrv(*args):
    """
	copy directories from app/update/ to app/run/
	args:
		srv:
		ctr:
		srvno:
		cfg.XML_CONFIG:only for 'copyXml' and indicate directory app/update/srvname/config/
	
	returns:
		0 indicate succ
		1 indicate failed
		
	Raises:
	"""
    try:
        ## 可以去掉小写
        srv = args[0].lower()
        ctr = args[1].lower()

        if len(args) == 3:
            filepath_src = join_path(cfg.DEPLOY_PATH_UPDATE, srv)
            filepath_dst = join_path(cfg.DEPLOY_PATH_RUN, srv + args[2])
        elif len(args) == 4:
            filepath_src = join_path(cfg.DEPLOY_PATH_UPDATE, srv, args[3])
            filepath_dst = join_path(cfg.DEPLOY_PATH_RUN, srv + args[2],
                                     args[3])
        ##文件夹以及文件均是带绝对路径的
        dir_list, file_list = getObjectLists(filepath_src)
        ##
        dic_files = getFileDic(file_list)
        ##
        file_tuplist = getFileTupleList(dic_files, ctr, args[2])
        copyDirs(dir_list, filepath_src, filepath_dst)
        copyFiles(file_tuplist, filepath_src, filepath_dst)
    except Exception as e:
        print(traceback.format_exc())
        return 1
    else:
        return 0
Пример #10
0
def copyDirs(dir_list, filepath_src, filepath_dst):
    """
	make directory dir_dst like /home/test/app/run/monevent1/log /home/test/app/run/monevent1/flow \
		/home/test/app/run/monevent1/config /home/test/app/run/monevent1/bin
	
	args:
		dir_list:['/home/test/app/update/monevent/log', '/home/test/app/update/monevent/flow', '/home/test/app/update/monevent/config', '/home/test/app/update/monevent/bin']
		filepath_src:/home/test/app/update/monevent
		filepath_dst:/home/test/app/run/monevent1
	"""
    for dir_path in dir_list:
        dir_dst = join_path(filepath_dst, dir_path[len(filepath_src):])
        print("mkdir %s" % (dir_dst))
        make_dirs(dir_dst)
Пример #11
0
    def __init__(self, session, course_url, path, course_name=None):
        """[summary]

        Args:
            session ([object]): requests已登录的session
            course_url ([string]): 课程url, 如: https://class.imooc.com/course/1330
            path ([string]): 保存的绝对路径, 在这个目录下创建course_name文件夹, 以course_name文件夹为root_path
        """
        self.session = session
        self.course_url = course_url
        self.course_id = int(course_url.split("/")[-1])
        self.path = path
        if course_name:
            self.root_path = tools.join_path(self.path, course_name)
Пример #12
0
def download(file):
    if "大家学习中有疑问该怎么办" in file: 
        return 
    with open(file, 'r', encoding="utf8") as f:
        file_content = f.read()
    data = json.loads(file_content)
    media_info = data['data']['media_info']
    if not "content" in media_info:
        print("not exist md")
        return
    
    print(file)
    md = media_info["content"]
    html = media_info['content_md']
    html = html.replace('src="//','src="http://') #有些图片地址少了http, 直接以//开头

    current_path = tools.get_dir_path(file)
    parent_path = tools.get_parent_dir_path(file)
    lesson_name = os.path.basename(current_path)

    md_path = tools.join_path(current_path, lesson_name+".md")
    if not os.path.exists(md_path):
        with open(md_path, "w", encoding="utf8") as f:
            f.write(md)

    pdf_path = tools.join_path(parent_path, lesson_name+".pdf")
    if not os.path.exists(pdf_path):
        try:
            pdfkit.from_string(html, pdf_path, options={
                "--encoding": "utf8"
            })            
        except OSError as ex:
            print("OSError",file)
            pass
        except Exception as ex:
            print("Exception",file)
            pass
Пример #13
0
def download1():
    session = Login().login()
    save_path = tools.join_path(tools.main_path(), "下载")
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1222", path=save_path+"\Java架构师体系课",course_name="第1周.万丈高楼,地基首要").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1223", path=save_path+"\Java架构师体系课",course_name="第2周.分类,推荐,搜索,评价,购物车开发").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1224", path=save_path+"\Java架构师体系课",course_name="第3周.地址,订单,支付,定时任务开发").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1225", path=save_path+"\Java架构师体系课",course_name="第4周.用户中心 ,订单/评价管理开发").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1226", path=save_path+"\Java架构师体系课",course_name="第5周.云服务器部署上线").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1227", path=save_path+"\Java架构师体系课",course_name="第6周.LVS+Nginx实现高可用集群").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1228", path=save_path+"\Java架构师体系课",course_name="第7周.主从复制高可用Redis集群").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1229", path=save_path+"\Java架构师体系课",course_name="第8周.Redis缓存雪崩,穿透").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1230", path=save_path+"\Java架构师体系课",course_name="第9周.分布式会话与单点登录SSO").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1231", path=save_path+"\Java架构师体系课",course_name="第10周.分布式搜索引擎-ES").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1232", path=save_path+"\Java架构师体系课",course_name="第11周.分布式文件系统-FastDFS+OSS").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1233", path=save_path+"\Java架构师体系课",course_name="第12周.分布式消息队列-RabbitMQ").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1234", path=save_path+"\Java架构师体系课",course_name="第13周.分布式消息队列-Kafka").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1235", path=save_path+"\Java架构师体系课",course_name="第14周.分布式锁").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1236", path=save_path+"\Java架构师体系课",course_name="第15周.读写分离、分库分表").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1237", path=save_path+"\Java架构师体系课",course_name="第16周.分布式全局ID、分布式事务和数据一致性").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1238", path=save_path+"\Java架构师体系课",course_name="第17周.分布式接口幂等性,分布式限流").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1239", path=save_path+"\Java架构师体系课",course_name="第18周.微服务架构认知、服务治理-Eureka").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1240", path=save_path+"\Java架构师体系课",course_name="第19周.负载均衡、服务通信与调用").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1241", path=save_path+"\Java架构师体系课",course_name="第20周.服务容错-Hystrix").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1242", path=save_path+"\Java架构师体系课",course_name="第21周.分布式配置中心-Config").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1243", path=save_path+"\Java架构师体系课",course_name="第22周.消息总线、服务网关").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1244", path=save_path+"\Java架构师体系课",course_name="第23周.服务调用链追踪、消息驱动").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1245", path=save_path+"\Java架构师体系课",course_name="第24周.微服务下Sentinel流量防控卫兵").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1246", path=save_path+"\Java架构师体系课",course_name="第25周.服务治理的另一条路 - Dubbo").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1247", path=save_path+"\Java架构师体系课",course_name="第26周.服务容器化-Docker").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1248", path=save_path+"\Java架构师体系课",course_name="第27周.容器技术-Cloud Foundry").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1249", path=save_path+"\Java架构师体系课",course_name="第28周.容器编排-Mesos+ Marathon").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1250", path=save_path+"\Java架构师体系课",course_name="第29周.容器编排-K8S").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1251", path=save_path+"\Java架构师体系课",course_name="第30周.容器弹性扩缩容").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1252", path=save_path+"\Java架构师体系课",course_name="第31周.高性能网络通信基石-Netty入门与提高").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1253", path=save_path+"\Java架构师体系课",course_name="第32周.高性能网络通信基石-Netty最佳实战").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1254", path=save_path+"\Java架构师体系课",course_name="第33周.基于Netty打造RPC通信框架-1").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1255", path=save_path+"\Java架构师体系课",course_name="第34周.基于Netty打造RPC通信框架-2").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1256", path=save_path+"\Java架构师体系课",course_name="第35周.应用监控与调优-工具篇").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1257", path=save_path+"\Java架构师体系课",course_name="第36周.应用监控与调优-技巧与实战篇").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1258", path=save_path+"\Java架构师体系课",course_name="第37周.JVM性能调优-理论+工具篇").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1259", path=save_path+"\Java架构师体系课",course_name="第38周.JVM性能调优-实战篇").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1260", path=save_path+"\Java架构师体系课",course_name="第39周.数据库监控与调优").download_m3u8()
    JzwCourseM3u8Downloader(session,  "https://class.imooc.com/course/1261", path=save_path+"\Java架构师体系课",course_name="第40周.Linux调优与架构调优").download_m3u8()
Пример #14
0
def undeploySrv(srv, srvno):
    """
	delete app/run/srv+srvno/
	args:
		srv, srvno:designate del path /run/srv+srvno/
	returns:
		0:indicate succ
		1:indicate failed
	"""
    print("----------Undeploy %s.%s----------" % (srv, srvno))
    try:
        ## 可以去掉小写
        srv = srv.lower()
        filepath_dst = join_path(cfg.DEPLOY_PATH_RUN, srv + srvno)
        delFilepath(filepath_dst)
    except Exception as e:
        print(traceback.format_exc())
        return 1
    else:
        return 0
Пример #15
0
def parse(base_dir):
    _base = Base()

    for filename in sorted(glob(join_path(base_dir, '*.txt'))):
        read, err = read_file(filename)

        if err:
            sys.exit(err)

        keys = read[0][1:]
        question_text = read[1]
        answers_text = read[2:]

        answers = [Answer(ans, base_dir) for ans in answers_text]
        for i, v in enumerate(keys):
            answers[i].is_true = (v == '1')

        _question = Question(filename, question_text, answers, base_dir)
        _base.questions.append(_question)

    return _base
Пример #16
0
            break


def download_all_multi(base_dir, thread_count=5):
    dir_list = get_dir_list(base_dir)
    for dir in dir_list:
        queue.put(dir)
    for i in range(thread_count):
        t = Thread(target=download_multi)
        t.daemon = True  # 设置线程daemon  主线程退出,daemon线程也会推出,即时正在运行
        t.start()
    queue.join()


def download_main_multi():
    '''
    多线程下载的入口
    '''
    if len(sys.argv) >= 2:
        dir = sys.argv[1]
    else:
        print("缺少dir参数")
        return
    download_all_multi(dir.decode("gbk"), 3)


if __name__ == "__main__":
    path = tools.join_path(tools.main_path(), "下载")
    download_all(path)

Пример #17
0
    def get_course_info(self, forceDownload=False):
        """获取课程信息, 解析章节目录
        课程(course)有多个章节(chapter), 章节有多个课时(lesson)
        格式参考course_info.json

        Args:
            url ([type]): course的url, 如: https://class.imooc.com/course/1330

        Returns:
            [type]: [description]
        """

        html = self.get_course_html()
        html_xpath = etree.HTML(html)

        title = html_xpath.xpath("/html/body//h1/a/text()")[0].strip()
        title = tools.filename_reg_check(title)
        if not self.root_path:
            self.root_path = tools.join_path(self.path, title)
        tools.check_or_make_dir(self.root_path)
        self.course_info_json_path = tools.join_path(self.root_path,
                                                     self.COURSE_INFO_JSON)
        if not forceDownload and os.path.exists(self.course_info_json_path):
            with open(self.course_info_json_path, "r", encoding="utf8") as f:
                content = f.read()
                if content:
                    info = json.loads(content)
                    return info

        introduction = html_xpath.xpath('//p[@class="con"]/text()')[0].strip()
        chapters_xpath = html_xpath.xpath(
            '//div[contains(@class,"chapter-item")]')
        chapter_infos = []
        for chapter_ in chapters_xpath:
            chapter_title = chapter_.xpath("h2/text()")[0].strip()
            lessons = []
            for a_xpath in chapter_.xpath('ul/li/a'):
                names = a_xpath.xpath(
                    'span[not(contains(@class,"finished"))]/text()')
                lesson_name = ''.join(names)
                lesson_name = lesson_name.replace(" ", "").replace("\n",
                                                                   "").strip()
                # 图标的类型, 可以用来表示课程类型, 视频、练习、图文等等
                type_icon = a_xpath.xpath('i/@class')[0]
                href = a_xpath.xpath('@href')[0]
                # href: lesson/1330#mid=41093
                # 1330是course_id, media_id相当于lesson_id
                media_id = href.split("=")[-1]
                media_id = int(media_id)
                lesson = dict(lesson_name=lesson_name,
                              href=href,
                              media_id=media_id,
                              type_icon=type_icon)
                lessons.append(lesson)
            chapter_info = {"chapter_title": chapter_title, "lessons": lessons}
            chapter_infos.append(chapter_info)
        aid_infos = self.get_aid_infos(html)
        data = dict(title=title,
                    introduction=introduction,
                    course_id=self.course_id,
                    chapters=chapter_infos,
                    aid_infos=aid_infos)
        data_json = json.dumps(data, ensure_ascii=False, indent=2)
        with open(self.course_info_json_path, "w", encoding="utf8") as f:
            f.write(data_json)
        return data