loading
open in
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import requests

#few counters to keep track of word counts
count_meccan=0
count_medinan = 0

#these two counters to keep track of total surah numbers
n_mekki=0
n_madani=0

#loop over the total 114 surah of Quran
for i in range(1,115):
    url='http://api.alquran.cloud/surah/'+str(i)
    json_data = requests.get(url).json()
    if (json_data['data']['revelationType'] == 'Meccan'):
        n_mekki+=1
        total_words = 0
        for aya in json_data['data']['ayahs']:
            length = len(aya['text'].split())
            total_words+= length
        print(str(i) + ' Meccan - Words: ' + str(total_words))
        count_meccan+=total_words
    else:
        n_madani+=1
        total_words = 0
        for aya in json_data['data']['ayahs']:
            length = len(aya['text'].split())
            total_words+= length
        count_medinan+=total_words
        print(str(i) + ' Medinan - Words: ' + str(total_words))

print('Quran has 114 surah among them '+ str(n_mekki) + ' Meccan Surah, and '+ str(n_madani) + ' Madani')
total_words = count_meccan + count_medinan
print('Total words in Quran: {:d}'.format(total_words))
percent_m = (count_meccan/total_words)*100
percent_d = (count_medinan/total_words)*100
print('Mekki words: {0:d} [{1:.0f}%]'.format(count_meccan, percent_m))
print('Madani words: {0:d} [{1:.0f}%]'.format(count_medinan, percent_d))
Python 3.6.1 (default, Dec 2015, 13:05:11) [GCC 4.8.2] on linux