A Flask web application with a React frontend that serves random jokes from a local file and tracks usage statistics using SQLite.
- Random Joke API: Get random jokes from a curated collection of 30 classic jokes
- Usage Tracking: SQLite database tracks joke requests with timestamps and IP addresses
- Statistics Endpoint: View joke request statistics for the last 24 hours
- React Frontend: Interactive web interface with a "Request Joke" button
- Real-time Counter: Shows total jokes requested today
.
├── app.py # Flask application with API endpoints
├── jokes.txt # Collection of 30 jokes
├── jokes.db # SQLite database (created automatically)
├── .gitignore # Git ignore file
└── README.md # This file
Serves the React frontend interface
Returns a random joke from the jokes.txt file
{
"joke": "Why did the cookie go to the doctor? Because it felt crumbly!"
}Returns statistics about joke requests in the last 24 hours
{
"jokes_requested_24h": 5,
"timestamps": [1748692200.35, 1748692207.99, ...],
"user_ip": "127.0.0.1"
}-
Install Dependencies
pip install flask
-
Run the Application
python3 app.py
-
Access the Application
- Frontend: http://localhost:5000
- API: http://localhost:5000/get-joke
- Open http://localhost:5000 in your browser
- Click the "Request Joke" button to get a random joke
- The counter shows how many jokes have been requested today
# Get a random joke
curl http://localhost:5000/get-joke
# Get usage statistics
curl http://localhost:5000/joke-statsThe SQLite database (jokes.db) contains a single table:
CREATE TABLE joke_requests (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_ip TEXT NOT NULL,
timestamp REAL NOT NULL
);- Backend: Flask (Python)
- Frontend: React 18 with Babel for JSX transformation
- Database: SQLite3
- Styling: CSS with modern design and responsive layout
- Error Handling: Comprehensive error handling for API requests and database operations
- AI-Generated: This entire application, including the code and deployment setup, was developed by an AI.
The application automatically:
- Creates the SQLite database and table on first run
- Loads jokes from the local
jokes.txtfile - Tracks all joke requests with IP addresses and timestamps
- Serves a fully functional React frontend
✅ Flask application with /get-joke endpoint
✅ Local jokes.txt file with 30 jokes
✅ SQLite database for request tracking
✅ React frontend with "Request Joke" button
✅ Real-time statistics and counter
✅ Error handling and loading states
✅ Responsive design
This project is open source and available under the MIT License.