Update app.py
Browse files
app.py
CHANGED
|
@@ -1,114 +1,39 @@
|
|
| 1 |
-
from flask import Flask, request,
|
| 2 |
-
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
UPLOAD_FOLDER = 'static'
|
| 6 |
-
IMAGE_FILENAME = 'latest_image.jpg'
|
| 7 |
-
|
| 8 |
app = Flask(__name__)
|
| 9 |
-
app.
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
@app.route('/
|
| 28 |
-
def
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
</head>
|
| 41 |
-
<body>
|
| 42 |
-
<h1>Latest Image</h1>
|
| 43 |
-
<img id="cameraImage" src="/image" alt="Image" style="width:100%;">
|
| 44 |
-
<script>
|
| 45 |
-
setInterval(function(){
|
| 46 |
-
var image = document.getElementById("cameraImage");
|
| 47 |
-
image.src = "/image?" + new Date().getTime();
|
| 48 |
-
}, 10000); // обновление каждые 10 секунд
|
| 49 |
-
</script>
|
| 50 |
-
</body>
|
| 51 |
-
</html>
|
| 52 |
-
'''
|
| 53 |
-
return render_template_string(html)
|
| 54 |
-
|
| 55 |
-
@app.route('/chat')
|
| 56 |
-
def chat():
|
| 57 |
-
return flask.render_template('chat.html')
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
@app.route('/chat2')
|
| 65 |
-
def chat2():
|
| 66 |
-
return flask.render_template('chat2.html')
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
@socketio.on('message')
|
| 74 |
-
def handle_message(message):
|
| 75 |
-
print('Received message: ' + message)
|
| 76 |
-
send(message, broadcast=True)
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
@app.route('/upload_form')
|
| 82 |
-
def upload_form():
|
| 83 |
-
html = '''
|
| 84 |
-
<!DOCTYPE html>
|
| 85 |
-
<html lang="en">
|
| 86 |
-
<head>
|
| 87 |
-
<meta charset="UTF-8">
|
| 88 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 89 |
-
<title>Upload Image</title>
|
| 90 |
-
</head>
|
| 91 |
-
<body>
|
| 92 |
-
<h1>Upload Image</h1>
|
| 93 |
-
<form action="/upload" method="post" enctype="multipart/form-data">
|
| 94 |
-
<input type="file" name="photo" accept="image/*">
|
| 95 |
-
<button type="submit">Upload</button>
|
| 96 |
-
</form>
|
| 97 |
-
<div id="message"></div>
|
| 98 |
-
</body>
|
| 99 |
-
</html>
|
| 100 |
-
'''
|
| 101 |
-
return render_template_string(html)
|
| 102 |
-
|
| 103 |
-
@socketio.on('message')
|
| 104 |
-
def handle_message(msg):
|
| 105 |
-
print('Message: ' + msg)
|
| 106 |
-
send(msg, broadcast=True)
|
| 107 |
-
|
| 108 |
-
@socketio.on('json')
|
| 109 |
-
def handle_json(json):
|
| 110 |
-
print('JSON: ' + str(json))
|
| 111 |
-
send(json, json=True, broadcast=True)
|
| 112 |
|
| 113 |
if __name__ == '__main__':
|
| 114 |
-
|
|
|
|
| 1 |
+
from flask import Flask, request, redirect, session
|
| 2 |
+
import requests
|
| 3 |
import os
|
| 4 |
|
|
|
|
|
|
|
|
|
|
| 5 |
app = Flask(__name__)
|
| 6 |
+
app.secret_key = 'YOUR_SECRET_KEY' # Замените на ваш секретный ключ
|
| 7 |
+
|
| 8 |
+
def get_access_token(code):
|
| 9 |
+
client_id = 'YOUR_APP_ID'
|
| 10 |
+
client_secret = 'YOUR_APP_SECRET'
|
| 11 |
+
redirect_uri = 'https://example.com/login'
|
| 12 |
+
|
| 13 |
+
url = f'https://oauth.vk.com/access_token?client_id={client_id}&client_secret={client_secret}&redirect_uri={redirect_uri}&code={code}'
|
| 14 |
+
response = requests.get(url)
|
| 15 |
+
data = response.json()
|
| 16 |
+
|
| 17 |
+
if 'access_token' in data:
|
| 18 |
+
access_token = data['access_token']
|
| 19 |
+
user_id = data['user_id']
|
| 20 |
+
return access_token, user_id
|
| 21 |
+
else:
|
| 22 |
+
return None, None
|
| 23 |
+
|
| 24 |
+
@app.route('/login')
|
| 25 |
+
def login():
|
| 26 |
+
code = request.args.get('code')
|
| 27 |
+
if code:
|
| 28 |
+
access_token, user_id = get_access_token(code)
|
| 29 |
+
if access_token and user_id:
|
| 30 |
+
session['access_token'] = access_token
|
| 31 |
+
session['user_id'] = user_id
|
| 32 |
+
return redirect('/')
|
| 33 |
+
else:
|
| 34 |
+
return "Ошибка при получении access_token", 400
|
| 35 |
+
else:
|
| 36 |
+
return "Код авторизации не найден", 400
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
if __name__ == '__main__':
|
| 39 |
+
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|