Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

random hadith endpoint #9

Closed
theflightguy2 opened this issue Aug 26, 2022 · 12 comments
Closed

random hadith endpoint #9

theflightguy2 opened this issue Aug 26, 2022 · 12 comments

Comments

@theflightguy2
Copy link

Salaam, is there any way we can get a random hadith using this API and Python? Any code sample?

@fawazahmed0
Copy link
Owner

Walaikum salam, you need to implement the logic in python

first you need to generate a random number
then use that random number in this url format:
https://cdn.jsdelivr.net/gh/fawazahmed0/hadith-api@1/editions/eng-abudawud/{randomnumber}.json

and then to get data from url, refer this example

@theflightguy2
Copy link
Author

Ah ok, Jzk Khair.

Does this API include Bukhari, Muslim, Sunan books etc? Or is it just riyadusalihin like sunnah.com?

@fawazahmed0
Copy link
Owner

Yes it includes those books.
Here is a demo website I created using this api:
Demo

Here are the list of available books :
https://cdn.jsdelivr.net/gh/fawazahmed0/hadith-api@1/editions.json

@theflightguy2
Copy link
Author

Great news... can I just ask one more thing, this endpoint you just gave which book will it yield the hadith from? And is there any range of numbers from whioch we should generate the number#

Appreciate the help, May Allah SWT bless you as well.

@fawazahmed0
Copy link
Owner

For range, refer last_hadithnumber at this link:
https://cdn.jsdelivr.net/gh/fawazahmed0/hadith-api@1/info.json

For sahih muslim english edition, use this:
https://cdn.jsdelivr.net/gh/fawazahmed0/hadith-api@1/editions/eng-muslim/{randomnumber}.json
sahih muslim arabic edition
https://cdn.jsdelivr.net/gh/fawazahmed0/hadith-api@1/editions/ara-muslim/{randomnumber}.json

For abu dawud english edition,
https://cdn.jsdelivr.net/gh/fawazahmed0/hadith-api@1/editions/eng-abudawud/{randomnumber}.json

Refer https://cdn.jsdelivr.net/gh/fawazahmed0/hadith-api@1/editions.json for all editions available

@theflightguy2
Copy link
Author

theflightguy2 commented Aug 27, 2022 via email

@fawazahmed0
Copy link
Owner

can you give me the link which is showing error?

@theflightguy2
Copy link
Author

theflightguy2 commented Aug 27, 2022 via email

@fawazahmed0
Copy link
Owner

fawazahmed0 commented Aug 28, 2022

You have to replace the {randomnumber} with the random number generated in python.
For example this link:
https://cdn.jsdelivr.net/gh/fawazahmed0/hadith-api@1/editions/eng-muslim/{randomnumber}.json
may become
https://cdn.jsdelivr.net/gh/fawazahmed0/hadith-api@1/editions/eng-muslim/77.json

I assume you are new to development, it's better if you take some python's beginners course, that should definitely help you in developing your application

@theflightguy2
Copy link
Author

theflightguy2 commented Aug 28, 2022 via email

@fawazahmed0
Copy link
Owner

oh ok! May Allah bless you for making hadith app 🙂

@theflightguy2
Copy link
Author

theflightguy2 commented Aug 28, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants