File size: 1,035 Bytes
afd9f5c
 
 
 
 
 
 
 
 
 
 
 
636d073
afd9f5c
 
 
 
 
 
 
 
 
 
 
 
 
 
636d073
afd9f5c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# -*- coding: utf-8 -*-
from flask import (
    Flask,
    request,
    render_template
)
app = Flask(__name__)

@app.route("/", methods=["GET", "POST"])
def home():

    #################################################
    # save logs
    #################################################

    with open("access.log", "a", encoding="utf-8") as f:

        log = (
            f'{request.remote_addr} - '
            f'"{request.method} {request.full_path} HTTP/1.1"\n'
        )

        f.write(log)

        f.flush()

    #################################################
    # q param
    #################################################

    q = request.args.get("q", "")

    #################################################
    # html render
    #################################################

    return render_template(
        "index.html",
        q=q
    )

if __name__ == "__main__":

    app.run(
        host="0.0.0.0",
        port=8080,
        debug=False
    )