Update flsk.py
parent
ac871f29a0
commit
c8fe330491
93
flsk.py
93
flsk.py
|
@ -1,11 +1,10 @@
|
|||
import os
|
||||
from flask import Flask, render_template, request, send_from_directory, redirect, url_for
|
||||
import uuid
|
||||
import csv
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def home():
|
||||
return render_template("index.html")
|
||||
|
@ -43,33 +42,33 @@ def contact():
|
|||
@app.route("/login", methods=["GET", "POST"])
|
||||
def login():
|
||||
if request.method == "POST":
|
||||
# Get form data
|
||||
username = request.form.get("username")
|
||||
password = request.form.get("password")
|
||||
|
||||
# Here you would typically validate the user's credentials
|
||||
# For this example, let's assume the user is valid
|
||||
|
||||
# Redirect the user to their account page
|
||||
return redirect(url_for('account', name=username))
|
||||
# Проверка, что поля не пустые
|
||||
if username and password:
|
||||
return redirect(url_for('index', name=username))
|
||||
else:
|
||||
# Если поля пустые, оставляем пользователя на странице "login"
|
||||
return render_template("login.html")
|
||||
|
||||
return render_template("login.html")
|
||||
|
||||
@app.route("/account/<name>")
|
||||
def account(name):
|
||||
# Render the account page with the user's name
|
||||
return render_template("account.html", name=name)
|
||||
|
||||
|
||||
@app.route("/index")
|
||||
def index():
|
||||
# Здесь можно добавить логику для страницы "index"
|
||||
return render_template("index.html")
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True)
|
||||
app.run()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def button_page():
|
||||
return render_template('account.html')
|
||||
return render_template('login.html')
|
||||
|
||||
@app.route('/index', methods=['GET', 'POST'])
|
||||
def display_text():
|
||||
|
@ -84,35 +83,43 @@ if __name__ == '__main__':
|
|||
|
||||
|
||||
|
||||
def get_latvia_time():
|
||||
try:
|
||||
url = "http://worldtimeapi.org/api/timezone/Europe/Riga"
|
||||
response = requests.get(url)
|
||||
data = response.json()
|
||||
latvia_time = data["datetime"]
|
||||
return latvia_time
|
||||
except Exception as e:
|
||||
return f"Ошибка при получении времени: {e}"
|
||||
|
||||
if __name__ == "__main__":
|
||||
latvia_time = get_latvia_time()
|
||||
print(f"Текущее время в Латвии: {latvia_time}")
|
||||
|
||||
|
||||
|
||||
#CSV_FILE_PATH = 'data.csv'
|
||||
|
||||
#@app.route('/')
|
||||
#def login1():
|
||||
# return render_template('login.html')
|
||||
|
||||
#@app.route('/login', methods=['POST'])
|
||||
#def submit():
|
||||
#username = request.form['username']
|
||||
#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'])
|
||||
|
||||
# Запись данных в CSV файл
|
||||
#with open(CSV_FILE_PATH, mode='a', newline='') as file:
|
||||
# writer = csv.writer(file)
|
||||
# writer.writerow([username, password])
|
||||
|
||||
# return redirect(url_for('login1'))
|
||||
|
||||
#if __name__ == '__main__':
|
||||
# app.run(debug=True)
|
||||
|
||||
|
||||
|
||||
def get_weather_in_riga():
|
||||
api_key = "ВАШ_КЛЮЧ"
|
||||
city_id = 456173 # ID города Рига
|
||||
url = f"https://api.openweathermap.org/data/2.5/weather?id={city_id}&appid={api_key}&units=metric"
|
||||
|
||||
response = requests.get(url)
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
weather_description = data["weather"][0]["description"]
|
||||
temperature = data["main"]["temp"]
|
||||
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