Update flsk.py
parent
ac871f29a0
commit
c8fe330491
243
flsk.py
243
flsk.py
|
@ -1,118 +1,125 @@
|
||||||
import os
|
from flask import Flask, render_template, request, send_from_directory, redirect, url_for
|
||||||
from flask import Flask, render_template, request, send_from_directory, redirect, url_for
|
|
||||||
import uuid
|
|
||||||
import csv
|
app = Flask(__name__)
|
||||||
|
|
||||||
app = Flask(__name__)
|
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
@app.route("/")
|
def home():
|
||||||
def home():
|
return render_template("index.html")
|
||||||
return render_template("index.html")
|
|
||||||
|
@app.route("/dwnld")
|
||||||
@app.route("/dwnld")
|
def dwnld_page():
|
||||||
def dwnld_page():
|
return render_template("download.html")
|
||||||
return render_template("download.html")
|
|
||||||
|
@app.route("/download")
|
||||||
@app.route("/download")
|
def download():
|
||||||
def download():
|
return send_from_directory('game', 'Game-master.zip')
|
||||||
return send_from_directory('game', 'Game-master.zip')
|
|
||||||
|
|
||||||
|
@app.route("/about")
|
||||||
@app.route("/about")
|
def about():
|
||||||
def about():
|
return render_template("about.html")
|
||||||
return render_template("about.html")
|
|
||||||
|
@app.route("/contact", methods=["GET", "POST"])
|
||||||
@app.route("/contact", methods=["GET", "POST"])
|
def contact():
|
||||||
def contact():
|
if request.method == "POST":
|
||||||
if request.method == "POST":
|
# Get form data
|
||||||
# Get form data
|
name = request.form.get("name")
|
||||||
name = request.form.get("name")
|
email = request.form.get("email")
|
||||||
email = request.form.get("email")
|
message = request.form.get("message")
|
||||||
message = request.form.get("message")
|
|
||||||
|
# Here you can process the message, send emails, save to database, etc.
|
||||||
# Here you can process the message, send emails, save to database, etc.
|
# let's just print the data to the console
|
||||||
# let's just print the data to the console
|
print(f"Name: {name}, Email: {email}, Message: {message}")
|
||||||
print(f"Name: {name}, Email: {email}, Message: {message}")
|
|
||||||
|
return render_template("thank_you.html", name=name)
|
||||||
return render_template("thank_you.html", name=name)
|
|
||||||
|
return render_template("contact.html")
|
||||||
return render_template("contact.html")
|
|
||||||
|
|
||||||
|
@app.route("/login", methods=["GET", "POST"])
|
||||||
@app.route("/login", methods=["GET", "POST"])
|
def login():
|
||||||
def login():
|
if request.method == "POST":
|
||||||
if request.method == "POST":
|
username = request.form.get("username")
|
||||||
# Get form data
|
password = request.form.get("password")
|
||||||
username = request.form.get("username")
|
|
||||||
password = request.form.get("password")
|
# Проверка, что поля не пустые
|
||||||
|
if username and password:
|
||||||
# Here you would typically validate the user's credentials
|
return redirect(url_for('index', name=username))
|
||||||
# For this example, let's assume the user is valid
|
else:
|
||||||
|
# Если поля пустые, оставляем пользователя на странице "login"
|
||||||
# Redirect the user to their account page
|
return render_template("login.html")
|
||||||
return redirect(url_for('account', name=username))
|
|
||||||
|
return render_template("login.html")
|
||||||
return render_template("login.html")
|
|
||||||
|
@app.route("/index")
|
||||||
@app.route("/account/<name>")
|
def index():
|
||||||
def account(name):
|
# Здесь можно добавить логику для страницы "index"
|
||||||
# Render the account page with the user's name
|
return render_template("index.html")
|
||||||
return render_template("account.html", name=name)
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
app.run(debug=True)
|
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
@app.route('/')
|
def button_page():
|
||||||
def button_page():
|
return render_template('login.html')
|
||||||
return render_template('account.html')
|
|
||||||
|
@app.route('/index', methods=['GET', 'POST'])
|
||||||
@app.route('/index', methods=['GET', 'POST'])
|
def display_text():
|
||||||
def display_text():
|
if request.method == 'POST':
|
||||||
if request.method == 'POST':
|
return render_template('index.html', show_text=True)
|
||||||
return render_template('index.html', show_text=True)
|
else:
|
||||||
else:
|
return render_template('index.html', show_text=False)
|
||||||
return render_template('index.html', show_text=False)
|
|
||||||
|
if __name__ == '__main__':
|
||||||
if __name__ == '__main__':
|
app.run(debug=True)
|
||||||
app.run(debug=True)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_latvia_time():
|
||||||
|
try:
|
||||||
|
url = "http://worldtimeapi.org/api/timezone/Europe/Riga"
|
||||||
|
response = requests.get(url)
|
||||||
#CSV_FILE_PATH = 'data.csv'
|
data = response.json()
|
||||||
|
latvia_time = data["datetime"]
|
||||||
#@app.route('/')
|
return latvia_time
|
||||||
#def login1():
|
except Exception as e:
|
||||||
# return render_template('login.html')
|
return f"Ошибка при получении времени: {e}"
|
||||||
|
|
||||||
#@app.route('/login', methods=['POST'])
|
if __name__ == "__main__":
|
||||||
#def submit():
|
latvia_time = get_latvia_time()
|
||||||
#username = request.form['username']
|
print(f"Текущее время в Латвии: {latvia_time}")
|
||||||
#password = request.form['password']
|
|
||||||
|
|
||||||
# Проверка существования файла, если нет - создаем с заголовками
|
|
||||||
#if not os.path.exists(CSV_FILE_PATH):
|
|
||||||
#with open(CSV_FILE_PATH, mode='w', newline='') as file:
|
|
||||||
# writer = csv.writer(file)
|
|
||||||
# writer.writerow(['username', 'password'])
|
def get_weather_in_riga():
|
||||||
|
api_key = "ВАШ_КЛЮЧ"
|
||||||
# Запись данных в CSV файл
|
city_id = 456173 # ID города Рига
|
||||||
#with open(CSV_FILE_PATH, mode='a', newline='') as file:
|
url = f"https://api.openweathermap.org/data/2.5/weather?id={city_id}&appid={api_key}&units=metric"
|
||||||
# writer = csv.writer(file)
|
|
||||||
# writer.writerow([username, password])
|
response = requests.get(url)
|
||||||
|
if response.status_code == 200:
|
||||||
# return redirect(url_for('login1'))
|
data = response.json()
|
||||||
|
weather_description = data["weather"][0]["description"]
|
||||||
#if __name__ == '__main__':
|
temperature = data["main"]["temp"]
|
||||||
# app.run(debug=True)
|
humidity = data["main"]["humidity"]
|
||||||
|
return f"Сейчас в Риге {weather_description}. Температура: {temperature}°C, Влажность: {humidity}%"
|
||||||
|
else:
|
||||||
|
return "Не удалось получить данные о погоде."
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
def weather_route():
|
||||||
|
return get_weather_in_riga()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run()
|
Loading…
Reference in New Issue