• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pypandoc.convert_file函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pypandoc.convert_file函数的典型用法代码示例。如果您正苦于以下问题:Python convert_file函数的具体用法?Python convert_file怎么用?Python convert_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了convert_file函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: docx2txt

def docx2txt(filename):
    newfilename = filename.replace(u'docx', u'txt')
    if os.name == 'nt':
        print 'nt'
        word = wc.Dispatch('Word.Application')
        doc = word.Documents.Open(filename)
        doc.SaveAs(newfilename, 4)
        doc.Close()
        word.Quit() #另存为txt文件,编码为gbk
        input_file = open(newfilename, 'r')
        gbktxt = input_file.read()
        utftxt = gbktxt.decode('gbk').encode('utf-8') #读取txt文件,将gbk转换成utf-8
        input_file.close()
        output_file = open(newfilename, 'w')
        output_file.write(utftxt) #保存utf-8文本
        output_file.close()

    else:
        '''
        # 从word(docx格式)中提取text,保存为txt
        document = Document(filename)
        docText = '\n\n'.join([
                                  paragraph.text.encode('utf-8') for paragraph in document.paragraphs
                                  ])
        print docText
        # 保存文件
        # document.save('doc/new-SL351C-A11-01.doc')

        output_file = open(newfilename, 'w')
        output_file.write(docText)
        output_file.close()
        '''
        #使用pandoc进行转换
        pypandoc.convert_file(filename,'markdown','docx',outputfile=newfilename)
        print newfilename
开发者ID:KevinBean,项目名称:chatbot,代码行数:35,代码来源:readdoc.py


示例2: main

def main():
    home_link = "https://raw.githubusercontent.com/mbadry1/DeepLearning.ai-Summary/master/"
    marks_down_links = {
        "Deeplearning.ai summary Homepage":
            home_link + "Readme.md",
        "01- Neural Networks and Deep Learning":
            home_link + "1-%20Neural%20Networks%20and%20Deep%20Learning/Readme.md",
        "02- Improving Deep Neural Networks Hyperparameter tuning, Regularization and Optimization":
            home_link + "2-%20Improving%20Deep%20Neural%20Networks/Readme.md",
        "03- Structuring Machine Learning Projects":
            home_link + "3-%20Structuring%20Machine%20Learning%20Projects/Readme.md",
        "04- Convolutional Neural Networks":
            home_link + "4-%20Convolutional%20Neural%20Networks/Readme.md",
        "05- Sequence Models":
            home_link + "5-%20Sequence%20Models/Readme.md",
    }

    # Extracting pandoc version
    print("pandoc_version:", pypandoc.get_pandoc_version())
    print("pandoc_path:", pypandoc.get_pandoc_path())
    print("\n")

    # Starting downloading and converting
    for key, value in marks_down_links.items():
        print("Converting", key)
        pypandoc.convert_file(
            value,
            'pdf',
            extra_args=['--latex-engine=xelatex', '-V', 'geometry:margin=1.5cm'],
            outputfile=(key + ".pdf")
        )
        print("Converting", key, "completed")
开发者ID:chankiw,项目名称:DeepLearning.ai-Summary,代码行数:32,代码来源:download.py


示例3: convert_index_to_html

def convert_index_to_html(directory):
    """
    Looks for the index.rst file, and converts it to index.html using pypandoc.
    """
    convert_file('{0}/index.rst'.format(directory),
                 'html',
                 outputfile='{0}/index.html'.format(directory))
开发者ID:ericmjl,项目名称:protein-systematic-characterization,代码行数:7,代码来源:make_index.py


示例4: convert_readme

def convert_readme():
    print("[*] Converting Markdown README to reStructuredText")
    import pypandoc
    rst = pypandoc.convert_file('README.md', 'rst')
    with open('README.rst', 'w+', encoding='utf-8') as f:
        f.write(rst)
    print("[*] Finished converting to README.rst ({} bytes)".format(len(rst)))
