This repository contains the code for a FastAPI application that generates weather reports and news updates for cities around the world. The application uses data from the OpenWeatherMap API, Microsoft Bing News Search API, and the OpenAI GPT-4 model to generate the reports.
-
Modular Design: Separate modules for each endpoint and service.
-
Security: Sensitive parameters are hidden from logs with a custom transport class.
-
Localization: Content is tailored to the primary language of each city.
-
Integration: Multiple APIs and GPT-4 model are combined in one service.
The purpose of this application is to generate short weather reports and news updates for a given city in the style of a local news reporter. The reports are based on real-time weather data from the OpenWeatherMap API and news data from the Microsoft Bing News Search API. The language of the report is determined by the primary language spoken in the city.
The application uses the OpenAI GPT-4 model to generate the reports. The model is given a prompt that includes the city name, the weather data, and the news data, and it generates a report that includes inside jokes about the city and sounds like it was written by a local news reporter from the city.
The application is organized into the following directories:
app
: This is the main directory that contains the FastAPI application.endpoints
: This directory contains the endpoint modules for the application. Each endpoint has its own module.services
: This directory contains the service modules for the application. Each service (OpenWeatherMap, OpenAI, Microsoft Bing News Search) has its own module.security
: This directory contains the security-related modules, such as the custom transport class for hiding sensitive parameters from the logs.
.
├── app
│ └── main.py
├── endpoints
│ ├── weather.py
│ ├── weather_report.py
│ └── news_report.py
├── services
│ ├── openai.py
│ ├── openweathermap.py
│ └── bing_news_search.py
└── security
│ └── transport.py
To use this application, you need to have Docker installed on your machine. You can then build and run the Docker image using the following commands:
docker build -t weather-api .
docker run -p 80:80 weather-api
Once the application is running, you can access it at http://localhost:80
. The application provides two endpoints:
/weather/{city}
: Returns the current weather data for the city from the OpenWeatherMap API./weather-report/{city}
: Returns a weather report for the city generated by the GPT-4 model./news-report/{city}
: Returns a news report for the city, which includes a summary of the top 3 news articles and a weather report.
Replace {city}
with the name of the city you want data for.