-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
48 lines (38 loc) · 1.54 KB
/
app.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
# Package import
from flask import Flask, render_template, send_file, make_response, url_for, Response, redirect, request
from main import main
from dotenv import load_dotenv
import os
import logging
logger = logging.getLogger(__name__)
# initialise app
app = Flask(__name__)
logger.warn("Try to load env...")
load_dotenv()
try:
emails = os.environ['EMAIL_RECIPIENTS']
except KeyError:
emails = ""
# decorator for homepage
@app.route('/')
def index():
return render_template('index.html', mails=emails)
# These functions will run when POST method is used.
@app.route('/', methods=["POST"])
def auto_scan():
# making sure its not empty
multiselect = request.form.getlist('email_recipients')
if request.form['subject'] != '':
logger.warn("Starts processing...")
logger.warn("Param emails: %s",';'.join(multiselect))
logger.warn("Param subject: %s",request.form['subject'])
logger.warn("Param mode: %s",request.form['scan_mode'])
logger.warn("Param format: %s",request.form['paper_format'])
logger.warn("Param batch: %d",int(request.form['batch_total']))
_is_local_scan = request.form.get('is_local_scan', False)
logger.warn("Param is_local: %s", _is_local_scan)
main(';'.join(multiselect), request.form['subject'], request.form['scan_mode'],
request.form['paper_format'], int(request.form['batch_total']), as_web_interface=True, is_local_scan=_is_local_scan)
return render_template('index.html', mails=emails)
if __name__ == '__main__':
app.run(debug=True)