开发者ID:rednaga,项目名称:APKiD,代码行数:7,代码来源:prep-release.py


示例5: get_long_description

 def get_long_description(self, filename='README.md'):
     """ I really prefer Markdown to reStructuredText. PyPi does not.
     """
     try:
         import pypandoc
         description = pypandoc.convert_file('README.md', 'rst', 'md')
     except (IOError, ImportError):
         description = open("README.md").read()
     return description
开发者ID:tanghaibao,项目名称:goatools,代码行数:9,代码来源:setup_helper.py


示例6: convert_readme

def convert_readme():
    try:
        import pypandoc
    except ImportError:
        return read_rst()
    rst = pypandoc.convert_file('README.md', 'rst')
    with open('README.rst', 'w') as f:
        f.write(rst)
    return rst
开发者ID:nocarryr,项目名称:python-ltc,代码行数:9,代码来源:setup.py


示例7: long_description

def long_description(filename = "README.md"):
  if os.path.isfile(os.path.expandvars(filename)):
    try:
      import pypandoc
      long_description = pypandoc.convert_file(filename, "rst")
    except ImportError:
      long_description = open(filename).read()
  else:
    long_description = ""
  return long_description
开发者ID:wdbm,项目名称:junk,代码行数:10,代码来源:setup.py


示例8: finalize

def finalize(args):
    distclean()
    try:
        check_pypirc()
        repository = Repository(REPO_ROOT, args.repo)
        img_manager = ImageManager(args.release)
        pr_data = repository.find_release_pr(args.release)
        if not pr_data:
            raise ScriptError('No PR found for {}'.format(args.release))
        if not check_pr_mergeable(pr_data):
            raise ScriptError('Can not finalize release with an unmergeable PR')
        if not img_manager.check_images():
            raise ScriptError('Missing release image')
        br_name = branch_name(args.release)
        if not repository.branch_exists(br_name):
            raise ScriptError('No local branch exists for this release.')
        gh_release = repository.find_release(args.release)
        if not gh_release:
            raise ScriptError('No Github release draft for this version')

        repository.checkout_branch(br_name)

        pypandoc.convert_file(
            os.path.join(REPO_ROOT, 'README.md'), 'rst', outputfile=os.path.join(REPO_ROOT, 'README.rst')
        )
        run_setup(os.path.join(REPO_ROOT, 'setup.py'), script_args=['sdist', 'bdist_wheel'])

        merge_status = pr_data.merge()
        if not merge_status.merged and not args.finalize_resume:
            raise ScriptError(
                'Unable to merge PR #{}: {}'.format(pr_data.number, merge_status.message)
            )

        pypi_upload(args)

        img_manager.push_images()
        repository.publish_release(gh_release)
    except ScriptError as e:
        print(e)
        return 1

    return 0
开发者ID:zhangqingfnst,项目名称:compose,代码行数:42,代码来源:release.py


示例9: read_metadata

 def read_metadata(self, path, format=None):
     metadata_yaml = convert_file(path, to='markdown', format=format,
                                  extra_args=['--template', META_TEMPLATE])
     raw_metadata = yaml.safe_load(metadata_yaml)
     logger.debug(str(raw_metadata))
     metadata = {}
     for name, value in raw_metadata.items():
         name = name.lower()
         value = str(value)
         metadata[name] = self.process_metadata(name, value)
     return metadata
开发者ID:bsmith89,项目名称:pelican-pandoc-reader,代码行数:11,代码来源:__init__.py


示例10: doc_convert

def doc_convert(project, logger):
    import pypandoc
    readme_file = project.expand_path("$distutils_readme_file")
    logger.debug("Converting %s into RST format for PyPi documentation...", readme_file)
    description = pypandoc.convert_file(readme_file, "rst")
    if not hasattr(project, "description") or project.description is None or project.get_property(
            "distutils_description_overwrite"):
        setattr(project, "description", description)

    if not hasattr(project, "summary") or project.summary is None or project.get_property(
            "distutils_description_overwrite"):
        setattr(project, "summary", description.splitlines()[0].strip())
