A FastAPI-based REST API that fetches and stores daily quotes from Wikiquote. The application provides endpoints to retrieve the quote of the day, search historical quotes, and filter quotes by author.
- Fetch and store daily quotes from Wikiquote
- Retrieve quote of the day
- Search historical quotes by date
- Filter quotes by author
- Pagination support
- MariaDB/MySQL database storage
- Clean and modular code structure
- Python 3.10+
- pip (Python package manager)
- MariaDB/MySQL database
-
Clone the repository:
git clone https://github.com/Agamya-Samuel/wq-qotd.git cd wq-qotd
-
Create a virtual environment:
python -m venv venv
-
Activate the virtual environment:
- Windows:
.\venv\Scripts\activate
- Unix/MacOS:
source venv/bin/activate
- Windows:
-
Install dependencies:
pip install -r requirements.txt
-
Create a
.env
file in the project root using.env.example
as a template:DB_HOST=localhost DB_PORT=3306 DB_USER=your_username DB_PASSWORD=your_password DB_NAME=your_database
-
Create the database:
CREATE DATABASE your_database;
-
Initialize the database:
python -m app.database.init_db
-
Start the FastAPI server:
uvicorn main:app --reload
-
Access the API documentation at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
GET /api/quote_of_the_day
: Get today's quoteGET /api/quotes/{date}
: Get quote by date (YYYY-MM-DD)GET /api/quotes
: Get all quotes (with pagination and author filter)
wq-qotd/
├── app/
│ ├── __init__.py
│ ├── api/
│ │ ├── __init__.py
│ │ └── routers/
│ │ └── quotes.py
│ ├── core/
│ │ ├── __init__.py
│ │ ├── config.py
│ │ └── utils.py
│ ├── database/
│ │ ├── __init__.py
│ │ ├── crud.py
│ │ ├── models.py
│ │ └── init_db.py
│ └── schemas/
│ ├── __init__.py
│ └── schemas.py
├── main.py
├── requirements.txt
├── .env
├── .env.example
└── README.md
app/
: Main application packageapi/
: API-related coderouters/
: FastAPI route handlers
core/
: Core application codeconfig.py
: Configuration settingsutils.py
: Utility functions
database/
: Database-related codecrud.py
: Database operationsmodels.py
: SQLAlchemy modelsinit_db.py
: Database initialization
schemas/
: Pydantic models for request/response validation
id
: String (32 chars) - MD5 hash of quote and authorquote
: String (1000 chars) - The quote textauthor
: String (255 chars) - The quote's authorfeatured_date
: Date - The date the quote was featured (YYYY-MM-DD)
- Follow PEP 8 style guide for Python code
- Use type hints for better code readability
- Write descriptive docstrings for functions and classes
- Keep functions small and focused
- Use meaningful variable and function names
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Make your changes
- Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Wikiquote for providing the quotes
- FastAPI for the amazing web framework
- SQLAlchemy for the ORM
- Pydantic for data validation
- MariaDB for the database system