本文整理汇总了Python中src.tools.path.Path类的典型用法代码示例。如果您正苦于以下问题:Python Path类的具体用法?Python Path怎么用?Python Path使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Path类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: create
def create(self):
self.image_container.set_save_path(Path.image_pool_path)
self.image_container.start_download()
title = "_".join([book.property.epub.title for book in self.book_list])
title = title.strip()
Path.chdir(Path.base_path + u"/知乎电子书临时资源库/")
epub = Book(title, 27149527)
html_tmp_path = Path.html_pool_path + "/"
image_tmp_path = Path.image_pool_path + "/"
for book in self.book_list:
page = book.page_list[0]
with open(html_tmp_path + page.filename, "w") as html:
html.write(page.content)
epub.createChapter(html_tmp_path + page.filename, ExtraTools.get_time(), page.title)
for page in book.page_list[1:]:
with open(html_tmp_path + page.filename, "w") as html:
html.write(page.content)
epub.addHtml(html_tmp_path + page.filename, page.title)
for image in self.book["image_list"]:
epub.addImg(image_tmp_path + image["filename"])
epub.addLanguage("zh-cn")
epub.addCreator("ZhihuHelp1.7.0")
epub.addDesc(u"该电子书由知乎助手生成,知乎助手是姚泽源为知友制作的仅供个人使用的简易电子书制作工具,源代码遵循WTFPL,希望大家能认真领会该协议的真谛,为飞面事业做出自己的贡献 XD")
epub.addRight("CC")
epub.addPublisher("ZhihuHelp")
Debug.logger.debug(u"当前目录为")
Path.pwd()
epub.addCss(Path.base_path + u"/epubResource/markdown.css")
epub.addCss(Path.base_path + u"/epubResource/front.css")
epub.buildingEpub()
return
开发者ID:hmilyfyj,项目名称:ZhihuHelp__Python,代码行数:32,代码来源:epub_creator.py
示例2: __init__
def __init__(self, recipe_kind='Notset', read_list='ReadList.txt', url=None, debug=False):
u"""
配置文件使用$符区隔,同一行内的配置文件归并至一本电子书内
:param recipe_kind:
:param read_list: default value: ReadList.txt
:param url:
:param debug:
:return:
"""
self.recipe_kind = recipe_kind
self.read_list = read_list
self.url = url
log.warning_log(u"website type: " + str(self.recipe_kind) + '\n')
import logging
if debug is True:
Debug.logger.setLevel(logging.DEBUG)
else:
Debug.logger.setLevel(logging.INFO)
Debug.logger.debug(u"read_list: " + str(self.read_list))
Debug.logger.debug(u"url: " + str(self.url))
Debug.logger.debug(u"recipe type:" + str(recipe_kind))
Path.init_base_path(recipe_kind) # 设置路径
Path.init_work_directory() # 创建路径
self.init_database() # 初始化数据库
Config._load()
return
开发者ID:gitter-badger,项目名称:EE-Book,代码行数:28,代码来源:main.py
示例3: create_book
def create_book(self, book_package):
book_package.image_container.set_save_path(Path.image_pool_path)
book_package.image_container.start_download()
title = book_package.get_title()
if not title:
# 电子书题目为空时自动跳过
# 否则会发生『rm -rf / 』的惨剧
return
Path.chdir(Path.base_path + u'/知乎电子书临时资源库/')
epub = Epub(title)
html_tmp_path = Path.html_pool_path + u'/'
image_tmp_path = Path.image_pool_path + u'/'
epub.set_creator(u'ZhihuHelp1.7.0')
epub.set_book_id()
epub.set_output_path(Path.result_path)
epub.add_css(Path.base_path + u'/www/css/markdown.css')
epub.add_css(Path.base_path + u'/www/css/customer.css')
epub.add_css(Path.base_path + u'/www/css/normalize.css')
for book in book_package.book_list:
page = book.page_list[0]
with open(html_tmp_path + page.filename, u'w') as html:
html.write(page.content)
epub.create_chapter(html_tmp_path + page.filename, page.title)
for page in book.page_list[1:]:
with open(html_tmp_path + page.filename, u'w') as html:
html.write(page.content)
epub.add_html(html_tmp_path + page.filename, page.title)
epub.finish_chapter()
for image in book_package.image_list:
epub.add_image(image_tmp_path + image['filename'])
epub.create()
Path.reset_path()
return
开发者ID:LichAmnesia,项目名称:ZhihuHelp,代码行数:33,代码来源:book.py
示例4: filepath
def filepath(answertmp = []):
if answertmp:
answerpath = Path.answer_path+'/Answer_qid_aid/'+'{0}'.format(answertmp['question_id'])
if not Path.is_dir(answerpath):
Path.mkdirs(answerpath)
filename = '{0}'.format(answertmp['question_id'])+'_'+'{0}'.format(answertmp['answer_id'])+'.txt'
return Path.join_dir(answerpath,filename)
开发者ID:HiltonWei,项目名称:zhihu,代码行数:7,代码来源:db.py
示例5: create_book
def create_book(self, command, counter):
Path.reset_path()
Debug.logger.info(u"开始制作第 {} 本电子书".format(counter))
Debug.logger.info(u"对记录 {} 进行分析".format(command))
task_list = CommandParser.get_task_list(command) # 分析命令
if len(task_list) == 0:
return
for task in task_list:
if Config.debug_for_create_book:
pass
else:
Worker.distribute(task)
Debug.logger.info(u"网页信息抓取完毕")
task_result_list = []
for task in task_list:
task_result = TaskResult(task)
task_result.extract_data()
task_result_list.append(task_result)
Debug.logger.info(u"数据库信息获取完毕")
# 下载图片
for task_result in task_result_list:
task_result.download_img()
Debug.logger.info(u"所有任务图片获取完毕")
# 按体积自动分卷
# 渲染html && 压缩为电子书
book = Book(task_result_list)
book_list = book.auto_split(Config.max_book_size_mb * 1024)
for chapter in book_list:
chapter.create_book()
return
开发者ID:EleVenPerfect,项目名称:OTHERS,代码行数:35,代码来源:main.py
示例6: add_index_html
def add_index_html(self, src, title):
Path.copy(src, EpubPath.html_path)
filename = Path.get_filename(src)
new_src = u'html/' + filename
resource_id = self.opf.add_html(new_src)
self.toc.add_item(resource_id, new_src, title)
return
开发者ID:HowieWang,项目名称:jianshu2e-book,代码行数:7,代码来源:epub.py
示例7: __init__
def __init__(self):
u"""
配置文件使用$符区隔,同一行内的配置文件归并至一本电子书内
"""
init.init_database()
Path.init_base_path()
Config._load()
return
开发者ID:hmilyfyj,项目名称:ZhihuHelp__Python,代码行数:8,代码来源:main.py
示例8: create_chapter
def create_chapter(self, src, title):
Path.copy(src, EpubPath.html_path)
filename = Path.get_filename(src)
new_src = u'html/' + filename
resource_id = self.opf.add_title_page_html(new_src)
self.directory.create_chapter(new_src, title)
self.toc.create_chapter(resource_id, new_src, title)
return
开发者ID:HowieWang,项目名称:jianshu2e-book,代码行数:8,代码来源:epub.py
示例9: __init__
def __init__(self):
u"""
配置文件使用$符区隔,同一行内的配置文件归并至一本电子书内
"""
Path.init_base_path() # 设置路径
Path.init_work_directory() # 创建路径
self.init_database() # 初始化数据库
Config._load()
return
开发者ID:HowieWang,项目名称:jianshu2e-book,代码行数:9,代码来源:main.py
示例10: __init__
def __init__(self):
# 初始化目录结构
Path.init_base_path()
Path.init_work_directory()
# 初始化数据库链接
DB.init_database()
# 初始化配置
Config.init_config()
return
开发者ID:EleVenPerfect,项目名称:OTHERS,代码行数:9,代码来源:main.py
示例11: create_book
def create_book(self):
# 确定文件信息
title = Match.fix_filename(self.book_title)
if self.is_split:
title = self.book_title + u'_卷{}'.format(self.chapter_no)
# 先切换到电子书临时资源目录下
Path.chdir(Path.book_pool_path)
epub = Epub(title)
for task_result in self.task_result_list:
chapter_src = ''
# info_page
if task_result.task.task_type == Type.question:
chapter_src = self.generate_question_info_page(task_result.info_page)
elif task_result.task.task_type == Type.answer:
chapter_src = self.generate_question_info_page(task_result.info_page)
elif task_result.task.task_type == Type.collection:
chapter_src = self.generate_collection_info_page(task_result.info_page)
elif task_result.task.task_type == Type.topic:
chapter_src = self.generate_topic_info_page(task_result.info_page)
elif task_result.task.task_type == Type.author:
chapter_src = self.generate_author_info_page(task_result.info_page)
elif task_result.task.task_type == Type.column:
chapter_src = self.generate_column_info_page(task_result.info_page)
elif task_result.task.task_type == Type.article:
chapter_src = self.generate_article_info_page(task_result.info_page)
epub.create_chapter(chapter_src, task_result.get_title())
for question in task_result.question_list:
# 添加图片文件
for filename in question.img_filename_list:
epub.add_image(Path.image_pool_path + '/' + filename)
question_src = self.generate_question_page(question)
epub.add_html(question_src, question.question_info.title)
for column in task_result.column_list:
# 添加图片文件
for filename in column.img_filename_list:
epub.add_image(Path.image_pool_path + '/' + filename)
for article in column.article_list:
article_src = self.generate_article_page(article)
epub.add_html(article_src, article.title)
epub.finish_chapter()
epub.set_creator(u'ZhihuHelp1.8.0')
epub.set_language(u'zh-cn')
epub.set_book_id()
epub.set_output_path(Path.result_path)
epub.add_css(Path.base_path + u'/www/css/markdown.css')
epub.add_css(Path.base_path + u'/www/css/customer.css')
epub.add_css(Path.base_path + u'/www/css/normalize.css')
epub.add_css(Path.base_path + u'/www/css/bootstrap.css')
epub.create()
Path.reset_path()
return
开发者ID:EleVenPerfect,项目名称:OTHERS,代码行数:55,代码来源:book.py
示例12: create_book
def create_book(command, counter):
Path.reset_path()
Debug.logger.info(u"开始制作第 {} 本电子书".format(counter))
Debug.logger.info(u"对记录 {} 进行分析".format(command))
task_package = ReadListParser.get_task(command) # 分析命令
if not task_package.is_work_list_empty():
worker_factory(task_package.work_list) # 执行抓取程序
Debug.logger.info(u"网页信息抓取完毕")
if not task_package.is_book_list_empty():
Debug.logger.info(u"开始从数据库中生成电子书")
book = Book(task_package.book_list)
book.create()
return
开发者ID:HowieWang,项目名称:jianshu2e-book,代码行数:16,代码来源:main.py
示例13: download_img
def download_img(self):
from src.container.image_container import ImageContainer
img_container = ImageContainer()
img_src_dict = Match.match_img_with_src_dict(self.content)
self.img_filename_list = []
for img in img_src_dict:
src = img_src_dict[img]
filename = img_container.add(src)
self.img_filename_list.append(filename)
self.content = self.content.replace(img, Match.create_img_element_with_file_name(filename))
# 下载文章封面图像
filename = img_container.add(self.image_url)
self.img_filename_list.append(filename)
self.image_url = Match.create_local_img_src(filename)
# 下载用户头像
filename = img_container.add(self.author_avatar_url)
self.img_filename_list.append(filename)
self.author_avatar_url = Match.create_local_img_src(filename)
img_container.start_download()
# 下载完成后,更新图片大小
for filename in self.img_filename_list:
self.total_img_size_kb += Path.get_img_size_by_filename_kb(filename)
return
开发者ID:EleVenPerfect,项目名称:OTHERS,代码行数:27,代码来源:article.py
示例14: init_database
def init_database():
if Path.is_file(Path.db_path):
DB.set_conn(sqlite3.connect(Path.db_path))
else:
DB.set_conn(sqlite3.connect(Path.db_path))
with open(Path.sql_path) as sql_script:
DB.cursor.executescript(sql_script.read())
DB.commit()
开发者ID:HowieWang,项目名称:jianshu2e-book,代码行数:8,代码来源:main.py
示例15: getAnswerContentFromFile
def getAnswerContentFromFile( answertmp = {}):
if not answertmp:
return
filepath_name = Ans2File.filepath(answertmp)
if Path.is_file(filepath_name):
with open(filepath_name, 'r') as f:
fileContent = f.read()
answertmp['content'] = fileContent
return
开发者ID:HiltonWei,项目名称:zhihu,代码行数:9,代码来源:db.py
示例16: add_html
def add_html(self, src, title):
u"""
add_index为add_html不需要添加文件时的特殊情况
"""
self.add_index_html(src, title)
filename = Path.get_filename(src)
new_src = u'html/' + filename
self.directory.add_html(new_src, title)
return
开发者ID:HowieWang,项目名称:jianshu2e-book,代码行数:9,代码来源:epub.py
示例17: create_chapter
def create_chapter(self, src, title):
template = self.get_template('directory', 'item_root')
item = template.format(href=Path.get_filename(src), title=title)
if self.chapter_deep == 0:
template = self.get_template('directory', 'chapter')
item = template.format(item=item, title=u'目录')
self.content += item
self.chapter_deep += 1
return
开发者ID:HowieWang,项目名称:jianshu2e-book,代码行数:10,代码来源:directory.py
示例18: init_database
def init_database():
if Path.is_file(Path.db_path):
Debug.logger.debug(u"Connect to the database...")
Debug.logger.debug(u"db_path: " + str(Path.db_path))
DB.set_conn(sqlite3.connect(Path.db_path))
else:
Debug.logger.debug(u"Create db file...")
DB.set_conn(sqlite3.connect(Path.db_path))
with open(Path.sql_path) as sql_script:
DB.cursor.executescript(sql_script.read())
DB.commit()
开发者ID:gitter-badger,项目名称:EE-Book,代码行数:11,代码来源:main.py
示例19: create_book
def create_book(command, counter):
Path.reset_path()
Debug.logger.info(u"Ready to make No.{} e-book".format(counter))
Debug.logger.info(u"Analysis {} ".format(command))
task_package = UrlParser.get_task(command) # 分析命令
Debug.logger.debug(u"#Debug:#task_package是:" + str(task_package))
if not task_package.is_work_list_empty():
worker_factory(task_package.work_list) # 执行抓取程序
Debug.logger.info(u"Complete fetching from web")
file_name_set = None
if not task_package.is_book_list_empty():
Debug.logger.info(u"Start generating e-book from the database")
book = Book(task_package.book_list)
file_name_set = book.create()
if file_name_set is not None:
file_name_set2list = list(file_name_set)
file_name = '-'.join(file_name_set2list[0:3])
return file_name
return u"Oops! no epub file produced"
开发者ID:gitter-badger,项目名称:EE-Book,代码行数:22,代码来源:main.py
示例20: create_book
def create_book(self, book_package):
book_package.image_container.set_save_path(Path.image_pool_path)
book_package.image_container.start_download()
title = book_package.get_title()
Debug.logger.debug(u"title of the e-book:" + str(title))
if not title:
# 电子书题目为空时自动跳过
# 否则会发生『rm -rf / 』的惨剧
return
Path.chdir(Path.in_base_path + u'/e-books_tmp_source')
epub = Epub(title)
html_tmp_path = Path.html_pool_path + u'/'
image_tmp_path = Path.image_pool_path + u'/'
epub.set_creator(u'EEBookV0-1')
epub.set_language(u'zh')
epub.set_book_id()
epub.set_output_path(Path.result_path)
epub.add_css(Path.in_base_path + u'/www/css/markdown.css')
epub.add_css(Path.in_base_path + u'/www/css/customer.css')
epub.add_css(Path.in_base_path + u'/www/css/normalize.css')
epub.add_css(Path.in_base_path + u'/www/css/bootstrap.css')
# epub.add_css(Path.in_base_path + u'/www/css/article.css') # TODO: 来自新浪,需要精简
for book in book_package.book_list:
page = book.page_list[0]
with open(html_tmp_path + page.filename, 'w') as html:
html.write(page.content)
if '_' in page.title:
page.title = ''.join(page.title.split('_')[1:]) # 删除章节前缀
epub.create_chapter(html_tmp_path + page.filename, page.title)
for page in book.page_list[1:]:
with open(html_tmp_path + page.filename, 'w') as html:
html.write(page.content)
epub.add_html(html_tmp_path + page.filename, page.title)
epub.finish_chapter()
for image in book_package.image_list:
epub.add_image(image_tmp_path + image['filename'])
epub.create()
Path.reset_path()
return
开发者ID:mozii,项目名称:EE-Book,代码行数:39,代码来源:book.py
注:本文中的src.tools.path.Path类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论