Constructing the bilara-data URL for a given sutta

If I want to construct the URL for a given suttas text in bilara-data, how do I do this?

For something like MN8 this is straightforward - https://github.com/suttacentral/bilara-data/blob/published/translation/en/sujato/sutta/mn/mn8_translation-en-sujato.json.

But for something like Iti14 - https://github.com/suttacentral/bilara-data/blob/published/translation/en/sujato/sutta/kn/iti/vagga2/iti14_translation-en-sujato.json - how do I know to add the “/vagga2/” part?

Is there some lookup table that maps suttas to URLs?

1 Like

Wow you have just chosen the most difficult example! The content of the Iti folders does not follow any logical system. While translating that collection, when I was looking for a particular Sutta, I just went there and opened the folders to look what is inside …

Not sure if there’s a better way? Learn them by heart? :see_no_evil: :person_shrugging:

Haha I want to access them programatically.

Ok I created a mapping table, here’s the code in case anyone is interested.

library(stringr)
library(purrr)
library(gh)
library(jsonlite)
library(dplyr)
library(readr)

# Check Github API calls remaining.
rate <- gh("GET /rate_limit")
calls_remaining <- rate$rate$limit - rate$rate$used
if (calls_remaining < 72) stop("API calls insufficient.")

sutta_list_root <- "/repos/suttacentral/bilara-data/contents/translation/en/sujato/sutta/"

nikayas <- c("dn", "mn", "sn", "an", "kn")

sutta_list <- unlist(map(sutta_list_root, paste0, nikayas))

resp <- map(paste0("GET ", sutta_list), gh)
names(resp) <- nikayas

raw_content_url <- function (resp) {
  lapply(resp, function (x) {
    if (is.null(x$download_url)) {
      raw_content_url(gh(x$url)) 
    } else {
      x$download_url
    }
  })
}

download_urls <- unlist(lapply(resp, raw_content_url))

output <- tibble(url = download_urls) %>% 
  mutate(sutta = str_remove(url, "^.*(?=/)/")) %>% 
  mutate(sutta = str_remove(sutta, "(?=_).*$")) %>% 
  toJSON(pretty = TRUE)
1 Like

Bhante @sujato if I send you the JSON file that maps suttas to URLs is that something you might upload to bilara-data?

Looks like this:

{
“url”: “https://raw.githubusercontent.com/suttacentral/bilara-data/published/translation/en/sujato/sutta/kn/ud/vagga7/ud7.10_translation-en-sujato.json”,
“sutta”: “ud7.10”
}

1 Like