Spaces:
Sleeping
Sleeping
File size: 4,641 Bytes
739886f 61e87e6 edee679 16c32c6 14af27b 96393fc 30ba6c5 d140f2b 58cae0c 6e5ec17 1d05f9c 1258d21 14af27b 1258d21 1d05f9c 40c4f6f 1258d21 1d05f9c d140f2b e7ebe2e 0d1f373 5736a57 0d1f373 d140f2b 9228b11 d140f2b 40c4f6f b9df598 7ff616c 6d5cbcf 40c4f6f 7ff616c 14af27b 40c4f6f 14af27b 2138b6a 6d5cbcf f381854 5fa984e 9ede144 b9757a6 5fa984e 77bdeeb 5fa984e 1258d21 e976dab 7f021d7 0753094 080f0bc 96393fc 080f0bc 739886f 080f0bc f18f04b 96393fc |
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
from flask import Flask, request, render_template_string, send_from_directory, jsonify, render_template
from flask import render_template
import sqlite3
import os
import uuid
import shutil
import decimal
import hashlib
from urllib import parse
from urllib.parse import urlparse
from datetime import datetime
import pytz
app = Flask(__name__, template_folder="./")
app.config['DEBUG'] = True
UPLOAD_FOLDER = 'static'
HTML_FOLDER = 'html'
# Создание директорий, если они не существуют
if not os.path.exists(UPLOAD_FOLDER):
os.makedirs(UPLOAD_FOLDER)
if not os.path.exists(HTML_FOLDER):
os.makedirs(HTML_FOLDER)
DATABASES = ['data_gc.db']
def init_db(db_name):
conn = sqlite3.connect(db_name)
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS contacts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
phone TEXT NOT NULL,
email TEXT NOT NULL,
vk_id TEXT,
chat_id TEXT,
orders TEXT,
looks TEXT
)
''')
conn.commit()
conn.close()
for db in DATABASES:
init_db(db)
@app.route('/get_current_time', methods=['GET'])
def get_current_time():
utc_now = datetime.utcnow()
msk_tz = pytz.timezone('Europe/Moscow')
msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
current_time = msk_now.strftime('%Y-%m-%d %H:%M:%S')
return jsonify({'current_time': current_time})
@app.route('/forms', methods=['GET'])
def up_forms():
return render_template('forms.html')
@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
# Генерация уникального имени файла
unique_filename = str(uuid.uuid4()) + os.path.splitext(file.filename)[1]
save_path = os.path.join(UPLOAD_FOLDER, unique_filename)
file.save(save_path)
# Возвращаем полный URL загруженного файла с протоколом https
full_url = request.url_root.replace('http://', 'https://') + 'uploads/' + unique_filename
return f"File uploaded successfully and saved to {full_url}", 200
@app.route('/uploads/<filename>', methods=['GET'])
def uploaded_file(filename):
return send_from_directory(UPLOAD_FOLDER, filename)
@app.route('/up_fa', methods=['GET'])
def up_fa():
return render_template('up_fa.html')
@app.route('/up_page', methods=['POST'])
def upload_page():
if 'file' not in request.files:
return "No file part", 400
file = request.files['file']
if file.filename == '':
return "No selected file", 400
filename = request.form.get('filename')
if not filename:
return "Filename is required", 400
save_path = os.path.join(HTML_FOLDER, filename + '.html')
file.save(save_path)
# Возвращаем полный URL загруженного файла с протоколом https
full_url = request.url_root.replace('http://', 'https://') + filename
return f"Page uploaded successfully and saved to {full_url}", 200
@app.route('/<path:filename>', methods=['GET'])
def serve_html(filename):
if not filename.endswith('.html'):
filename += '.html'
return send_from_directory(HTML_FOLDER, filename)
@app.route('/up_page', methods=['GET'])
def up_page():
return render_template('up_page.html')
@app.route('/monitor', methods=['GET'])
def monitor():
# Получаем информацию о загруженных файлах
files = os.listdir(UPLOAD_FOLDER)
html_files = os.listdir(HTML_FOLDER)
# Получаем информацию о дисковом пространстве
total, used, free = shutil.disk_usage("/")
# Преобразуем байты в гигабайты для удобства чтения
total_gb = total // (2**30)
used_gb = used // (2**30)
free_gb = free // (2**30)
return render_template('monitor.html',
uploaded_files=files,
uploaded_html_files=html_files,
disk_space={
'total': f"{total_gb} GB",
'used': f"{used_gb} GB",
'free': f"{free_gb} GB"
})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860))) |