Skip to content

Commit

Permalink
total overhaul and fixed problems with books beginning with a number
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenRaccoon23 committed Jan 31, 2015
1 parent 769cb0b commit ca97a84
Show file tree
Hide file tree
Showing 14 changed files with 641 additions and 457 deletions.
Binary file added .bbl.mybible
Binary file not shown.
Binary file added .data.go.swp
Binary file not shown.
Binary file added .display_linux.go.swp
Binary file not shown.
Binary file added .display_windows.go.swp
Binary file not shown.
Binary file added .main.go.swp
Binary file not shown.
Binary file added .parse.go.swp
Binary file not shown.
Binary file modified bgmysword
Binary file not shown.
451 changes: 0 additions & 451 deletions bgmysword.go

This file was deleted.

28 changes: 27 additions & 1 deletion data.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type BibleArchive struct {
}

var (
logger *log.Logger
db *sql.DB
tx *sql.Tx
sqlStmtInsBible string = `insert into Bible values(?,?,?,?)`
Expand Down Expand Up @@ -90,7 +91,32 @@ var (
}
)

func genBible() {
func GenLog() (logFile *os.File) {
var err error
fileName := "bgmysword.log"
if _, err = os.Stat(fileName); err == nil {
os.Remove(fileName)
printRemovedFile(fileName)
}
logFile, err = os.OpenFile(fileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
return
}
logger = log.New(logFile, "logger: ", log.Lshortfile)
return
}

func CloseLog(logFile *os.File) {
logFile.Close()
}

func Log(s ...interface{}) {
if logMe {
logger.Print(s...)
}
}

func GenModule() {
ext := ".bbl.mybible"
fileName := str([]string{translation, ext})
if _, err := os.Stat(fileName); err == nil {
Expand Down
12 changes: 12 additions & 0 deletions display_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ func ColorUnset() {
color.Unset()
}

func Exit() {
os.Exit(0)
}

func printHelp() {
defer Exit()
defer ColorUnset()
BGreen.Printf(
"How to use:\n bgmysword <translation>\nExample:\n bgmysword KJV\n",
)
}

func ImgSword() {
/* ,
//
Expand Down
11 changes: 11 additions & 0 deletions display_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ func ImgINRI() {
PrintSlice(image)
}

func Exit() {
os.Exit(0)
}

func printHelp() {
defer Exit()
fmt.Printf(
"How to use:\n bgmysword <translation>\nExample:\n bgmysword KJV\n",
)
}

func PrintSlice(sl []string) {
for _, st := range sl {
PrintCenterLines(st)
Expand Down
19 changes: 14 additions & 5 deletions format.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,39 @@ var (
buffer bytes.Buffer
)

func str(slice []string) string {
func str(slice []string) (concatenated string) {
for _, s := range slice {
buffer.WriteString(s)
}
concatenated := buffer.String()
concatenated = buffer.String()
buffer.Reset()
return concatenated
return
}

func slc(args ...string) []string {
return args
}

func combine(args ...string) string {
func concat(args ...string) string {
return str(args)
}

func IsNotEmpty(s string) bool {
switch s {
case "":
return false
default:
return true
}
}

func appendCombine(slice []string, args ...string) (combined string) {
appendedSlice := append(slice, args...)
combined = str(appendedSlice)
return
}

func strLast(s string) string {
func lastLetter(s string) string {
last := len(s) - 1
return string([]rune(s)[last])
}
Expand Down
109 changes: 109 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package main

import (
"fmt"
//"github.com/PuerkitoBio/goquery"
//"log"
"os"
"strconv"
"strings"
//"unicode"
//"github.com/mattn/go-sqlite3"
//"github.com/fatih/color"
)

var (
translation string
transName string
BibleGatewayUrl string
logMe bool
//doc *goquery.Document
//db *sql.DB
//tx *sql.Tx
)

func init() {
defer ColorUnset()
ImgINRI()
numArgs := len(os.Args)
if numArgs > 1 {
firstArg := os.Args[1]
switch firstArg {
case "h", "-h", "help", "-help":
printHelp()
default:
translation = os.Args[1]
}
}
if numArgs > 2 {
logMe = true
}
GenBibleGatewayUrl()
CopyrightFetch()
}

func GenBibleGatewayUrl() {
preUrl := "https://www.biblegateway.com/passage/?version="
midUrl := "&search="
BibleGatewayUrl = concat(preUrl, translation, midUrl)
}

func GenFullUrl(book, chap string) (url string) {
url = concat(BibleGatewayUrl, book, "+", chap)
return
}

func main() {
defer ColorUnset()
if logMe {
logFile := GenLog()
defer CloseLog(logFile)
}
ImgSword()
GenModule()
progressTranslation()
defer db.Close()
defer tx.Commit()
bookLoop(Bible)
}

func bookLoop(Bible []BibleArchive) {
var bRange int
bRange = len(Bible)
for i := 0; i < bRange; i++ {
b := i + 1
title := strings.Replace(Bible[i].Book, "+", " ", -1)
titleSpaces := 30 - len(title)
titleSpacing := strings.Repeat(" ", titleSpaces)
var numSpacing string
if b < 10 {
numSpacing = " "
} else {
numSpacing = ""
}
progressBook(title, titleSpacing, numSpacing, b, bRange)
chapterLoop(Bible[i])
fmt.Println()
}
}

func chapterLoop(data BibleArchive) {
currentBook := strconv.Itoa(data.Index)
var cRange int = data.ChapterRange
for c := 1; c <= cRange; c++ {
progressChapter(c, cRange)
currentChapter := strconv.Itoa(c)
url := GenFullUrl(data.Book, currentChapter)
chapterText := Chapter.Parse(url)
Log(chapterText)
saveChapter(currentBook, currentChapter, chapterText)
}
}

func saveChapter(currentBook string, currentChapter string, chapterText []string) {
for i, s := range chapterText {
verseNumber := i + 1
verseText := s
sqlInsBible(currentBook, currentChapter, verseNumber, verseText)
}
}
Loading

0 comments on commit ca97a84

Please sign in to comment.