Automated Action 1468af1391 Add Weather Data API with OpenWeatherMap integration
- Created FastAPI application with SQLite database integration
- Implemented OpenWeatherMap client with caching
- Added endpoints for current weather, forecasts, and history
- Included comprehensive error handling and validation
- Set up Alembic migrations
- Created detailed README with usage examples

generated with BackendIM... (backend.im)
2025-05-12 14:26:44 +00:00

45 lines
1.5 KiB
Python

from sqlalchemy import Column, Integer, String, Float, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from datetime import datetime
from app.database.session import Base
class City(Base):
__tablename__ = "cities"
id = Column(Integer, primary_key=True, index=True)
name = Column(String, index=True)
country = Column(String)
latitude = Column(Float)
longitude = Column(Float)
created_at = Column(DateTime, default=datetime.utcnow)
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
weather_records = relationship("WeatherRecord", back_populates="city")
def __repr__(self):
return f"<City {self.name}, {self.country}>"
class WeatherRecord(Base):
__tablename__ = "weather_records"
id = Column(Integer, primary_key=True, index=True)
city_id = Column(Integer, ForeignKey("cities.id"))
temperature = Column(Float)
feels_like = Column(Float)
humidity = Column(Integer)
pressure = Column(Integer)
wind_speed = Column(Float)
wind_direction = Column(Integer)
weather_condition = Column(String)
weather_description = Column(String)
clouds = Column(Integer)
rain_1h = Column(Float, nullable=True)
snow_1h = Column(Float, nullable=True)
timestamp = Column(DateTime, index=True)
created_at = Column(DateTime, default=datetime.utcnow)
city = relationship("City", back_populates="weather_records")
def __repr__(self):
return f"<WeatherRecord for {self.city.name} at {self.timestamp}>"