Skip to content

A simple yet powerful Python script that fetches random Hadiths from HadithAPI using a producer-consumer threading model. The displayed Hadiths are well-formatted for clarity, and only valid (complete) ones are shown.

Notifications You must be signed in to change notification settings

Umair-Awans/Random-Hadith

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ•Œ Hadith Viewer β€” A Simple Way to Read the Words of the Prophet ο·Ί

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.


✨ Features

  • 🧡 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 n to 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

🧠 How It Works

🧡 Producer Thread

Retrieves Hadiths from NUM_PAGES random pages using HadithAPI and puts each Hadith into a queue.

🧡 Consumer Thread

Reads Hadiths from the queue one-by-one, validates them, and displays formatted output to the user.


πŸš€ Getting Started

1. Clone the Repository

git clone https://github.com/Umair-Awans/Random-Hadith.git
cd Random-Hadith
  1. Install Dependencies

Install the required packages:

pip install requests pyperclip

  1. 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.
  1. 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


About

A simple yet powerful Python script that fetches random Hadiths from HadithAPI using a producer-consumer threading model. The displayed Hadiths are well-formatted for clarity, and only valid (complete) ones are shown.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages