Replace prazdnikisegodnyaru with celebratoday, small underhood fixes
- Replace prazdnikisegodnyaru with celebratoday as first is banned in Russia - Update .golangci.yml rule set - Megatons of fixes for linter - Update README.md
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// Package anekdotru implemets client for anekdot.ru service.
|
||||
package anekdotru
|
||||
|
||||
import (
|
||||
@@ -23,11 +24,7 @@ func APIClient(cfg *config.MyConfig) (string, error) {
|
||||
url = "https://www.anekdot.ru/rss/randomu.html"
|
||||
)
|
||||
|
||||
err := requests.
|
||||
URL(url).
|
||||
UserAgent(userAgent).
|
||||
ToBytesBuffer(&respBody).
|
||||
Fetch(ctx)
|
||||
err := requests.URL(url).UserAgent(userAgent).ToBytesBuffer(&respBody).Fetch(ctx)
|
||||
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to GET %s: %w", url, err)
|
||||
@@ -42,6 +39,7 @@ func APIClient(cfg *config.MyConfig) (string, error) {
|
||||
|
||||
if (len(aneks) >= 2) && (aneks[1] != "") {
|
||||
re = regexp.MustCompile(`'\);`)
|
||||
|
||||
a := re.Split(aneks[1], 2)
|
||||
|
||||
if (len(a) >= 2) && (a[0] != "") {
|
||||
@@ -51,7 +49,9 @@ func APIClient(cfg *config.MyConfig) (string, error) {
|
||||
anek = re.ReplaceAll(anek, []byte(`"`))
|
||||
|
||||
re = regexp.MustCompile(`\\"`)
|
||||
|
||||
anekJSON := re.ReplaceAll(anek, []byte(`"`))
|
||||
|
||||
anekJSON = bytes.ToValidUTF8(anekJSON, []byte{0xef, 0xbf, 0xbd})
|
||||
|
||||
var anekMap []string
|
||||
@@ -60,6 +60,7 @@ func APIClient(cfg *config.MyConfig) (string, error) {
|
||||
}
|
||||
|
||||
re = regexp.MustCompile(`<br>`)
|
||||
|
||||
answer := re.ReplaceAll([]byte(anekMap[0]), []byte("\n"))
|
||||
|
||||
return string(answer), nil
|
||||
|
||||
Reference in New Issue
Block a user