66import requests
77
88
9- def get_number_of_visitors (language : str ) -> int :
9+ def get_number_of_visitors (language : str ) -> tuple [ int , float | None ] :
1010 param = urllib .parse .urlencode ({'filters' : f'[["contains","event:page",["/{ language } /"]]]' })
1111 r = requests .get (f'https://plausible.io/docs.python.org/export?{ param } ' , timeout = 10 )
12+ d = languages_data .get (language )
13+ p = d and (d ['native_speakers_millions' ] * d ['literacy_rate_percentage' ] + d ["second_language_learners_millions" ] * 10e6 )
1214 with zipfile .ZipFile (io .BytesIO (r .content ), 'r' ) as z , z .open ('visitors.csv' ) as csv_file :
1315 csv_reader = csv .DictReader (io .TextIOWrapper (csv_file ))
14- return sum (int (row ["visitors" ]) for row in csv_reader )
16+ sum_ = sum (int (row ["visitors" ]) for row in csv_reader )
17+ return sum_ , p and (sum_ / p * 10000 )
18+
19+ languages_data = {
20+ "ar" : {"native_speakers_millions" : 310 , "literacy_rate_percentage" : 76 , "second_language_learners_millions" : 24 },
21+ "bn-in" : {"native_speakers_millions" : 230 , "literacy_rate_percentage" : 74 , "second_language_learners_millions" : 20 },
22+ "es" : {"native_speakers_millions" : 495 , "literacy_rate_percentage" : 97 , "second_language_learners_millions" : 24 },
23+ "fa" : {"native_speakers_millions" : 80 , "literacy_rate_percentage" : 85 , "second_language_learners_millions" : 50 },
24+ "fr" : {"native_speakers_millions" : 80 , "literacy_rate_percentage" : 99 , "second_language_learners_millions" : 200 },
25+ "gr" : {"native_speakers_millions" : 13 , "literacy_rate_percentage" : 97 , "second_language_learners_millions" : 0.4 },
26+ "id" : {"native_speakers_millions" : 43 , "literacy_rate_percentage" : 96 , "second_language_learners_millions" : 12 },
27+ "it" : {"native_speakers_millions" : 67 , "literacy_rate_percentage" : 99 , "second_language_learners_millions" : 2 },
28+ "hi-in" : {"native_speakers_millions" : 341 , "literacy_rate_percentage" : 74 , "second_language_learners_millions" : 120 },
29+ "hu" : {"native_speakers_millions" : 13 , "literacy_rate_percentage" : 99.1 , "second_language_learners_millions" : 2 },
30+ "ja" : {"native_speakers_millions" : 125 , "literacy_rate_percentage" : 99 , "second_language_learners_millions" : 3 },
31+ "ko" : {"native_speakers_millions" : 81 , "literacy_rate_percentage" : 98 , "second_language_learners_millions" : 13 },
32+ "lt" : {"native_speakers_millions" : 3 , "literacy_rate_percentage" : 99.8 , "second_language_learners_millions" : 0.2 },
33+ "mr" : {"native_speakers_millions" : 83 , "literacy_rate_percentage" : 82.9 , "second_language_learners_millions" : 3 },
34+ "pl" : {"native_speakers_millions" : 38 , "literacy_rate_percentage" : 98 , "second_language_learners_millions" : 2 },
35+ "pt" : {"native_speakers_millions" : 232 , "literacy_rate_percentage" : 93.5 , "second_language_learners_millions" : 25 },
36+ "pt-br" : {"native_speakers_millions" : 260 , "literacy_rate_percentage" : 94 , "second_language_learners_millions" : 10 },
37+ "ru" : {"native_speakers_millions" : 154 , "literacy_rate_percentage" : 99.7 , "second_language_learners_millions" : 61 },
38+ "tr" : {"native_speakers_millions" : 88 , "literacy_rate_percentage" : 96 , "second_language_learners_millions" : 5 },
39+ "uk" : {"native_speakers_millions" : 40 , "literacy_rate_percentage" : 99 , "second_language_learners_millions" : 2 },
40+ "zh-cn" : {"native_speakers_millions" : 920 , "literacy_rate_percentage" : 96 , "second_language_learners_millions" : 300 },
41+ "zh-tw" : {"native_speakers_millions" : 25 , "literacy_rate_percentage" : 98 , "second_language_learners_millions" : 20 },
42+ }
0 commit comments