Skip to content

Commit

Permalink
Pass document to all scrape functions. (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
pdunnavant authored Sep 4, 2019
1 parent 3dd6600 commit d6eabf5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
1 change: 0 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package config

// Configuration holds all configuration for modem-scraper.
type Configuration struct {
ModemType string
IP string
PollSchedule string
MQTT MQTT
Expand Down
9 changes: 2 additions & 7 deletions scrape/connectionstatus.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package scrape

import "github.com/pdunnavant/modem-scraper/config"
import "github.com/PuerkitoBio/goquery"

// ConnectionStatus holds all info from /cmconnectionstatus.html.
type ConnectionStatus struct {
Expand All @@ -9,12 +9,7 @@ type ConnectionStatus struct {
UpstreamBondedChannels []UpstreamBondedChannel
}

func scrapeConnectionStatus(config config.Configuration) (*ConnectionStatus, error) {
doc, err := getDocumentFromURL(config.IP + "/cmconnectionstatus.html")
if err != nil {
return nil, err
}

func scrapeConnectionStatus(doc *goquery.Document) (*ConnectionStatus, error) {
connectionStatus := ConnectionStatus{
StartupProcedure: scrapeStartupProcedure(doc),
DownstreamBondedChannels: scrapeDownstreamBondedChannels(doc),
Expand Down
13 changes: 11 additions & 2 deletions scrape/scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,20 @@ import (

// Scrape scrapes data from the modem.
func Scrape(config config.Configuration) (*ModemInformation, error) {
connectionStatus, err := scrapeConnectionStatus(config)
doc, err := getDocumentFromURL(config.IP + "/cmconnectionstatus.html")
if err != nil {
return nil, err
}
softwareInformation, err := scrapeSoftwareInformation(config)
connectionStatus, err := scrapeConnectionStatus(doc)
if err != nil {
return nil, err
}

doc, err = getDocumentFromURL(config.IP + "/cmswinfo.html")
if err != nil {
return nil, err
}
softwareInformation, err := scrapeSoftwareInformation(doc)
if err != nil {
return nil, err
}
Expand Down
9 changes: 2 additions & 7 deletions scrape/softwareinformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"strconv"
"strings"

"github.com/pdunnavant/modem-scraper/config"
"github.com/PuerkitoBio/goquery"
)

// SoftwareInformation holds data pulled from the /cmswinfo.html page.
Expand All @@ -25,12 +25,7 @@ const macAddressSelector = "#bg3 > div.container > div.content > table:nth-child
const serialNumberSelector = "#bg3 > div.container > div.content > table:nth-child(2) > tbody > tr:nth-child(6) > td:nth-child(2)"
const uptimeSelector = "#bg3 > div.container > div.content > table:nth-child(5) > tbody > tr:nth-child(2) > td:nth-child(2)"

func scrapeSoftwareInformation(config config.Configuration) (*SoftwareInformation, error) {
doc, err := getDocumentFromURL(config.IP + "/cmswinfo.html")
if err != nil {
return nil, err
}

func scrapeSoftwareInformation(doc *goquery.Document) (*SoftwareInformation, error) {
uptimeString := doc.Find(uptimeSelector).Text()
uptimeMins := uptimeToMinutes(uptimeString)
softwareInformation := SoftwareInformation{
Expand Down

0 comments on commit d6eabf5

Please sign in to comment.