mirror of
https://github.com/not-kennethreitz/markdownplease.com.git
synced 2026-06-05 23:20:19 +00:00
26 lines
533 B
Python
26 lines
533 B
Python
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
|
|
|
from mercury_parser import ParserAPI
|
|
from html2text import html2text
|
|
|
|
mercury = ParserAPI(api_key=os.environ['MERCURY_API_KEY'])
|
|
|
|
def convert(html, title=None):
|
|
if title:
|
|
title = '# {}'.format(title)
|
|
html = '\n\n'.join([title, html])
|
|
|
|
return html2text(html)
|
|
|
|
def meh(url):
|
|
try:
|
|
d = mercury.parse(url)
|
|
return convert(d.content, title=d.title)
|
|
except KeyError:
|
|
return None
|
|
|
|
|
|
if __name__ == '__main__':
|
|
print meh('http://kennethreitz.org/') |