File size: 1,762 Bytes
4cd23ec
e9edc80
4cd23ec
 
 
ec447d0
e9edc80
3ab3bfe
ec447d0
 
 
 
30cb684
7a42f0c
70f7ff7
ec447d0
 
 
 
 
 
4cd23ec
 
 
 
 
 
 
7851dcb
4cd23ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7851dcb
 
 
 
ec447d0
 
f18f04b
0cf3e5e
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
from flask import Flask, request, send_from_directory, render_template_string
import os




app = flask.Flask(__name__, template_folder="./")
app.config['DEBUG'] = True




@app.route("/")
def index():
    return flask.render_template('index.html')






app = Flask(__name__)
UPLOAD_FOLDER = 'static'
IMAGE_FILENAME = 'latest_image.jpg'

# Создание директории, если она не существует
if not os.path.exists(UPLOAD_FOLDER):
    os.makedirs(UPLOAD_FOLDER)

@app.route('/upload', methods=['POST'])
def upload_file():
    if 'file' not in request.files:
        return "No file part", 400
    file = request.files['file']
    if file.filename == '':
        return "No selected file", 400
    file.save(os.path.join(UPLOAD_FOLDER, IMAGE_FILENAME))
    return "File uploaded successfully", 200

@app.route('/image')
def get_image():
    return send_from_directory(UPLOAD_FOLDER, IMAGE_FILENAME)

@app.route('/')
def index():
    html = '''
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Camera Image</title>
    </head>
    <body>
        <h1>Latest Camera Image</h1>
        <img id="cameraImage" src="/image" alt="Camera Image" style="width:100%;">
        <script>
            setInterval(function(){
                var image = document.getElementById("cameraImage");
                image.src = "/image?" + new Date().getTime();
            }, 10000); // обновление каждые 10 секунд
        </script>
    </body>
    </html>
    '''
    return render_template_string(html)






if __name__ == '__main__':
    app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))