quran / quran.com-api

Quran.com content APIs
https://api-docs.quran.foundation/docs/category/content-apis
MIT License
921 stars 191 forks source link

Access to the DB #44

Closed timRa closed 8 years ago

timRa commented 8 years ago

I would like to have an access to the DB for word to word translation. Please let me know what is the procedure to get the access. Thanks

mmahalwy commented 8 years ago

@timRa thanks for pinging. We usually give access to people we are familiar with, know personally or have contributed to our projects. Please don't take it personally, we just have had incidents in the past where people copy our codebase and deploy it as their own and at times with ads.

Perhaps send me an email at mohamed@quran.com and we can get to know you?

CC @ahmedre

timRa commented 8 years ago

I really appreciate that you messaged me. Thanks very much. I have an application which shows various translation but it doesn't have word to word translation. I have built that for myself. I would like to add word to word translation functionality in it. If I can get the word to word translation db, I will be great help to me. I am not using my application for any commercial use. In fact this application is very much tailored for me only. Attached is the image of it as well. I have attached the image If you need more details, please let me know. I have also sent an email to you @ your email address mohamed@quran.com. Thanks q

mmahalwy commented 8 years ago

@timRa what I suggest for the time being is to call the API directly to get the data you need. How does that sound ?

dashohoxha commented 8 years ago

@timRa I think that accessing the data through an API is always better than having direct access to the DB, @mmahalwy is right. However I am not sure whether you need any credentials to access the API (client_id, client_secret) or it is open to everyone. Also I am not sure how you should learn about how to use the API. Maybe by looking at the examples from the existing code.

timRa commented 8 years ago

Thanks for your response. You are right, API access would be better, so that applications just worry about the UI. My application works offline most of the time, that's why I requested the db access. I will be appreciated if you help this. If you need any-other information, please let me know. Thanks

dashohoxha commented 8 years ago

It seems like a huge task, and a waste of time, to build an offline application, only for yourself. Even if you got the DB, probably you would need lots of resources to make it work properly (for example installing a server in a VM, maybe on Docker, which needs this much RAM and resources, etc.). So, why don't you try to make sure that you have internet connection. This is not a luxury nowadays, everybody has internet connection, everywhere. Anyway this is just my opinion.

timRa commented 8 years ago

Thanks for your response. My application is built in C# .NET and database in MS Access. I don't know how to work with the technologies you mentioned (Docker). If I get a database, I needed to the convert it into the MS Access. I created this simple application for understanding various translations and bookmarks. In it, word by word translation is missing; that's why I was requesting that from you. I hope, I have clarified. Thanks

dashohoxha commented 8 years ago

I am not sure, but I think that this is impossible, because MS Access is a simplistic database (it lacks some features of a real database).

timRa commented 8 years ago

Thanks for answering so quickly. I understand your concern. Since you might have the database with huge amount of information and other database related functions were built in DBMS. You are right it is not wise to built an application with complex functionality which is already built. My requirement is very simple and different. All I want is to display the word to word translation in my application; which is relative a simple task. I am sure, MS Access can help this. It would something like this: الرَّحِيمِ (the Compassionate) الرَّحْمَٰنِ(the Merciful) بِسْمِ اللَّهِ (In the name of Allah) Thanks

mmahalwy commented 8 years ago

@timRa sorry, I think I will have to go with @dashohoxha on this one. Here are the reasons:

timRa commented 8 years ago

Thanks for your response. I understand your concern. If someone is borrowing the database from you and start using on his name commercially; which is ethically incorrect and shows the lower character and moral standards. Please provide the API (id/secret) for the access as mentioned by @dashohoxha initially. I am sure, there must be some documentation that would help me understand the available API/functions. Thanks,

mmahalwy commented 8 years ago

There is no client or secret right now, although it will be coming soon. We haven't had a chance to build documentation and is discussed in https://github.com/quran/quran.com-api/issues/46

timRa commented 8 years ago

Please let me know the URL of the API and I hope I can call that URL as a RESTful service. Please let me know if I have incorrect understanding. Thanks

timRa commented 8 years ago

As mentioned by @dashohoxha that accessing the data using API is better approach than direct access to DB. Would you please let me know URL of the API to use. Thanks

mmahalwy commented 8 years ago

@timRa see http://staging.quran.com:3000/docs

dashohoxha commented 8 years ago

I find this API quite simple (not complicated), which is a good thing.

But still I find some problems with the terminology. Maybe you will consider improving it on version 3, if you don't mind, whenever you have time to work on it. For example "audio" in my opinion should have been "reciter", "content" could have been "translation", etc.

I also find "ayahs" and "surahs" an ugly mix of Arabic and English. It might be better if they are renamed to "chapters" and "verses" or something similar.

May you have peace.

mmahalwy commented 8 years ago

@dashohoxha agreed

dashohoxha commented 8 years ago

Quick API testing for the begginers (you may add it to the docs somewhere):

