Skip to content

Commit

Permalink
update download tipitaka
Browse files Browse the repository at this point in the history
  • Loading branch information
siongui committed Oct 23, 2023
1 parent 7081cfd commit 582325b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions tpkutil/downloadtpk.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,29 +70,34 @@ func GetAllXml(urlPrefix, xmlSrc, dir string, overwrite bool) (err error) {
}

// DownloadTipitaka downloads all Tipiṭaka XMLs from
// https://www.tipitaka.org/romn/ to dir. This method will overwrite existing
// XMLs if overwrite set to true.
func DownloadTipitaka(dir string, overwrite bool) (err error) {
// https://www.tipitaka.org/{{script}}/ to {{dir}}. This method will overwrite
// existing XMLs if overwrite set to true.
func DownloadTipitaka(script, dir string, overwrite bool) (err error) {
// Python version
// https://github.com/siongui/pali/blob/master/tipitaka/setup/init1getTocs.py

// observation:
// 1. All meaningful node has attribute 'text'
// 2. node with 'action' attribute is leaf
urlPrefix := "https://tipitaka.org/romn/"
urlPrefix := "https://tipitaka.org/" + script + "/"
rootTocXmlSrc := "tipitaka_toc.xml"

err = GetAllXml(urlPrefix, rootTocXmlSrc, dir, overwrite)
if err != nil {
return
}

xsl := "cscd/tipitaka-latn.xsl"
// The XSL and CSS filename for romn script is *latn*, not *romn*
if script == "romn" {
script = "latn"
}

xsl := "cscd/tipitaka-" + script + ".xsl"
err = util.CheckDownload(urlPrefix+xsl, path.Join(dir, xsl), overwrite)
if err != nil {
return
}
css := "cscd/tipitaka-latn.css"
css := "cscd/tipitaka-" + script + ".css"
err = util.CheckDownload(urlPrefix+css, path.Join(dir, css), overwrite)
return
}
2 changes: 1 addition & 1 deletion tpkutil/downloadtpk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func TestDownloadTipitaka(t *testing.T) {
//err := DownloadTipitaka("/tmp/tpkxml/", false)
//err := DownloadTipitaka("romn", "/tmp/tpkxml/", false)
err := GetAllXml("https://tipitaka.org/romn/", "cscd/vin01m.mul.toc.xml", "/tmp/tpkxml/", false)
if err != nil {
t.Error(err)
Expand Down

0 comments on commit 582325b

Please sign in to comment.