Fetches a random joke daily from various joke APIs and displays it with smart caching to ensure you get one joke per day!
- Multiple Joke APIs - Fetches from 3 different joke sources:
- JokeAPI (v2.jokeapi.dev)
- Official Joke API
- icanhazdadjoke
- Smart Caching - One joke per day (cached locally)
- Joke History - View jokes from previous days
- Force New Joke - Get a new random joke anytime
- Beautiful Formatting - Clean, readable output with emojis
- Automatic API Rotation - Tries different APIs for variety
- Error Handling - Graceful fallback if APIs are unavailable
- Python 3.6+
requestslibrary
- Install the required package:
pip install requests- Run the program:
python main.pyThe program offers 4 options:
Shows the cached joke for today. If no joke exists for today, fetches a new one.
Forces fetching a new joke from the API, ignoring the cache.
Displays jokes from the last 7 days.
Exits the program.
======================================================================
😂 DAILY JOKE OF THE DAY 😂
======================================================================
📅 Date: October 21, 2025
⏰ Time: 02:30 PM
🔗 Source: JokeAPI
======================================================================
Why don't scientists trust atoms?
Because they make up everything!
======================================================================
-
Caching System:
- Stores one joke per day in
daily_joke_cache.json - Prevents redundant API calls
- Maintains joke history
- Stores one joke per day in
-
API Rotation:
- Automatically rotates between different joke APIs
- Provides variety in joke styles
- Ensures reliability if one API is down
-
Smart Fetching:
- Checks cache first for today's date
- Only fetches from API if needed
- Tries multiple APIs if one fails
- URL:
https://v2.jokeapi.dev/joke/Any?safe-mode - Supports both single and two-part jokes
- Safe mode enabled (no offensive content)
- URL:
https://official-joke-api.appspot.com/random_joke - Clean programming and general jokes
- Two-part format (setup + punchline)
- URL:
https://icanhazdadjoke.com/ - Dad jokes collection
- Single-line format
main.py- Main programdaily_joke_cache.json- Auto-generated cache file (stores jokes)
- Saves jokes with date, source, and timestamp
- Automatically creates cache file on first run
- Prevents fetching the same joke multiple times
- Gracefully handles API failures
- Tries alternative APIs
- Shows friendly error messages
- Clean menu system
- Colored emojis for visual appeal
- Formatted joke display with metadata
Run the program daily to get a fresh joke! The program ensures:
- Only one joke is fetched per day (saves API calls)
- Cached joke is shown if you run multiple times per day
- History keeps track of previous jokes
Schedule to run at 9 AM daily:
python "path\to\main.py"Add to crontab:
0 9 * * * python3 /path/to/main.pyModify the script to automatically display and exit:
if __name__ == "__main__":
fetcher = DailyJokeFetcher()
joke, source, is_cached = fetcher.get_daily_joke()
fetcher.display_joke(joke, source, is_cached)Feel free to:
- Add more joke APIs
- Improve joke formatting
- Add joke categories/filters
- Implement joke rating system
This project is open source and available for educational purposes.
Start your day with a laugh! 😂