开发者ID:esc,项目名称:pybuilder,代码行数:12,代码来源:distutils_plugin.py


示例11: read_md

def read_md(path):
    long_desc = ""
    if os.path.exists(path):
        try:
            from pypandoc import convert_file
            long_desc = convert_file(path, 'rst')
        except:
            try:
                long_desc = open(path, 'r').read()
            except:
                pass
    return long_desc
开发者ID:dessibelle,项目名称:sorl-thumbnail-serializer-field,代码行数:12,代码来源:setup.py


示例12: read_input

def read_input(infilename):
    """ read text from a file

        supported formats:
            * plain text
            * pdf
            * all formats from pandoc
    """
    if ".pdf" in infilename:
        return extract_from_pdf(infilename)
    try:
        return pypandoc.convert_file(infilename, 'md')
    except Exception as e:
        # if fileinput format is not available using pypandoc so try to read it as text
        with open(infilename, "r") as infile:
            return "".join(infile.readlines())
开发者ID:stg7,项目名称:ctag,代码行数:16,代码来源:ctag.py


示例13: open

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from setuptools import setup, find_packages

# I really prefer Markdown to reStructuredText. PyPi does not. This allows me
# to have things how I'd like, but not throw complaints when people are trying
# to install the package and they don't have pypandoc or the README in the
# right place.
try:
    import pypandoc
    long_description = pypandoc.convert_file('README.md', 'rst')
except (IOError, ImportError):
    long_description = open('README.md').read()

about = {}
with open('src/clikraken/__about__.py') as f:
    exec(f.read(), about)
# now we have a about['__version__'] variable

