forked from dragnet-org/dragnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwsgi.py
More file actions
45 lines (33 loc) · 1.24 KB
/
wsgi.py
File metadata and controls
45 lines (33 loc) · 1.24 KB
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
import os
from flask import Flask, jsonify, request
from flask_httpauth import HTTPBasicAuth
from werkzeug.security import generate_password_hash, check_password_hash
from dragnet import extract_content, extract_content_and_comments
USERNAME = os.getenv("USR", "admin")
PASSWORD = generate_password_hash(os.getenv("PASSWD", "secret"))
app = Flask(__name__)
auth = HTTPBasicAuth()
@auth.verify_password
def verify_password(username, password):
if username == USERNAME and check_password_hash(PASSWORD, password):
return username
@app.post("/extract_content")
@auth.login_required
def content():
data_src = request.get_json() if request.is_json else request.form
html = data_src.get('html', '')
content_ = extract_content(html)
if request.is_json:
return jsonify({'content': content_})
else:
return content_
@app.post("/extract_content_and_comments")
@auth.login_required
def content_and_comments():
data_src = request.get_json() if request.is_json else request.form
html = data_src.get('html', '')
content_and_comments_ = extract_content_and_comments(html)
if request.is_json:
return jsonify({'content_and_comments': content_and_comments_})
else:
return content_and_comments_