mirror of
https://github.com/not-kennethreitz/markdownplease.com.git
synced 2026-06-05 07:06:12 +00:00
w00t
This commit is contained in:
@@ -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/')
|
||||
@@ -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
@@ -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)
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user