from fastcore.test import test_eq
from nbdev.showdoc import *
URL Construction Functions¶
url_path_query is a generic low-level function. It requires specification of required path and if used without other specific arguments, returns over 17000 records.
cntry is a two-letter country code as was specified in FIPS 10-4 (US Federal Information Processing Standard), which is now absolete a bit differs from the international ISO 3166 standard. See details.
The library provides a helper function to work around the current ambiguity.
pgid is a string with people group id.
extra is an optional argument in a form field=value, for example: 'LeastReached=Y'
month and day are optional arguments of type int or str used in url_upgotd to specify the date for which to request the unreached people group. If either is omitted, the value of the current date is used. If int values are passed, these are coverted to proper str.
test_eq(url_path_query('/api/v2/people_groups'),
f'https://joshuaproject.net/api/v2/people_groups?&api_key={api_key}')
url_path_query is a generic function. More specific functions are described below.
m, d = date.today().strftime("%-m"), date.today().strftime("%-d")
# Today
test_eq(url_upgotd(),
f'https://joshuaproject.net/api/v2/upgotd?&LRofTheDayMonth={m}&LRofTheDayDay={d}&api_key={api_key}')
# Any `month` and `day`
test_eq( url_upgotd(month=10, day=1),
f'https://joshuaproject.net/api/v2/upgotd?&LRofTheDayMonth=10&LRofTheDayDay=1&api_key={api_key}')
# Current month, specific `day`
test_eq( url_upgotd(day='15'),
f'https://joshuaproject.net/api/v2/upgotd?&LRofTheDayMonth={m}&LRofTheDayDay={15}&api_key={api_key}')
Note, since cntry is the first positional argument, it can be passed by value only.
country = 'EN'
test_eq(url_pgs_cntry(country),
f'https://joshuaproject.net/api/v2/people_groups?ROG3={country}&api_key={api_key}')
country='IN'
test_eq(url_upgs_cntry(country),
f'https://joshuaproject.net/api/v2/people_groups?ROG3={country}&LeastReached=Y&api_key={api_key}')
country='RS'
test_eq(url_pg_cntry(cntry=country),
f'https://joshuaproject.net/api/v2/people_groups?ROG3={country}&api_key={api_key}')
People group is to be encoded as PeopleID3 -- People-Group-Across-Countries ID number.
pgid=18859
test_eq(url_pg_cntries(pgid=pgid),
f'https://joshuaproject.net/api/v2/people_groups?&PeopleID3={pgid}&api_key={api_key}')
country = 'BD'
test_eq(url_cntry(country),
f'https://joshuaproject.net/api/v2/countries?ROG3={country}&api_key={api_key}')
Language argument is a three letter code: https://www.ethnologue.com/codes.
lang = 'hau'
test_eq(url_lang(lang=lang),
f'https://joshuaproject.net/api/v2/languages?&ROL3={lang}&api_key={api_key}')