Skip to content

Instantly share code, notes, and snippets.

@manuel-delverme
Created May 27, 2019 15:36
Show Gist options
  • Save manuel-delverme/af5d207762bc147b92fb25b0f6e68139 to your computer and use it in GitHub Desktop.
Save manuel-delverme/af5d207762bc147b92fb25b0f6e68139 to your computer and use it in GitHub Desktop.
import flask
import newspaper
import wtforms
DEBUG = True
app = flask.Flask(__name__)
app.config.from_object(__name__)
app.config['SECRET_KEY'] = 'feeddeadbeeffeeddeadbeeffeedde'
accatiemmeelle = """
<title>amifamous?</title>
<form action="" method="POST">{{ form.csrf }}
<div class="input text">{{ form.url.label }} {{ form.url }}</div>
<div class="input submit"><input type="submit" value="Submit"></div>
</form>
"""
def wtf(url="http://www.ansa.it/sito/notizie/tecnologia/hitech/2015/04/06/robot-per-amazon-due-italiani-in-gara_e1199b8c-95e0-4700-8283-8a6b0a882a6c.html"):
article = newspaper.Article(url)
article.download()
article.parse()
article.nlp()
html = f"""
<table border=1>
<tr>
<td>testo</td>
<td>{article.text}</td>
</tr>
<tr>
<td>son mario</td>
<td>article.summary</td>
</tr>
<tr>
<td>gg</td>
<td>easy</td>
</tr>
</table>
"""
return html
class ReusableForm(wtforms.Form):
url = wtforms.TextField('url')
@app.route("/", methods=['GET', 'POST'])
def hello():
form = ReusableForm(flask.request.form)
if flask.request.method == 'POST':
url = flask.request.form['url']
html = wtf(url)
return flask.render_template_string(html, form=form)
else:
return flask.render_template_string(accatiemmeelle, form=form)
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment