From aee9952b8af678b0c637e645ef2d496ed942ddd7 Mon Sep 17 00:00:00 2001 From: Andreas Schulte Date: Mon, 2 Oct 2023 23:49:37 +0200 Subject: [PATCH] Migrated to git.0x0001f346.de/andreas/utils --- imdb-scraper.go | 19 +++++-------------- imdb-scraper_test.go | 17 ----------------- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/imdb-scraper.go b/imdb-scraper.go index 2c4c106..26ced10 100644 --- a/imdb-scraper.go +++ b/imdb-scraper.go @@ -5,10 +5,10 @@ import ( "errors" "fmt" "net/url" - "strconv" "strings" "unicode" + "git.0x0001f346.de/andreas/utils" "github.com/gocolly/colly" ) @@ -108,22 +108,13 @@ func convertIMDbRuntimeIntoMinutes(s string) int64 { if strings.Contains(s, "H") { if strings.Contains(s, "M") { ss := strings.Split(strings.Replace(s, "M", "", -1), "H") - return (convertStringToIntOrZeroOnError(ss[0]) * 60) + convertStringToIntOrZeroOnError(ss[1]) + return (utils.ConvertStringToIntOrZeroOnError(ss[0]) * 60) + utils.ConvertStringToIntOrZeroOnError(ss[1]) } - return convertStringToIntOrZeroOnError(strings.Replace(s, "H", "", -1)) * 60 + return utils.ConvertStringToIntOrZeroOnError(strings.Replace(s, "H", "", -1)) * 60 } - return convertStringToIntOrZeroOnError(strings.Replace(s, "M", "", -1)) -} - -func convertStringToIntOrZeroOnError(s string) int64 { - i, err := strconv.ParseInt(s, 10, 64) - if err != nil { - return 0 - } - - return i + return utils.ConvertStringToIntOrZeroOnError(strings.Replace(s, "M", "", -1)) } func extractYearFromIMDbTitle(s string, title string) int64 { @@ -138,7 +129,7 @@ func extractYearFromIMDbTitle(s string, title string) int64 { continue } - year := convertStringToIntOrZeroOnError( + year := utils.ConvertStringToIntOrZeroOnError( strings.Replace( strings.Replace(chunck, "(", "", -1), ")", diff --git a/imdb-scraper_test.go b/imdb-scraper_test.go index 580b2ad..ec8103b 100644 --- a/imdb-scraper_test.go +++ b/imdb-scraper_test.go @@ -31,23 +31,6 @@ func TestConvertIMDbRuntimeIntoMinutes(t *testing.T) { } } -func TestConvertStringToIntOrZeroOnError(t *testing.T) { - data := map[string]int64{ - "-13": -13, - "0": 0, - "13": 13, - "Son Goku": 0, - "1f346": 0, - } - - for d, expectedResult := range data { - result := convertStringToIntOrZeroOnError(d) - if result != expectedResult { - t.Errorf("\ngot: %d\nwanted: %d\nfor: %q", result, expectedResult, d) - } - } -} - func TestGetIMDbIDFromQuery(t *testing.T) { data := map[string]string{ "tt2861424": "tt2861424",