summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorJoop Kiefte <ikojba@gmail.com>2021-06-07 19:54:15 +0100
committerJoop Kiefte <ikojba@gmail.com>2021-06-07 19:54:15 +0100
commit7a6efffc98fdda8e3b07829900b5b8926e791437 (patch)
tree582431eeb9e0f0d321d6056e5c1b8fd61af350f7 /main.go
Initial commit
Diffstat (limited to 'main.go')
-rw-r--r--main.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..95024ab
--- /dev/null
+++ b/main.go
@@ -0,0 +1,57 @@
+package main
+
+import (
+ "database/sql"
+ _ "modernc.org/sqlite"
+
+ "text/template"
+)
+
+var opml = `<?xml version="1.0" encoding="utf-8"?>
+<opml version="2.0">
+ <head>
+ <title>Bahá'í Prayers</title>
+ </head>
+ <body>
+ <outline text="Prayers">
+{{range .}}
+ <outline text="{{with .Phelps}}#{{.}}{{else}}Unmatched prayer{{.ID}}{{end}} #{{.Language}} #{{.Author}}">
+ <outline text="{{.Text}}"/>
+ </outline>
+{{end}}
+ </outline>
+ </body>
+</opml>`
+
+type Prayer struct{
+ Phelps string
+ ID string
+ Language string
+ Author string
+ Text string
+}
+
+func main() {
+ var prayers []Prayer
+ db := sql.Open("sqlite", "holywritings.db")
+ rows := db.Query("select id, phelps, author, language, text from writings;")
+ for rows.Next() {
+ var prayer Prayer
+ rows.Scan(&prayer.ID, &prayer.Phelps, &prayer.Author, &prayer.Language, &prayer.Text)
+ switch prayer.Author {
+ case "Báb":
+ prayer.Author = "bab"
+ case "`Abdu'l-Bahá":
+ prayer.Author = "abdulbaha"
+ case "Bahá'u'lláh":
+ prayer.Author = "bahaullah"
+ }
+ prayer.Text = template.HTMLEscapeString(prayer.Text)
+ prayers = append(prayers, prayer)
+ }
+
+ tmpl, err := template.New("opml").Parse(opml)
+ if err != nil { panic(err) }
+ err = tmpl.Execute(os.Stdout, prayers)
+ if err != nil { panic(err) }
+}