-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapi.py
77 lines (65 loc) · 1.85 KB
/
api.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from flask import Flask, request, render_template,jsonify
from models.newspaper.newspaper import Article
# from models.newspaper.newspaper import fulltext
import json
app = Flask(__name__)
app.debug = True
@app.route('/')
def load_home():
return render_template("home.html")
"""
For Php API
"""
@app.route('/analyse', methods=['POST','GET'])
def analyse():
data = request.data.decode("utf-8")
data = json.loads(data)
if not verify_token(data["token"]):
return ('token did not matched')
# data = request.form.to_dict()
url = data["url"]
print (url)
article = Article(url, language='hi')
article.download()
article.parse()
article.nlp()
data_to_send = {
"DATE": article.publish_date,
"TITLE": article.title,
"keywords": article.keywords,
"summary" :article.summary,
"TEXT" : article.text,
"img_url": article.top_image,
"video" : article.movies,
"url":url,
}
result = {str(key): value for key, value in data_to_send.items()}
return jsonify(result=data_to_send)
"""
For Web API
"""
@app.route('/analyse_web', methods=['POST','GET'])
def analyse_web():
data = request.form.to_dict()
# data = request.form.to_dict()
url = data["url"]
print (url)
article = Article(url, language='hi')
article.download()
article.parse()
article.nlp()
data_to_send = {
"DATE": article.publish_date,
"TITLE": article.title,
"keywords": article.keywords,
"summary" :article.summary,
"TEXT" : article.text,
"img_url": article.top_image,
"video" : article.movies,
"url":url,
}
print (data_to_send)
result = {str(key): value for key, value in data_to_send.items()}
return jsonify(result=data_to_send)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=11706)