setup(
    name=about['__title__'],
    version=about['__version__'],
    packages=find_packages('src'),
    package_dir={'': 'src'},
    author=about['__author__'],
    author_email=about['__email__'],
    license=about['__license__'],
    description=about['__summary__'],
    long_description=long_description,
    include_package_data=True,
开发者ID:zertrin,项目名称:clikraken,代码行数:31,代码来源:setup.py


示例14: convert_file

from setuptools import setup
from setuptools import find_packages

try:
    from pypandoc import convert_file
    long_description = convert_file('README.md', 'rst')
except ImportError:
    long_description = open('README.md').read()


setup(
    name='talkzoho',
    version='3.0.3',
    description='Asynchronous wrapper for Zoho\'s numerous APIs',
    long_description=long_description,
    url='https://github.com/A2Z-Cloud/Talk-Zoho',
    packages=find_packages(exclude=('tests', 'tests.*')),
    author='James Stidard',
    author_email='[email protected]',
    keywords=['talkzoho', 'Zoho', 'async', 'tornado'],
    install_requires=[
        'fuzzywuzzy',
        'python-Levenshtein',
        'inflect',
        'tornado'])
开发者ID:i-Dynamics,项目名称:Talk-Zoho,代码行数:25,代码来源:setup.py


示例15: open

#!/usr/bin/env python
import pypandoc
import os
import yara
import fnmatch
from codecs import open

rules_dir = 'apkid/rules/'
compiled_rules_path = "%srules.yarc" % rules_dir

print "[*] Converting Markdown README to reStructuredText ..."
rst = pypandoc.convert_file('README.md', 'rst')
with open('README.rst', 'w+', encoding='utf-8') as f:
  f.write(rst)
print "[*] Finished converting to README.rst (%s bytes)" % len(rst)

yara_files = {}
for root, dirnames, filenames in os.walk(rules_dir):
  for filename in fnmatch.filter(filenames, '*.yar'):
    path = os.path.join(root, filename)
    yara_files[path] = path

#print yara_files
rules = yara.compile(filepaths=yara_files)
print "[*] Compiling %d Yara rules ..." % len(yara_files)
rules.save(compiled_rules_path)
print "[*] Saved rules to %s" % compiled_rules_path

#print "[*] Registering ..."
#os.system("python setup.py register")
开发者ID:Andy10101,项目名称:APKiD,代码行数:30,代码来源:prep-release.py


示例16: prepare

import pypandoc
import panflute


def prepare(doc):
	doc.images = []
	doc.links = []


def action(elem, doc):
    if isinstance(elem, panflute.Image):
    	doc.images.append(elem)
    elif isinstance(elem, panflute.Link):
    	doc.links.append(elem)


if __name__ == '__main__':
	data = pypandoc.convert_file('example.md', 'json')
	f = io.StringIO(data)
	doc = panflute.load(f)
	doc = panflute.run_filter(action, prepare=prepare, doc=doc)
	
	print("\nImages:")
	for image in doc.images:
		print(image.url)

	print("\nLinks:")
	for link in doc.links:
		print(link.url)
开发者ID:sergiocorreia,项目名称:panflute-filters,代码行数:29,代码来源:extract_urls.py


示例17: print

    except ImportError:
        print('Wheel library missing. Please run "pip install wheel"')
        sys.exit()
    os.system('python setup.py sdist upload')
    os.system('python setup.py bdist_wheel upload')
    sys.exit()

if sys.argv[-1] == 'tag':
    print("Tagging the version on github:")
    os.system("git tag -a %s -m 'version %s'" % (version, version))
    os.system("git push --tags")
    sys.exit()

try:
    import pypandoc
    long_description = pypandoc.convert_file('README.md', 'rst') + \
        pypandoc.convert_file('docs/HISTORY.md', 'rst')
except BaseException:
    long_description = ''

license = open('LICENSE').read()

setup(
    name='callisto-core',
    version=version,
    description='Report intake, escrow, matching and secure delivery code for Callisto, an online reporting system for sexual assault.',
    long_description=long_description,
    license=license,
    author='Project Callisto',
    author_email='[email protected]',
    url='https://github.com/project-callisto/callisto-core',
开发者ID:SexualHealthInnovations,项目名称:callisto-core,代码行数:31,代码来源:setup.py


示例18: filepath

import os

from setuptools import setup


def filepath(fname):
    return os.path.join(os.path.dirname(__file__), fname)

exec(compile(open('lifelines/version.py').read(),
                  'lifelines/version.py', 'exec'))

readme_md = filepath('README.md')

try:
    import pypandoc
    readme_rst = pypandoc.convert_file(readme_md, 'rst')
except(ImportError):
    readme_rst = open(readme_md).read()


setup(
    name="lifelines",
    version=__version__,
    author="Cameron Davidson-Pilon, Jonas Kalderstam",
    author_email="[email protected]",
    description="Survival analysis in Python, including Kaplan Meier, Nelson Aalen and regression",
    license="MIT",
    keywords="survival analysis statistics data analysis",
    url="https://github.com/CamDavidsonPilon/lifelines",
    packages=['lifelines',
              'lifelines.datasets',
开发者ID:springcoil,项目名称:lifelines,代码行数:31,代码来源:setup.py


示例19: open

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Dec  1 18:39:12 2016

@author: Pranavtadepalli
"""

import pypandoc

#converts markdown to reStructured
z = pypandoc.convert_file('Users/Pranavtadepalli/WordInfo/README.rst','rst',format='markdown')

#writes converted file
with open('WordInfo/README.rst','w') as outfile:
    outfile.write(z)
开发者ID:orcapt,项目名称:orca_python,代码行数:16,代码来源:rstconvert.py


示例20:

import pypandoc

output = pypandoc.convert_file('README.md', 'rst', outputfile="README.rst")
assert output == ""
开发者ID:codedrkl,项目名称:paystack-python,代码行数:4,代码来源:convert.py



注:本文中的pypandoc.convert_file函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pypandoc.convert_text函数代码示例发布时间:2022-05-27
下一篇:
Python pypandoc.convert函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap