This commit is contained in:
Kenneth Reitz
2013-09-26 20:53:01 -04:00
parent 49b1c1ee28
commit e819c09273
5 changed files with 86 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
web: gunicorn service:app
+31
View File
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
import os
import requests
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']
def convert(html):
return html2text(html)
def meh(url):
try:
return convert(readability(url))
except KeyError:
return None
if __name__ == '__main__':
print meh('http://kennethreitz.org/')
+10
View File
@@ -0,0 +1,10 @@
Flask==0.10.1
Jinja2==2.7.1
MarkupSafe==0.18
Werkzeug==0.9.4
distribute==0.6.34
gunicorn==18.0
html2text==3.200.3
itsdangerous==0.23
requests==2.0.0
wsgiref==0.1.2
+25
View File
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
from flask import Flask, request, redirect, url_for, render_template
from converter import meh
app = Flask(__name__)
app.debug = True
@app.route('/')
def fuck_gpl2():
url = request.args.get('url')
if url:
content = meh(url)
if content:
return content, 200, {'Content-Type': 'text/x-markdown; charset=UTF-8'}
else:
return '404 Not Found', 404
else:
return render_template('index.html')
@app.route('/', methods=['POST', 'PUT'])
def lazy_301():
url = request.form.get('url')
redirect(url_for('fuck_gpl2'), url=url)
+19
View File
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>url2markdown</title>
</head>
<body>
<h1>url2markdown</h1>
<p>This is a very simple web service that will take a given URL, and return
a Markdown representation of that page.</p>
<form action="/" method="get">
URL: <input type="text" name="url">
<button type='submit'>Submit</button>
</form>
<p>Enjoy!</p>
</body>
</html>