-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
37 lines (32 loc) · 924 Bytes
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import datetime
from flask import Flask
from flask import request
from flask import json
from newspaper import Article
app = Flask(__name__)
@app.route("/")
def home():
url = request.args.get('url')
article = Article(url)
article.download()
article.parse()
article.nlp()
data = {}
data['title'] = article.title
data['summary'] = article.summary
data['text'] = article.text
data['image'] = article.top_image
data['keywords'] = article.keywords
data['authors'] = article.authors
if isinstance(article.publish_date, datetime.date):
data['published'] = article.publish_date.strftime("%Y-%m-%d %H:%M:00")
else:
data['published'] = ""
response = app.response_class(
response=json.dumps(data),
status=200,
mimetype='application/json'
)
return response
if __name__ == "__main__":
app.run(host='0.0.0.0', port=38765)