# Options:
curl -s http://api.quran.com:3000/options/language | python -m json.tool
curl -s http://api.quran.com:3000/options/quran | python -m json.tool
curl -s http://api.quran.com:3000/options/content | python -m json.tool
curl -s http://api.quran.com:3000/options/audio | python -m json.tool

# Pages:
curl -s http://api.quran.com:3000/v2/pages/10 | python -m json.tool
No JSON object could be decoded

# Surahs:
curl -s http://api.quran.com:3000/v2/surahs/1 | python -m json.tool
curl -s http://api.quran.com:3000/v2/surahs/114 | python -m json.tool
curl -s http://api.quran.com:3000/v2/surahs | python -m json.tool

# Search:
curl -s 'http://api.quran.com:3000/v2/search?q=allah&size=2' | python -m json.tool

# Ayahs:
curl -s 'http://api.quran.com:3000/v2/surahs/114/ayahs?from=1&to=3' | python -m json.tool
{
    "error": "Internal Server Error",
    "status": "500"
}
dashohoxha commented 8 years ago

See also this: http://dashohoxha.fs.al/quran.com-frontend/api-examples/js/

timRa commented 8 years ago

I can use the API. Thanks very much to both of you (@mmahalwy and @dashohoxha) for the help.

mmahalwy commented 8 years ago

@dashohoxha thanks so much for the examples. The status 500 will be fixed inshallah very shortly!

mmahalwy commented 8 years ago

Also, we should use this for examples: https://github.com/Apipie/apipie-rails#examples-recording

dashohoxha commented 8 years ago

Why not, but it is not something that I can do, at least not right now. Maybe some other guys could give it a try.

dashohoxha commented 8 years ago

On the other hand, having an open API, that everybody can access, is a bit delicate situation, because it is easy to make a DOS (denial of service) attack and to block the main website (quran.com). It may be better to have 2 API servers, one used exclusively by quran.com, and another open to everyone, to be used by developers, testers and external (third party) applications. Maybe we should consider something like this for the future.

mmahalwy commented 8 years ago

@dashohoxha or we might implement a access token based API

dashohoxha commented 8 years ago

It is quite possible, using an oauth2 server:

However having a dev/test clone of the API server may still be a worthy idea.

timRa commented 8 years ago

Quick question for @mmahalwy. The result of the this API call http://staging.quran.com:3000/v2/surahs/1/ayahs return words with one of the item "word_id". How is this "word_id" going to refer back to the actual Arabic word text. Thanks

mmahalwy commented 8 years ago

@timRa I'd ignore the word_id key as it's just for internal database reference. I should probably not show it. Especially that the ayah markers do not have an id, see:

  {
        "resource_id": 1,
        "ayah_key": "1:2",
        "position": 5,
        "word_id": null,
        "page_num": 1,
        "line_num": 3,
        "code_dec": 64346,
        "code_hex": "fb5a",
        "char_type_id": 2,
        "class_name": "p1",
        "code": "&#xfb5a",
        "translation": null,
        "transliteration": null
      }
timRa commented 8 years ago

Thanks for responding. In the json data we can find translation and transliteration. But we cannot find the actual Arabic word. Like in this case below أَنْعَمْتَ . Would you please add the Arabic word into the json data as well. { "resource_id": 1, "ayah_key": "1:7", "position": 3, "word_id": 23, "page_num": 1, "line_num": 6, "code_dec": 64365, "code_hex": "fb6d", "char_type_id": 1, "class_name": "p1", "code": "&#xfb6d", "translation": "You have bestowed (Your) Favors", "transliteration": "anʿamta" } Thanks

mmahalwy commented 8 years ago

@timRa sounds good, @maryamklabib ^^

timRa commented 8 years ago

Thanks very much. Let me know when this update is available in the API.

timRa commented 8 years ago

@maryamklabib, I didn't understand your solution. Basically I am using this staging environment API (http://staging.quran.com:3000/v2/surahs/1/ayahs) and asking the Arabic text can be returned for each word as well. If you have mentioned a different way to access this information, please clarify which API, I can use to do that. Thanks

maryamklabib commented 8 years ago

@timRa sure no problem. So I changed the endpoint you linked to have the Arabic text for each word as well. Before each word had a group of fields, ending with "translation" and "transliteration". I added a field at the end called "arabic" which contains the individual Arabic word.

The screenshot below is of the first entry at the link you provided:

screen shot 2016-07-10 at 12 07 29 am

Does this meet your needs?

mmahalwy commented 8 years ago

@maryamklabib hmmm perhaps we could have renamed it to 'text'

maryamklabib commented 8 years ago

@mmahalwy sure that's a quick change. @timRa is renaming to 'text' more intuitive?

timRa commented 8 years ago

Thanks very much @maryamklabib. I really appreciate your help and quick response. I will test and use it and if I have any questions, I will ask. Thanks,