Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
One script to run them all
Browse files Browse the repository at this point in the history
  • Loading branch information
texadactyl committed Jul 7, 2024
1 parent 54f5f29 commit a613e4f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ module ppolls2024

go 1.21.4

require (
gonum.org/v1/plot v0.14.0
gopkg.in/yaml.v3 v3.0.1
modernc.org/sqlite v1.28.0
)

require (
git.sr.ht/~sbinet/gg v0.5.0 // indirect
github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b // indirect
Expand All @@ -22,16 +28,13 @@ require (
golang.org/x/text v0.12.0 // indirect
golang.org/x/tools v0.6.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gonum.org/v1/plot v0.14.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/uint128 v1.2.0 // indirect
modernc.org/cc/v3 v3.40.0 // indirect
modernc.org/ccgo/v3 v3.16.13 // indirect
modernc.org/libc v1.29.0 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.7.2 // indirect
modernc.org/opt v0.1.3 // indirect
modernc.org/sqlite v1.28.0 // indirect
modernc.org/strutil v1.1.3 // indirect
modernc.org/token v1.0.1 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ golang.org/x/image v0.11.0/go.mod h1:bglhjqbqVuEb9e9+eNR45Jfu7D+T4Qan+NhQk8Ck2P8
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand Down Expand Up @@ -79,6 +80,7 @@ golang.org/x/tools v0.0.0-20201124115921-2c860bdd6e78 h1:M8tBwCtWD/cZV9DZpFYRUga
golang.org/x/tools v0.0.0-20201124115921-2c860bdd6e78/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
7 changes: 4 additions & 3 deletions helpers/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func moveTempCSVToCurrentCSV(pathTemp, pathCurrent string) {
}
}

func Fetch(dirCsv, fileName, url, dirTemp string) {
func Fetch(dirCsv, fileName, url, dirTemp string) bool {

// Form the full path of the CSV file in the final directory and the temporary directory.
pathCurrentCSV := filepath.Join(dirCsv, fileName)
Expand Down Expand Up @@ -67,7 +67,7 @@ func Fetch(dirCsv, fileName, url, dirTemp string) {
log.Println("Fetch: No previous poll data.")
moveTempCSVToCurrentCSV(pathTempCSV, pathCurrentCSV)
log.Println("Fetch: End")
return
return true
}
cksumCurrent := crc32.ChecksumIEEE(fileBytes)

Expand All @@ -83,10 +83,11 @@ func Fetch(dirCsv, fileName, url, dirTemp string) {
log.Println("Fetch: Internet poll data has changed.")
moveTempCSVToCurrentCSV(pathTempCSV, pathCurrentCSV)
log.Println("Fetch: End")
return
return true
}

// ByeBye.
log.Println("Fetch: Internet poll data has not changed. Nothing to do.")
log.Println("Fetch: End")
return false
}
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ func main() {

// Fetch new data?
if glob.FlagFetch {
helpers.Fetch(glob.DirCsv, glob.LocalCsvFile, glob.InternetCsvFile, glob.DirTemp)
if !helpers.Fetch(glob.DirCsv, glob.LocalCsvFile, glob.InternetCsvFile, glob.DirTemp) {
os.Exit(1)
}
}

// Load newly-fetched data into the database?
Expand Down
13 changes: 13 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set -e

ppolls2024 -f
if [ $? -ne 0 ]; then
exit 1
fi

ppolls2024 -l

ppolls2024 -p

ppolls2024 -r ec

0 comments on commit a613e4f

Please sign in to comment.