helperfuncties naar internal/util (2)

This commit is contained in:
Peter Kleiweg
2026-05-24 16:29:56 +02:00
parent 75832c3132
commit fcad105a75
14 changed files with 37 additions and 125 deletions

View File

@@ -9,5 +9,5 @@ xml2txt: cmd/xml2txt/*.go ../internal/util/*.go
metadata: cmd/metadata/*.go metadata: cmd/metadata/*.go
go build -o $@ $^ go build -o $@ $^
at5: cmd/at5/*.go at5: cmd/at5/*.go ../internal/util/*.go
go build -o $@ $^ go build -o $@ $<

View File

@@ -3,13 +3,14 @@ package main
import ( import (
e "codeberg.org/pebbe/errors" e "codeberg.org/pebbe/errors"
u "git.web.rug.nl/p209327/nlnieuws/internal/util"
"encoding/xml" "encoding/xml"
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
"path/filepath"
"strings" "strings"
"time" "time"
) )
@@ -46,7 +47,7 @@ func main() {
}() }()
myLock := "/net/corpora/nlnieuws/AT5/lock" myLock := "/net/corpora/nlnieuws/AT5/lock"
mkLock(myLock) u.MkLock(myLock)
defer func() { defer func() {
_ = os.Remove(myLock) _ = os.Remove(myLock)
}() }()
@@ -110,16 +111,3 @@ func main() {
}() }()
} }
} }
func mkLock(filename string) {
pid := os.Getpid()
link := fmt.Sprintf("%s.%d", filepath.Base(filename), pid)
p(os.Symlink(link, filename))
name, err := os.Readlink(filename)
p(err)
if name != link {
p(fmt.Errorf("wrong lock name %q, should be %q", name, link))
}
}

View File

@@ -9,5 +9,5 @@ json2txt: cmd/json2txt/*.go ../internal/util/*.go
metadata: cmd/metadata/*.go metadata: cmd/metadata/*.go
go build -o $@ $^ go build -o $@ $^
nos: cmd/nos/*.go nos: cmd/nos/*.go ../internal/util/*.go
go build -o $@ $^ go build -o $@ $<

View File

@@ -3,6 +3,8 @@ package main
import ( import (
e "codeberg.org/pebbe/errors" e "codeberg.org/pebbe/errors"
u "git.web.rug.nl/p209327/nlnieuws/internal/util"
"encoding/xml" "encoding/xml"
"fmt" "fmt"
"html" "html"
@@ -10,7 +12,6 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
"path/filepath"
"strings" "strings"
"time" "time"
) )
@@ -62,7 +63,7 @@ func main() {
}() }()
myLock := "/net/corpora/nlnieuws/NOS/lock" myLock := "/net/corpora/nlnieuws/NOS/lock"
mkLock(myLock) u.MkLock(myLock)
defer func() { defer func() {
_ = os.Remove(myLock) _ = os.Remove(myLock)
}() }()
@@ -194,16 +195,3 @@ func doArticle(filename string, url string, timestamp time.Time, needUpdate bool
p(os.Chtimes(filename+".json", timestamp, timestamp)) p(os.Chtimes(filename+".json", timestamp, timestamp))
return true return true
} }
func mkLock(filename string) {
pid := os.Getpid()
link := fmt.Sprintf("%s.%d", filepath.Base(filename), pid)
p(os.Symlink(link, filename))
name, err := os.Readlink(filename)
p(err)
if name != link {
p(fmt.Errorf("wrong lock name %q, should be %q", name, link))
}
}

View File

@@ -5,5 +5,5 @@ all: \
metadata: cmd/metadata/*.go metadata: cmd/metadata/*.go
go build -o $@ $^ go build -o $@ $^
nu: cmd/nu/*.go nu: cmd/nu/*.go ../internal/util/*.go
go build -o $@ $^ go build -o $@ $<

View File

@@ -3,6 +3,8 @@ package main
import ( import (
e "codeberg.org/pebbe/errors" e "codeberg.org/pebbe/errors"
u "git.web.rug.nl/p209327/nlnieuws/internal/util"
"bytes" "bytes"
"encoding/json" "encoding/json"
"encoding/xml" "encoding/xml"
@@ -12,7 +14,6 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
"path/filepath"
"strings" "strings"
"time" "time"
) )
@@ -73,7 +74,7 @@ func main() {
}() }()
myLock := "/net/corpora/nlnieuws/NU/lock" myLock := "/net/corpora/nlnieuws/NU/lock"
mkLock(myLock) u.MkLock(myLock)
defer func() { defer func() {
_ = os.Remove(myLock) _ = os.Remove(myLock)
}() }()
@@ -226,7 +227,7 @@ func doArticle(filename string, url string, timestamp time.Time, needUpdate bool
// text bevat kopjes zonder punt aan het eind // text bevat kopjes zonder punt aan het eind
lines := strings.Split(text, "\n") lines := strings.Split(text, "\n")
for i, line := range lines { for i, line := range lines {
line = fixSpace(line) line = u.FixSpace(line)
n := len(line) n := len(line)
if n > 0 { if n > 0 {
if strings.ContainsAny(line[n-1:], ".!?") { if strings.ContainsAny(line[n-1:], ".!?") {
@@ -249,7 +250,7 @@ func doArticle(filename string, url string, timestamp time.Time, needUpdate bool
p(fmt.Fprintln(fp, "##META text tag =")) p(fmt.Fprintln(fp, "##META text tag ="))
} else { } else {
for _, tag := range tags { for _, tag := range tags {
p(fmt.Fprintf(fp, "##META text tag = %s\n", fixSpace(tag))) p(fmt.Fprintf(fp, "##META text tag = %s\n", u.FixSpace(tag)))
} }
} }
p(fp.WriteString(text)) p(fp.WriteString(text))
@@ -259,20 +260,3 @@ func doArticle(filename string, url string, timestamp time.Time, needUpdate bool
return true return true
} }
func fixSpace(s string) string {
return strings.Join(strings.Fields(s), " ")
}
func mkLock(filename string) {
pid := os.Getpid()
link := fmt.Sprintf("%s.%d", filepath.Base(filename), pid)
p(os.Symlink(link, filename))
name, err := os.Readlink(filename)
p(err)
if name != link {
p(fmt.Errorf("wrong lock name %q, should be %q", name, link))
}
}

View File

@@ -9,5 +9,5 @@ xml2txt: cmd/xml2txt/*.go ../internal/util/*.go
metadata: cmd/metadata/*.go metadata: cmd/metadata/*.go
go build -o $@ $^ go build -o $@ $^
oog: cmd/oog/*.go oog: cmd/oog/*.go ../internal/util/*.go
go build -o $@ $^ go build -o $@ $<

View File

@@ -3,13 +3,14 @@ package main
import ( import (
e "codeberg.org/pebbe/errors" e "codeberg.org/pebbe/errors"
u "git.web.rug.nl/p209327/nlnieuws/internal/util"
"encoding/xml" "encoding/xml"
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
"path/filepath"
"strings" "strings"
"time" "time"
) )
@@ -46,7 +47,7 @@ func main() {
}() }()
myLock := "/net/corpora/nlnieuws/Oog/lock" myLock := "/net/corpora/nlnieuws/Oog/lock"
mkLock(myLock) u.MkLock(myLock)
defer func() { defer func() {
_ = os.Remove(myLock) _ = os.Remove(myLock)
}() }()
@@ -111,16 +112,3 @@ func main() {
} }
} }
func mkLock(filename string) {
pid := os.Getpid()
link := fmt.Sprintf("%s.%d", filepath.Base(filename), pid)
p(os.Symlink(link, filename))
name, err := os.Readlink(filename)
p(err)
if name != link {
p(fmt.Errorf("wrong lock name %q, should be %q", name, link))
}
}

View File

@@ -9,5 +9,5 @@ xml2txt: cmd/xml2txt/*.go ../internal/util/*.go
metadata: cmd/metadata/*.go metadata: cmd/metadata/*.go
go build -o $@ $^ go build -o $@ $^
ro: cmd/ro/*.go ro: cmd/ro/*.go ../internal/util/*.go
go build -o $@ $^ go build -o $@ $<

View File

@@ -3,13 +3,14 @@ package main
import ( import (
e "codeberg.org/pebbe/errors" e "codeberg.org/pebbe/errors"
u "git.web.rug.nl/p209327/nlnieuws/internal/util"
"encoding/xml" "encoding/xml"
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
"path/filepath"
"strings" "strings"
"time" "time"
) )
@@ -46,7 +47,7 @@ func main() {
}() }()
myLock := "/net/corpora/nlnieuws/RO/lock" myLock := "/net/corpora/nlnieuws/RO/lock"
mkLock(myLock) u.MkLock(myLock)
defer func() { defer func() {
_ = os.Remove(myLock) _ = os.Remove(myLock)
}() }()
@@ -111,16 +112,3 @@ func main() {
} }
} }
func mkLock(filename string) {
pid := os.Getpid()
link := fmt.Sprintf("%s.%d", filepath.Base(filename), pid)
p(os.Symlink(link, filename))
name, err := os.Readlink(filename)
p(err)
if name != link {
p(fmt.Errorf("wrong lock name %q, should be %q", name, link))
}
}

View File

@@ -9,5 +9,5 @@ xml2txt: cmd/xml2txt/*.go ../internal/util/*.go
metadata: cmd/metadata/*.go metadata: cmd/metadata/*.go
go build -o $@ $^ go build -o $@ $^
sargasso: cmd/sargasso/*.go sargasso: cmd/sargasso/*.go ../internal/util/*.go
go build -o $@ $^ go build -o $@ $<

View File

@@ -3,13 +3,14 @@ package main
import ( import (
e "codeberg.org/pebbe/errors" e "codeberg.org/pebbe/errors"
u "git.web.rug.nl/p209327/nlnieuws/internal/util"
"encoding/xml" "encoding/xml"
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
"path/filepath"
"strings" "strings"
"time" "time"
) )
@@ -46,7 +47,7 @@ func main() {
}() }()
myLock := "/net/corpora/nlnieuws/Sargasso/lock" myLock := "/net/corpora/nlnieuws/Sargasso/lock"
mkLock(myLock) u.MkLock(myLock)
defer func() { defer func() {
_ = os.Remove(myLock) _ = os.Remove(myLock)
}() }()
@@ -111,16 +112,3 @@ func main() {
} }
} }
func mkLock(filename string) {
pid := os.Getpid()
link := fmt.Sprintf("%s.%d", filepath.Base(filename), pid)
p(os.Symlink(link, filename))
name, err := os.Readlink(filename)
p(err)
if name != link {
p(fmt.Errorf("wrong lock name %q, should be %q", name, link))
}
}

View File

@@ -9,5 +9,5 @@ xml2txt: cmd/xml2txt/*.go ../internal/util/*.go
metadata: cmd/metadata/*.go metadata: cmd/metadata/*.go
go build -o $@ $^ go build -o $@ $^
tzum: cmd/tzum/*.go tzum: cmd/tzum/*.go ../internal/util/*.go
go build -o $@ $^ go build -o $@ $<

View File

@@ -3,13 +3,14 @@ package main
import ( import (
e "codeberg.org/pebbe/errors" e "codeberg.org/pebbe/errors"
u "git.web.rug.nl/p209327/nlnieuws/internal/util"
"encoding/xml" "encoding/xml"
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
"path/filepath"
"strings" "strings"
"time" "time"
) )
@@ -46,7 +47,7 @@ func main() {
}() }()
myLock := "/net/corpora/nlnieuws/Tzum/lock" myLock := "/net/corpora/nlnieuws/Tzum/lock"
mkLock(myLock) u.MkLock(myLock)
defer func() { defer func() {
_ = os.Remove(myLock) _ = os.Remove(myLock)
}() }()
@@ -111,16 +112,3 @@ func main() {
} }
} }
func mkLock(filename string) {
pid := os.Getpid()
link := fmt.Sprintf("%s.%d", filepath.Base(filename), pid)
p(os.Symlink(link, filename))
name, err := os.Readlink(filename)
p(err)
if name != link {
p(fmt.Errorf("wrong lock name %q, should be %q", name, link))
}
}