updates
This commit is contained in:
parent
e3bacf6b1c
commit
09bd529cf4
@ -1,6 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
# Check if running with sudo
|
||||||
|
if [ "$(id -u)" != "0" ]; then
|
||||||
|
echo "This script must be run with sudo."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Install and enable SSH
|
# Install and enable SSH
|
||||||
install_ssh() {
|
install_ssh() {
|
||||||
|
|||||||
@ -11,15 +11,23 @@ app = Flask(__name__)
|
|||||||
|
|
||||||
# Function to fetch outdoor temperature from Météo-France
|
# Function to fetch outdoor temperature from Météo-France
|
||||||
def fetch_outdoor_temperature():
|
def fetch_outdoor_temperature():
|
||||||
# Format the date in the required format (YYYYMMDD)
|
# Get the current time
|
||||||
formatted_csv_date = datetime.now().strftime("%Y%m%d%H")
|
current_hour = datetime.now().hour
|
||||||
print(formatted_csv_date)
|
|
||||||
|
# Check if the current hour is one of the hours when data is published (every 3 hours from midnight)
|
||||||
|
if current_hour % 3 == 0:
|
||||||
|
# Format the date in the required format (YYYYMMDDHH)
|
||||||
|
formatted_csv_date = datetime.now().strftime("%Y%m%d%H")
|
||||||
|
else:
|
||||||
|
# If the current hour is not one of the publishing hours, fetch the data from the last published hour
|
||||||
|
formatted_csv_date = (datetime.now() - timedelta(hours=current_hour % 3)).strftime("%Y%m%d%H")
|
||||||
|
|
||||||
# Construct the URL
|
# Construct the URL
|
||||||
url = f"https://donneespubliques.meteofrance.fr/donnees_libres/Txt/Synop/synop.{formatted_csv_date}.csv"
|
url = f"https://donneespubliques.meteofrance.fr/donnees_libres/Txt/Synop/synop.{formatted_csv_date}.csv"
|
||||||
|
|
||||||
# Make the HTTP GET request
|
# Make the HTTP GET request
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
print(response)
|
|
||||||
# Check if request was successful
|
# Check if request was successful
|
||||||
try:
|
try:
|
||||||
# Decode the content as UTF-8 and split into lines
|
# Decode the content as UTF-8 and split into lines
|
||||||
@ -29,17 +37,14 @@ def fetch_outdoor_temperature():
|
|||||||
|
|
||||||
# Extract outdoor temperature from the CSV data
|
# Extract outdoor temperature from the CSV data
|
||||||
for row in reader:
|
for row in reader:
|
||||||
if row['numer_sta'] == '07149': #
|
if row['numer_sta'] == '07149':
|
||||||
outdoor_temp = float(row['t'])
|
outdoor_temp = float(row['t'])
|
||||||
return round(outdoor_temp - 273.15, 1) #convert °K to °c
|
return round(outdoor_temp - 273.15, 1) # Convert °K to °C
|
||||||
except:
|
except Exception as e:
|
||||||
print("Failed to fetch data from Météo-France.")
|
print(f"[{datetime.now()}] MeteoFrance - Failed to fetch data from Météo-France. Error: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Appel de la fonction pour obtenir la température
|
|
||||||
#temperature = fetch_outdoor_temperature()
|
|
||||||
#print(temperature)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -51,7 +56,9 @@ def dashboard():
|
|||||||
# Convert figure to JSON for rendering in template
|
# Convert figure to JSON for rendering in template
|
||||||
temp_graph_json = history_graph_temp()
|
temp_graph_json = history_graph_temp()
|
||||||
HR_graph_json = history_graph_HR()
|
HR_graph_json = history_graph_HR()
|
||||||
return render_template('index.html', data=data, temperature=None, temp_graph_json=temp_graph_json, HR_graph_json=HR_graph_json)
|
outdoor_temp = fetch_outdoor_temperature()
|
||||||
|
|
||||||
|
return render_template('index.html', data=data, temperature=outdoor_temp, temp_graph_json=temp_graph_json, HR_graph_json=HR_graph_json)
|
||||||
|
|
||||||
#Route to display the sensor history
|
#Route to display the sensor history
|
||||||
@app.route('/history')
|
@app.route('/history')
|
||||||
@ -116,5 +123,5 @@ def run_flask():
|
|||||||
def RunInThread_WebServer():
|
def RunInThread_WebServer():
|
||||||
threading.Thread(target=run_flask, daemon=True).start()
|
threading.Thread(target=run_flask, daemon=True).start()
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True)
|
print(fetch_outdoor_temperature)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user