How i create gists and write them to markdown table

title image


I have hundreds of code snippets in OneNote, I want to put them into python cheat file. I achieve this by creating gists and write them into my markdown file with Python. You can see the result at my blog.


Create a gist for each code snippet, then embed the <script> tag into markdown file.

First we need to generate a new personal token here.

We only need the permission that relate to gist.

Then we move on to coding.


import requests
gist_content = "import operator\ns = [[1, 2], [1, 0], [2, 0]]\ns.sort(key=lambda x: (x[0], x[1]))"
gist_name = "create gist"

new_gist = {
    "description": "[Hello] #python",
    "public": "true",
    "files": {
        gist_name: {
            "content": gist_content

response =
    # wizna is my GitHub username, change it to yours
    auth=('wizna', 'YOUR PERSONAL TOKEN STRING'))

gist_id = response.json()['id']
gist_address = '<script src=""></script>' % gist_id


<script src=""></script>

Written on July 16, 2019