diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..d5b14bb --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: gunicorn service:app \ No newline at end of file diff --git a/converter.py b/converter.py new file mode 100644 index 0000000..f06bf88 --- /dev/null +++ b/converter.py @@ -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/') \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..67c9da7 --- /dev/null +++ b/requirements.txt @@ -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 diff --git a/service.py b/service.py new file mode 100644 index 0000000..54b4083 --- /dev/null +++ b/service.py @@ -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) \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..46c051b --- /dev/null +++ b/templates/index.html @@ -0,0 +1,19 @@ + + + + url2markdown + + +

url2markdown

+

This is a very simple web service that will take a given URL, and return +a Markdown representation of that page.

+ +
+ URL: + +
+ +

Enjoy!

+ + + \ No newline at end of file