Wetter-API Integration hinzugefügt
This commit is contained in:
12
CHANGELOG.md
12
CHANGELOG.md
@@ -5,6 +5,18 @@ Alle wichtigen Änderungen an diesem Projekt werden in dieser Datei dokumentiert
|
|||||||
Das Format basiert auf [Keep a Changelog](https://keepachangelog.com/de/1.0.0/),
|
Das Format basiert auf [Keep a Changelog](https://keepachangelog.com/de/1.0.0/),
|
||||||
und dieses Projekt adhäriert zu [Semantic Versioning](https://semver.org/lang/de/).
|
und dieses Projekt adhäriert zu [Semantic Versioning](https://semver.org/lang/de/).
|
||||||
|
|
||||||
|
## [1.0.2] - 2024-03-19
|
||||||
|
|
||||||
|
### Hinzugefügt
|
||||||
|
- Wetterinformationen für jeden Suchtreffer
|
||||||
|
- Integration der OpenWeather API
|
||||||
|
- Wetter-Icons und Temperaturanzeige
|
||||||
|
- Umgebungsvariablen für API-Keys
|
||||||
|
|
||||||
|
### Geändert
|
||||||
|
- Anpassung der API-Antwortstruktur
|
||||||
|
- Verbesserte Fehlerbehandlung für API-Anfragen
|
||||||
|
|
||||||
## [1.0.1] - 2024-03-19
|
## [1.0.1] - 2024-03-19
|
||||||
|
|
||||||
### Hinzugefügt
|
### Hinzugefügt
|
||||||
|
44
app.py
44
app.py
@@ -4,6 +4,8 @@ import os
|
|||||||
import logging
|
import logging
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
import requests
|
||||||
|
|
||||||
app = Flask(__name__, static_folder='static')
|
app = Flask(__name__, static_folder='static')
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
@@ -15,6 +17,9 @@ VERSION = "1.0.1"
|
|||||||
# Pfad zur CSV-Datei
|
# Pfad zur CSV-Datei
|
||||||
CSV_FILE = "data/customers.csv"
|
CSV_FILE = "data/customers.csv"
|
||||||
|
|
||||||
|
# Lade Umgebungsvariablen
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
def clean_dataframe(df):
|
def clean_dataframe(df):
|
||||||
"""Konvertiert NaN-Werte in None für JSON-Kompatibilität"""
|
"""Konvertiert NaN-Werte in None für JSON-Kompatibilität"""
|
||||||
return df.replace({np.nan: None})
|
return df.replace({np.nan: None})
|
||||||
@@ -35,6 +40,31 @@ def load_data():
|
|||||||
logger.error(f"Fehler beim Laden der CSV-Datei: {str(e)}")
|
logger.error(f"Fehler beim Laden der CSV-Datei: {str(e)}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_weather(city):
|
||||||
|
"""Holt Wetterinformationen für eine Stadt von der OpenWeather API"""
|
||||||
|
api_key = os.getenv('OPENWEATHER_API_KEY')
|
||||||
|
base_url = "http://api.openweathermap.org/data/2.5/weather"
|
||||||
|
|
||||||
|
try:
|
||||||
|
params = {
|
||||||
|
'q': city,
|
||||||
|
'appid': api_key,
|
||||||
|
'units': 'metric', # Temperatur in Celsius
|
||||||
|
'lang': 'de'
|
||||||
|
}
|
||||||
|
response = requests.get(base_url, params=params)
|
||||||
|
data = response.json()
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
return {
|
||||||
|
'temperature': round(data['main']['temp']),
|
||||||
|
'icon': data['weather'][0]['icon'],
|
||||||
|
'description': data['weather'][0]['description']
|
||||||
|
}
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Fehler beim Abrufen der Wetterdaten: {e}")
|
||||||
|
return None
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
return render_template('index.html')
|
return render_template('index.html')
|
||||||
@@ -95,7 +125,19 @@ def search():
|
|||||||
|
|
||||||
results = df[mask].to_dict('records')
|
results = df[mask].to_dict('records')
|
||||||
logger.info(f"{len(results)} Ergebnisse gefunden")
|
logger.info(f"{len(results)} Ergebnisse gefunden")
|
||||||
return jsonify(results)
|
|
||||||
|
# Füge Wetterinformationen für jeden Treffer hinzu
|
||||||
|
for result in results:
|
||||||
|
weather = get_weather(result['Ort'])
|
||||||
|
if weather:
|
||||||
|
result['weather'] = weather
|
||||||
|
else:
|
||||||
|
result['weather'] = None
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'results': results,
|
||||||
|
'total': len(results)
|
||||||
|
})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Fehler bei der Suche: {str(e)}")
|
logger.error(f"Fehler bei der Suche: {str(e)}")
|
||||||
return jsonify({"error": str(e)}), 500
|
return jsonify({"error": str(e)}), 500
|
||||||
|
@@ -2,3 +2,4 @@ flask==3.0.2
|
|||||||
pandas==2.2.1
|
pandas==2.2.1
|
||||||
numpy==1.26.4
|
numpy==1.26.4
|
||||||
python-dotenv==1.0.1
|
python-dotenv==1.0.1
|
||||||
|
requests==2.31.0
|
@@ -139,6 +139,18 @@
|
|||||||
margin-left: 4px;
|
margin-left: 4px;
|
||||||
font-size: 1.2em;
|
font-size: 1.2em;
|
||||||
}
|
}
|
||||||
|
.weather-info {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
margin-left: 10px;
|
||||||
|
font-size: 0.9em;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
.weather-info img {
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
margin-right: 4px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
Reference in New Issue
Block a user