mirror of
https://github.com/not-kennethreitz/markdownplease.com.git
synced 2026-06-05 07:06:12 +00:00
user mercury parser
This commit is contained in:
+4
-14
@@ -1,21 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
|
||||
|
||||
import os
|
||||
|
||||
import requests
|
||||
from mercury_parser import ParserAPI
|
||||
from html2text import html2text
|
||||
|
||||
READABILITY_URL = 'https://www.readability.com/api/content/v1/parser'
|
||||
|
||||
def readability(url):
|
||||
token = os.environ.get('READABILITY_TOKEN')
|
||||
params = {'url': url, 'token': token}
|
||||
|
||||
r = requests.get(READABILITY_URL, params=params)
|
||||
return r.json()['content'], r.json()['title']
|
||||
mercury = ParserAPI(api_key=os.environ['MERCURY_API_KEY'])
|
||||
|
||||
def convert(html, title=None):
|
||||
if title:
|
||||
@@ -26,8 +16,8 @@ def convert(html, title=None):
|
||||
|
||||
def meh(url):
|
||||
try:
|
||||
content, title = readability(url)
|
||||
return convert(content, title=title)
|
||||
d = mercury.parse(url)
|
||||
return convert(d.content, title=d.title)
|
||||
except KeyError:
|
||||
return None
|
||||
|
||||
|
||||
@@ -8,3 +8,4 @@ mistune==0.7.1
|
||||
requests==2.9.1
|
||||
Werkzeug==0.11.3
|
||||
wheel==0.24.0
|
||||
mercury-parser
|
||||
@@ -17,3 +17,7 @@ def fuck_gpl3():
|
||||
return '404 Not Found', 404
|
||||
else:
|
||||
return render_template('index.html')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
Reference in New Issue
Block a user