<commit_before>// Brief: Scripture API
// Primary responsibility: Query calls for Scripture functionality

package main

import (
	"fmt"
	"log"
	"net/url"

	bmul "github.com/julwrites/BotMultiplexer"
)

var passageQuery string = "http://www.biblegateway.com/passage/?search=%s&version=%s"

func GetReference(ref string, env *bmul.SessionData) string {
	query := fmt.Sprintf(passageQuery, ref, GetUserConfig(&env.User).Version)

	log.Printf("Query String: %s", query)

	doc := GetHtml(query)

	if doc == nil {
		log.Fatalf("Error getting reference")
		return ""
	}

	foundRef, err := FindByClass(doc, "bcv")
	if err != nil {
		log.Fatalf("Error in Finding of Reference: %v", err)
	}

	return foundRef.FirstChild.Data
}

func GetPassage(ref string, env *bmul.SessionData) string {
	query := fmt.Sprintf(passageQuery, ref, GetUserConfig(&env.User).Version)
	query = url.QueryEscape(query)

	doc := GetHtml(query)

	if doc == nil {
		log.Fatalf("Error getting reference")
		return ""
	}

	foundRef, err := FindByClass(doc, "passage-text")
	if err != nil {
		log.Fatalf("Error in Finding of Reference: %v", err)
	}

	return foundRef.Data
}

func GetBiblePassage(env *bmul.SessionData) bool {
	if len(env.Msg.Message) > 0 {

		ref := GetReference(env.Msg.Message, env)

		if len(ref) > 0 {
			env.Res.Message = GetPassage(ref, env)

			return true
		}
	}

	return false
}<commit_msg>Restructuring parsing of html so that we only get once<commit_after>// Brief: Scripture API
// Primary responsibility: Query calls for Scripture functionality

package main

import (
	"fmt"
	"log"

	bmul "github.com/julwrites/BotMultiplexer"
	"golang.org/x/net/html"
)

var passageQuery string = "http://www.biblegateway.com/passage/?search=%s&version=%s"

func Query(ref string, env *bmul.SessionData) *html.Node {
	query := fmt.Sprintf(passageQuery, ref, GetUserConfig(&env.User).Version)

	log.Printf("Query String: %s", query)

	doc := GetHtml(query)

	if doc == nil {
		log.Fatalf("Error getting html")
		return nil
	}

	return doc
}

func GetReference(doc *html.Node, env *bmul.SessionData) string {
	foundRef, err := FindByClass(doc, "bcv")
	if err != nil {
		log.Fatalf("Error parsing for reference: %v", err)
	}

	return foundRef.FirstChild.Data
}

func GetPassage(doc *html.Node, env *bmul.SessionData) string {
	passage, err := FindByClass(doc, "passage-text")
	if err != nil {
		log.Fatalf("Error parsing for passage: %v", err)
	}

	return fmt.Sprintf("I currently can't parse a passage but here's what I got so far: %s", passage.Data)
}

func GetBiblePassage(env *bmul.SessionData) bool {
	if len(env.Msg.Message) > 0 {

		doc := Query(env.Msg.Message, env)
		ref := GetReference(doc, env)

		if len(ref) > 0 {
			env.Res.Message = GetPassage(doc, env)

			return true
		}
	}

	return false
}
{'fraction_non_alphanumeric': 0.1387491013659238, 'fraction_numerical': 0.0014378145219266715, 'mean_word_length': 4.163265306122449, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2152608', 'n_tokens_mistral': 1044, 'n_tokens_neox': 978, 'n_words': 256}