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
.envfile in the project root using.env.exampleas 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
| ├── static/
│ ├── index.html
| ├── style.css
│ └── script.js
├── 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 validationstatic/: Frontend Related Code
The application includes a built-in frontend interface served directly from the FastAPI backend.
- Modern, responsive design
- Quote of the Day display
- Date-based quote search
- Author filtering
- Pagination for quote browsing
- Error handling and user feedback
The frontend is located in the app/static directory:
app/static/
├── index.html # Main HTML structure|
├── style.css # custom CSS file
└── script.js # Frontend logic and API interactions- HTML5 for structure
- Bootstrap 5 (via Toolforge CDN) for responsive UI components and styling
- Vanilla JavaScript for functionality
- Wikimedia Fonts (Roboto) for typography
The frontend is automatically served when you run the FastAPI application:
-
Quote of the Day Section
- Automatically displays the current day's quote
- Updates daily
- Animated card layout
-
Date Search Section
- Date picker for historical quotes
- Immediate feedback on search results
- Error handling for invalid dates or missing quotes
-
Quote Collection Section
- Author-based filtering
- Pagination controls
- Responsive quote cards
- Loading states and error handling
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