Convert Wordpress to Markdown Files
_post = _getpost('https://outerbounds.com/wp-json/wp/v2/posts/220')
assert _post

_post = _getpost(post_id=247, baseurl='https://outerbounds.com/wp-json/wp/v2/posts') #this is an alternate way of calling this 
assert _post

url2api[source]

url2api(url)

Get the wordpress api endpoint to retrieve post from the public url

url2api allows you to retrieve the full api endpoint to get the contents of the wordpress article as described here from any public-facing wordpress url!

test_eq(url2api('https://outerbounds.com/blog/notebooks-in-production-with-metaflow/'), 'https://outerbounds.com/wp-json/wp/v2/posts/220')

class WP[source]

WP(url:str=None, baseurl:str=None, post_id:int=None)

Instantiating a WP object will allow you to get access to useful properties that can render as front matter.

_post = WP('https://outerbounds.com/blog/notebooks-in-production-with-metaflow/')
print(_post.frontmatter)
---
title: "Notebooks In Production With Metaflow"
date: "2022-02-09T22:59:06"
image: "https://outerbounds.com/wp-content/uploads/2022/02/Screen-Shot-2022-02-09-at-12.45.20-pm-1024x525.png"
slug: "notebooks-in-production-with-metaflow"
---

_result="""---
title: "Notebooks In Production With Metaflow"
date: "2022-02-09T22:59:06"
image: "https://outerbounds.com/wp-content/uploads/2022/02/Screen-Shot-2022-02-09-at-12.45.20-pm-1024x525.png"
slug: "notebooks-in-production-with-metaflow"
---
"""
test_eq(_post.frontmatter, _result)

The markdown representation is also available as a property (below we print the first 1,000 characters:

print(_post.markdown[:1500])
---
title: "Notebooks In Production With Metaflow"
date: "2022-02-09T22:59:06"
image: "https://outerbounds.com/wp-content/uploads/2022/02/Screen-Shot-2022-02-09-at-12.45.20-pm-1024x525.png"
slug: "notebooks-in-production-with-metaflow"
---


By Hamel Husain


*Learn how to use notebooks in production ML workflows with a new Metaflow feature*


When building production-ready machine learning systems, it is critical to monitor the health and performance of those systems with reports and visualizations. Furthermore, allowing for rapid debugging and interactive introspection is critical when workflows fail or do unexpected things. Jupyter notebooks have often been a preferred tool of data scientists for these tasks of visualization, exploration, debugging, and rapid iteration.  Ironically, many production systems do not integrate appropriately with notebooks, which can significantly frustrate progress on these tasks.


Indeed, in the field of data science tooling, one of the most [hotly-contested](https://mlops.community/jupyter-notebooks-in-production/) questions is whether notebooks are suitable for production use. We believe that tools should strive to meet data scientists where they are instead of forcing them to adapt approaches from other disciplines not suited to their needs. This is why we are excited to introduce **Notebook Cards**, which allow data scientists to use notebooks for visualizing and debugging production workflows and help to bridge the MLOps divide between 

Getting Hidden Posts

A wordpress post may note be public (i.e. it might have a status other than published). In that case, you will need two pieces of information to retrieve the markdown content for that post.

  1. The url for the api. This is <your_site>/wp-json/v2/posts, for example https://outerbounds.com/wp-json/wp/v2/posts. Note: This is the api route to retrieve a single WP post.

  2. The post id you wish to convert to markdown. The post id can be extracted from wordpress edit url, for example the id for https://outerbounds.com/wp-admin/post.php?post=220&action=edit is 220.

For example, we can get the contets of a post which has an id of 220 as follows:

_post = WP(baseurl='https://outerbounds.com/wp-json/wp/v2/posts', post_id=220)
test_eq(_post.title, 'Notebooks In Production With Metaflow')

Downloading Images

nb2md also Downloads Images for you, and puts the images in a folder named _<name_of_markdown_file>_data/

assert len(_post.mdimages) == 5
_post.tomd()
_data_dir = Path('_notebooks-in-production-with-metaflow_data/')
assert _data_dir.exists()
_data_dir.ls()
Writing: notebooks-in-production-with-metaflow.md
(#5) [Path('_notebooks-in-production-with-metaflow_data/4_img'),Path('_notebooks-in-production-with-metaflow_data/2_img'),Path('_notebooks-in-production-with-metaflow_data/3_img'),Path('_notebooks-in-production-with-metaflow_data/1_img'),Path('_notebooks-in-production-with-metaflow_data/0_img')]

The paths to downloaded images are also automatically replaced in the markdown file:

_md = Path('notebooks-in-production-with-metaflow.md').read_text()
_img_url=r'https://lh4.googleusercontent.com/-8XLZezB4E7s64BQcu-KTZO0VWh4VyKXpNhVwzSqPSgrAC_3qu62OZ-fleSr5mGRqPYTcEm5ed_ZKx8o6W0o2JIQea1kCemhuX5cZMMZRRtumGi0yf0mIp3DJWvDzKGpUR9GP8ug'
assert _img_url in _post.raw_markdown
assert _img_url not in _md

CLI Utility For Wordpress To Markdown

wp2md[source]

wp2md(url_or_id:"the public URL of the WP article OR the post id", apiurl:"the base url for the wordpress api to retrieve posts for your site."='https://outerbounds.com/wp-json/wp/v2/posts', dest_path:"The path to save the markdown file to"='.', dest_file:"Name of destination markdown file. If not given defaults to the slug indicated in wordpress"=None, no_download:"Pass this flag to NOT download any images locally"=False)

Convert A wordpress post into markdown file with front matter.