Skip to content

Commit

Permalink
fixed a few bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenRaccoon23 committed Feb 2, 2015
1 parent ca97a84 commit f01ff01
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 119 deletions.
Binary file removed .bbl.mybible
Binary file not shown.
Binary file removed .data.go.swp
Binary file not shown.
Binary file removed .display_linux.go.swp
Binary file not shown.
Binary file removed .display_windows.go.swp
Binary file not shown.
Binary file removed .main.go.swp
Binary file not shown.
Binary file removed .parse.go.swp
Binary file not shown.
32 changes: 22 additions & 10 deletions data.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package main

import (
"database/sql"
_ "github.com/mattn/go-sqlite3"
"log"
"os"
"time"

_ "github.com/mattn/go-sqlite3"
//"github.com/PuerkitoBio/goquery"
//"github.com/fatih/color"
)
Expand All @@ -18,6 +19,7 @@ type BibleArchive struct {

var (
logger *log.Logger
logFile *os.File
db *sql.DB
tx *sql.Tx
sqlStmtInsBible string = `insert into Bible values(?,?,?,?)`
Expand Down Expand Up @@ -91,28 +93,33 @@ var (
}
)

func GenLog() (logFile *os.File) {
func GenLog() {
var err error
fileName := "bgmysword.log"
if _, err = os.Stat(fileName); err == nil {
os.Remove(fileName)
printRemovedFile(fileName)
logFileName := "bgmysword.log"

if _, err = os.Stat(logFileName); err == nil {
os.Remove(logFileName)
printRemovedFile(logFileName)
}
logFile, err = os.OpenFile(fileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)

logFile, err = os.OpenFile(logFileName, 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 CloseLog() {
if logMe {
logFile.Close()
}
}

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

Expand Down Expand Up @@ -149,6 +156,11 @@ func GenModule() {
sqlInsDetails()
}

func CloseModule() {
tx.Commit()
db.Close()
}

func sqlCrt(sqlStmt string) {
_, err := db.Exec(sqlStmt)
if err != nil {
Expand Down
21 changes: 18 additions & 3 deletions display_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package main
import (
"bufio"
"fmt"
"github.com/fatih/color"
"os"
"strings"

"github.com/fatih/color"
//"github.com/PuerkitoBio/goquery"
//"github.com/mattn/go-sqlite3"
)
Expand Down Expand Up @@ -172,9 +173,23 @@ func progressTranslation() {
BWhite.Println(transName)
}

func progressBook(title, titleSpacing, numSpacing string, currNum, totalNum int) {
func progressBook(index int) {
var spacingNumber string = ""

book := Bible[index].Book
bookTitle := strings.Replace(book, "+", " ", -1)

numberOfSpaces := 30 - len(bookTitle)
spacingTitle := strings.Repeat(" ", numberOfSpaces)

bookNumber := index + 1

if bookNumber < 10 {
spacingNumber = " "
}

BGreen.Printf("\r=>%v%v%v%d/%d\n",
title, titleSpacing, numSpacing, currNum, totalNum)
bookTitle, spacingTitle, spacingNumber, bookNumber, 66)
}

func progressChapter(current, total int) {
Expand Down
20 changes: 17 additions & 3 deletions display_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func PrintCenter(t string) {
}

func printRemovedFile(fileName string) {
Black.Println("Removed", fileName)
fmt.Println("Removed", fileName)
}

func Break(s string) {
Expand All @@ -119,9 +119,23 @@ func progressTranslation() {
fmt.Println(transName)
}

func progressBook(title, titleSpacing, numSpacing string, currNum, totalNum int) {
func progressBook(index int) {
var spacingNumber string = ""

book := Bible[index].Book
bookTitle := strings.Replace(book, "+", " ", -1)

numberOfSpaces := 30 - len(bookTitle)
spacingTitle := strings.Repeat(" ", numberOfSpaces)

bookNumber := index + 1

if bookNumber < 10 {
spacingNumber = " "
}

fmt.Printf("\r=>%v%v%v%d/%d\n",
title, titleSpacing, numSpacing, currNum, totalNum)
bookTitle, spacingTitle, spacingNumber, bookNumber, 66)
}

func progressChapter(current, total int) {
Expand Down
Binary file added linux/bgmysword
Binary file not shown.
63 changes: 26 additions & 37 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ package main

import (
"fmt"
//"github.com/PuerkitoBio/goquery"
//"log"
"os"
"strconv"
"strings"
//"unicode"
//"github.com/PuerkitoBio/goquery"
//"github.com/mattn/go-sqlite3"
//"github.com/fatih/color"
)
Expand All @@ -17,34 +14,39 @@ var (
transName string
BibleGatewayUrl string
logMe bool
//doc *goquery.Document
//db *sql.DB
//tx *sql.Tx
)

func init() {
defer ColorUnset()
ImgINRI()
AnalyseArgs()
GenBibleGatewayUrl()
CopyrightFetch()
}

func AnalyseArgs() {
numArgs := len(os.Args)
if numArgs > 1 {
firstArg := os.Args[1]
switch firstArg {
switch os.Args[1] {
case "h", "-h", "help", "-help":
printHelp()
default:
translation = os.Args[1]
}

}
if numArgs > 2 {
logMe = true
GenLog()
}
GenBibleGatewayUrl()
CopyrightFetch()
}

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

BibleGatewayUrl = concat(preUrl, translation, midUrl)
}

Expand All @@ -54,56 +56,43 @@ func GenFullUrl(book, chap string) (url string) {
}

func main() {
defer CloseLog()
defer ColorUnset()
if logMe {
logFile := GenLog()
defer CloseLog(logFile)
}
ImgSword()
GenModule()
defer CloseModule()
progressTranslation()
defer db.Close()
defer tx.Commit()
bookLoop(Bible)
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])
func BookLoop(Bible []BibleArchive) {
for i := 0; i < 66; i++ {
progressBook(i)
ChapterLoop(Bible[i])
fmt.Println()
}
}

func chapterLoop(data BibleArchive) {
func ChapterLoop(data BibleArchive) {
currentBook := strconv.Itoa(data.Index)
var cRange int = data.ChapterRange
cRange := 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)

SaveChapter(currentBook, currentChapter, chapterText)
}
}

func saveChapter(currentBook string, currentChapter string, chapterText []string) {
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 f01ff01

Please sign in to comment.