user mercury parser

This commit is contained in:
2017-01-08 16:00:59 -05:00
parent 97267d532d
commit 81ad15d5a2
3 changed files with 9 additions and 14 deletions
+4 -14
View File
@@ -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
+1
View File
@@ -8,3 +8,4 @@ mistune==0.7.1
requests==2.9.1
Werkzeug==0.11.3
wheel==0.24.0
mercury-parser
+4
View File
@@ -17,3 +17,7 @@ def fuck_gpl3():
return '404 Not Found', 404
else:
return render_template('index.html')
if __name__ == '__main__':
app.run()