Giter Club home page Giter Club logo

Comments (2)

illava avatar illava commented on May 21, 2024
import os
import nbconvert
from future import print function
folders = ['01-python-tools',
           '02-python-essentials',
           '03-numpy',
           '04-scipy',
           '05-advanced-python',
           '06-matplotlib',
           '07-interfacing-with-other-languages',
           '08-object-oriented-programming',
           '09-theano',
           '10-something-interesting',
           '11-useful-tools',
           '12-pandas'
           ]
mdtxt = open("README.md", encoding="utf8").read()
i = 0
for folder in folders:
    for file in os.listdir(folder):
        if file.endswith(".png"):
            open(file.replace(".png", "temp.png"), "wb").write(open(os.path.join(folder, file), "rb").read())
        if not file.endswith(".ipynb"):
            continue
        i += 1
        path = os.path.join(folder, file)
        print(path)
        converted = nbconvert.export(nbconvert.MarkdownExporter, path)
        markdown = converted[0].replace(".png", "temp.png")
        pics = converted[1]["outputs"]
        for pic_name in pics:
            picpath = pic_name.replace(".png", "temp.png")
            if (os.path.exists(picpath)):
                markdown.replace(picpath, picpath.replace("temp.png", str(i) + "temp.png"))
                picpath = picpath.replace("temp.png", str(i) + "temp.png")
            with open(picpath, "wb") as p:
                p.write(pics[pic_name])
        mdtxt += markdown
open("final.md", "w", encoding="utf8").write(mdtxt)
# open Atom markdown-preview and save as html
# open html in chrome and print to pdf
# or other method to convert md to pdf
os.remove("final.md")
for file in os.listdir("."):
    if file.endswith("temp.png"):
        os.remove(file)

from notes-python.

Jackiexiao avatar Jackiexiao commented on May 21, 2024

thx! it works. But in final.md, it have lots of lines of "hello world", so I delete it.

I used vscode extension "Markdown PDF" to convert markdown to pdf

from notes-python.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.