-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
76 lines (60 loc) · 2.71 KB
/
main.py
File metadata and controls
76 lines (60 loc) · 2.71 KB
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
# main.py
import os
from dotenv import load_dotenv
from datetime import datetime, timedelta
import json
from config import CITIES
from services.weather import fetch_weather_data
from services.llm import get_weather_analysis
load_dotenv()
def process_data_for_llm(weather_data_list):
"""
Transforms the raw weather data list into a clean, formatted string for the LLM.
"""
print("\nProcessing data for LLM...")
final_report = f"Weather forecast overview for {datetime.now().strftime('%A, %B %d, %Y')}:\n\n"
for data in weather_data_list:
city_name = data.get('city_name', 'Unknown City')
final_report += f"--- {city_name} ---\n"
# We only want the forecast for the next 5 days
for i, daily_forecast in enumerate(data['daily'][:5]):
# Get the date for the forecast day
forecast_date = datetime.now() + timedelta(days=i)
day_of_week = forecast_date.strftime('%A')
# Safely get values from the dictionary
max_temp = daily_forecast.get('temp', {}).get('max', 'N/A')
min_temp = daily_forecast.get('temp', {}).get('min', 'N/A')
weather_desc = daily_forecast.get('weather', [{}])[0].get('description', 'N/A')
precip_prob = int(daily_forecast.get('pop', 0) * 100)
final_report += f"{day_of_week}: {weather_desc}, High: {max_temp}°C, Low: {min_temp}°C, Precipitation: {precip_prob}%\n"
final_report += "\n"
return final_report
def main():
"""
The main function to orchestrate the Kairos workflow.
"""
print("Running Kairos orchestrator...")
if not os.getenv('OPENWEATHER_API_KEY') or not os.getenv('OPENROUTER_API_KEY'):
print("Error: Required API keys not found in .env file.")
return
all_weather_data = []
for city in CITIES:
print(f"Fetching weather for {city['name']}...")
weather_report = fetch_weather_data(os.getenv('OPENWEATHER_API_KEY'), city['lat'], city['lon'])
if weather_report:
weather_report['city_name'] = city['name']
all_weather_data.append(weather_report)
if not all_weather_data:
print("Could not fetch any weather data. Exiting.")
return
print(f"\nSuccessfully fetched weather data for {len(all_weather_data)} cities.")
llm_ready_data = process_data_for_llm(all_weather_data)
analysis_result = get_weather_analysis(llm_ready_data)
if analysis_result:
print("\n--- Kairos Recommendation ---")
print(json.dumps(analysis_result, indent=2))
print("\nWorkflow complete!")
else:
print("\nCould not get weather analysis. Workflow stopped.")
if __name__ == "__main__":
main()