We wrap all the functionality of the tools built in the `mediumapi` and the `convert` modules to upload the rendered markdown document to Medium

nb2medium[source]

nb2medium(title:"The title of your article", notebook:"Path to your notebook", log_level:"The minimum reported logging level (debug, info, warning, error or critical)"='info', log_to_stdout:"Whether logging should be redirected to stdout (internal use)"=False)

first_article = nb2medium(title = 'First test',
                          notebook = '../samples/test-notebook.ipynb')
converter:INFO - Found a hide-source tag in cell #35.
converter:INFO - Found a hide-output tag in cell #36.
converter:INFO - Found a hide-cell tag in cell #37.
converter:INFO - Gist notebooktest.py from cell 26 succesfully uploaded!
converter:INFO - Gist print.py from cell 27 succesfully uploaded!
converter:INFO - Gist pandas.py from cell 30 succesfully uploaded!
converter:INFO - Gist pandas.py.csv from cell 30 succesfully uploaded!
converter:INFO - Gist pandas-doubleupload.py from cell 33 succesfully uploaded!
converter:INFO - Gist pandas-doubleupload.py.csv from cell 33 succesfully uploaded!
converter:INFO - Detected 4 plots and 2 local images in notebook.
converter:INFO - Markdown document written to ../samples/test-notebook/test-notebook.md
uploader:INFO - Draft of 'First test' from test-notebook.ipynb notebook uploaded to Medium: https://medium.com/@lucha6/603f9bac5eb

CLI

nb2medium can both be used from python or as a CLI thanks to the amazing @call_parse decorator developed by fastcore. You can use nb2medium from the command line in the following way

To get the help

!nb2medium --help
usage: nb2medium [-h] [--log_level LOG_LEVEL] [--log_to_stdout] title notebook

positional arguments:
  title                  The title of your article
  notebook               Path to your notebook

optional arguments:
  -h, --help             show this help message and exit
  --log_level LOG_LEVEL  The minimum reported logging level (debug, info,
                         warning, error or critical) (default: info)
  --log_to_stdout        Whether logging should be redirected to stdout
                         (internal use) (default: False)

Uploading article through the CLI

Both the title and notebook arguments are positional and hence you need to pass them in order in addition to that if your title contains any spaces you will need to put it between double or single quotes.

%%sh
nb2medium "My really cool article" ../samples/test-gist-output-df.ipynb
converter:INFO - Gist pandas.py from cell 0 succesfully uploaded!
converter:INFO - Gist pandas.py.csv from cell 0 succesfully uploaded!
converter:INFO - Detected 0 plots and 0 local images in notebook.
converter:INFO - Markdown document written to ../samples/test-gist-output-df/test-gist-output-df.md
uploader:INFO - Draft of 'My really cool article' from test-gist-output-df.ipynb notebook uploaded to Medium: https://medium.com/@lucha6/e3e271eea8a4

Note: I am using the %%sh and the shebang ! magic to emulate what you would usually run from bash, zshell or your preferred shell