A Multithreaded Python Tool with Clean Output
A simple yet powerful Python script that retrieves random Hadiths from HadithAPI using a producer-consumer threading model. The displayed Hadiths are well-formatted, and only valid (complete) ones are shown.
- π§΅ Multithreaded design
Producer retrieves Hadiths, Consumer displays them - β
Only complete Hadiths are shown
(Heading, Narrator, Text, Book, Chapter, and Status) - π¦ Clean output with headings
- π Browse multiple Hadiths in one session β press Enter to continue, or type
nto quit - π Handles missing API key automatically:
- Launches HadithAPI in your browser
- Reads API key from clipboard (
pyperclip) - Validates and saves it
- π Alerts you if no valid Hadiths are found
Retrieves Hadiths from NUM_PAGES random pages using HadithAPI and puts each Hadith into a queue.
Reads Hadiths from the queue one-by-one, validates them, and displays formatted output to the user.
git clone https://github.com/Umair-Awans/Random-Hadith.git
cd Random-Hadith- Install Dependencies
Install the required packages:
pip install requests pyperclip
- API Key Setup
You do not need to manually create API_KEY.txt anymore!
The script will:
Open HadithAPI in your browser
Ask you to sign up and copy the API key
Read it from your clipboard
Validate and save it automatically β
Prefer manual setup? Create a file called API_KEY.txt and paste your key in it.
- Run the Script
python main.py
Youβll see a Hadith with headings displayed in your terminal.
Press Enter to see another, or type n to quit. π Example Output
==================================================
Heading: Excellence of Performing Wudu Perfectly
Narrator: Abu Hurairah (RA)
Hadith: The Messenger of Allah (ο·Ί) said: "When a Muslim or a believer washes his face..."
Book: Sahih Muslim Chapter 2: Ablution Status: Sahih
==================================================
π‘ Future Ideas
π Add search/filter by Book, Narrator, or Topic
πΌοΈ Convert to GUI using PyQt5
πΎ Save favorite Hadiths to a file
π Add support for Arabic Hadith display
π License
MIT License β free to use and modify with attribution.
Made with β€οΈ by Umair Visit HadithAPI.com