コード例 #1
0
ファイル: scribdl.py プロジェクト: golmedon/scribd-downloader
    def get_book(self):
        book_id = self._get_book_id()
        token = self._get_token(book_id)

        chapter = 1
        string_text = ''

        while True:
            url = self._format_content_url(book_id, chapter, token)
            response = requests.get(url)

            try:
                json_response = json.loads(response.text)
                for block in json_response['blocks']:
                    if block['type'] == 'text':
                        string_text += ' '.join(
                            self._extract_text(block)) + '\n\n'
                        print(string_text)
                    elif block['type'] == 'image':
                        image_url = self._format_image_url(
                            book_id, chapter, block['src'], token)
                        imagename = block['src'].replace('images/', '')
                        string_text += '![{}]({})\n\n'.format(
                            imagename, image_url)

                chapter += 1

            except json.decoder.JSONDecodeError:
                print('No more content being exposed by Scribd!')
                pdf_out = '{}.pdf'.format(book_id)
                print('Generating PDF file: {}'.format(pdf_out))
                md2pdf(pdf_out, md_content=string_text)
                break
コード例 #2
0
    def __exit__(self, exc_type, exc_value, traceback):
        """Exit Function to implement with open method to manage report file.

        :param exc_type: Indicates class of exception
        :param exc_value: Indicates type of exception
        :param traceback: Report with all of the information needed to solve the exception
        """
        self.report_file.close()
        # Opening the file in reading format
        with open(self.filepath, "r", encoding="utf-8") as filemd:
            file_str = filemd.read()

        # Parse incomptibility syntax
        mdtopdf = self.parse_pdf(file_str)
        # Generate pdf report if generate_pdf is selected
        if self.generate_pdf:
            directory = path.dirname(path.abspath(self.filepath))
            filename, _ = path.splitext(path.basename(self.filepath))
            md2pdf(
                f"{directory}/{filename}.pdf",
                md_content=mdtopdf,
                md_file_path=None,
                css_file_path="./templates/markdown-pdf.css",
                base_url=directory,
            )
コード例 #3
0
 def _markdown_to_pdf(self):
     """
     Converts markdown to PDF.
     """
     md2pdf(self.pdf_path,
            md_file_path=self.input_content,
            base_url=os.getcwd())
コード例 #4
0
def _get_documents(heads, repo, branches):
    css_file = _copy_css_to_tmp()
    doc_path = os.path.abspath(os.path.join("..", "docs"))
    base_path = os.path.abspath(os.path.join(".."))
    for branch in branches:
        print("Branch:", branch)
        local_name = branch.split("origin/")[-1]
        if local_name in heads:
            repo.git.checkout(local_name)
        else:
            repo.git.checkout('-t', branch)
        repo.remotes.origin.pull("/".join(branch.split("/")[1:]))
        language_name = local_name.split("/")[-1].strip()
        pdf_path = os.path.abspath(os.path.join(base_path, language_name))
        if os.path.exists(pdf_path):
            shutil.rmtree(pdf_path)
        os.mkdir(pdf_path)
        files = os.listdir(doc_path)
        files.sort()
        print(files)
        mdcontent = ""
        for file in files:
            if ".md" in file:
                md_file_path = os.path.join(doc_path, file)
                with open(md_file_path, 'r') as f:
                    mdcontent += "\n".join(f.readlines())
                mdcontent += "\n"
        filename = "{}_a4kWs.pdf".format(language_name)
        destination = os.path.join(pdf_path, filename)
        md2pdf(destination, md_content=mdcontent, css_file_path=css_file)
        print("Created ", destination)
    repo.git.checkout('master')
    os.remove(css_file)
コード例 #5
0
def convert_md_to_pdf(dirname):
    original_dir = os.getcwd()

    os.chdir(dirname)
    for file in glob.glob('*.md'):
        pdf_list = glob.glob('*.pdf')
        new_filename = file.replace('.md', '.pdf')
        if new_filename not in pdf_list and new_filename.lower().replace(
                ' ', '-') not in pdf_list:
            md2pdf.md2pdf(new_filename, md_file_path=file)

    os.chdir(original_dir)
コード例 #6
0
                else:
                    line += ". "
                    text = text.capitalize()
            else:
                line += " "
            line += text
    if len(line) > 0:
        script += str(cntr) + ". " + line + ".\n"

    with open("scripts/script-" + str(x) + ".txt", "w") as w:
        w.write(script)
    with open("scripts/script-" + str(x) + ".md", "w") as w:
        w.write(script)
    md2pdf(
        "scripts/script-" + str(x) + ".pdf",
        script.replace(
            "## Script",
            "<div style=\"page-break-after: always\"></div>\n\n## Script"))

scripta.sort()

line: str = ""

script: str = "# Script for low-tone and high-tone standalone words.\n"
script += "\n"
script += "The following text contains a list of words with and without high tones.\n"
script += "\n"
script += "Both the high tones and low tones are level and do not glide.\n"
script += "\n"
script += "The final word vowels, unless otherwise marked, should be the word final nasalized high-fall glide.\n"
script += "\n"
コード例 #7
0
ファイル: cr_mkdown.py プロジェクト: deytalytics/deyblog
from md2pdf.core import md2pdf

md2pdf(pdf_file_path=".",
       md_content="content/info-hairball.md",
       md_file_path=".",
       css_file_path=".",
       base_url="https://deytalytics.github.io/deyblog")
コード例 #8
0
    return 'bad name'


# get the title of the page
def getPageTitle(fileName):
    return names[pages.index(fileName)]


# sidebar file is requires
sidebar = '_Sidebar.md'
if sidebar in files:
    # process sidebar
    sidebarText = readFile(sidebar)
    pages = getPageOrder(sidebarText)
    names = getPageNames(sidebarText)

    # combine files and write to both markdown and pdf
    combined = '\n\n---\n\n'.join([
        '#' + getPageTitle(name) + '\n\n' + readFile(name) for name in pages
        if name != 'bad name'
    ])
    writeFile('combined.md', combined)
    print('Combined markdown finished!')
    md2pdf('combined.pdf',
           md_content=combined,
           css_file_path='styles.css',
           base_url=path)
    print('PDF finished!')
else:
    print('Failed to find _Sidebar.md')
コード例 #9
0
 def md_to_pdf(self, pdf_file, body, css_file_path):
     md2pdf(pdf_file,
            md_content=body,
            md_file_path=None,
            css_file_path=css_file_path,
            base_url=None)