cleanup predb

This commit is contained in:
lyx0 2023-12-17 17:46:41 +01:00
parent 146c04be0c
commit 2ce6c8f0d9

View file

@ -3,7 +3,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"net/url" "net/url"
"strings" "strings"
@ -36,22 +36,21 @@ func (app *application) PreDBLatest() string {
resp, err := http.Get(baseUrl) resp, err := http.Get(baseUrl)
if err != nil { if err != nil {
app.Log.Error(err) app.Log.Error(err)
return "Something went wrong FeelsBadMan"
} }
app.Log.Info(resp)
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
app.Log.Error(err) app.Log.Error(err)
return "Something went wrong FeelsBadMan"
} }
app.Log.Info(body)
var release latestFullResult var release latestFullResult
_ = json.Unmarshal([]byte(body), &release) _ = json.Unmarshal([]byte(body), &release)
var ts []string var ts []string
app.Log.Info(release)
for i := 0; i < release.Results; i++ { for i := 0; i < release.Results; i++ {
t := fmt.Sprintf("ID: %v\nRelease timestamp: %v\nRelease: %v\nSection: %v\nFiles: %v\nSize: %v\nStatus: %v\nReason: %v\nRelease group: %v\nRelease genre: %v\npredb.net: %v\nNFO URL: %v\nNFO Image URL: %v\n\n", t := fmt.Sprintf("ID: %v\nRelease timestamp: %v\nRelease: %v\nSection: %v\nFiles: %v\nSize: %v\nStatus: %v\nReason: %v\nRelease group: %v\nRelease genre: %v\npredb.net: %v\nNFO URL: %v\nNFO Image URL: %v\n\n",
release.Data[i].ID, release.Data[i].ID,
@ -72,12 +71,6 @@ func (app *application) PreDBLatest() string {
} }
// reply, err := app.uploadPaste(strings.Join(ts, ""))
// if err != nil {
// app.Log.Errorw("Error trying to retrieve all timers from database", err)
// return ""
// }
reply := app.YafUploadString(strings.Join(ts, "")) reply := app.YafUploadString(strings.Join(ts, ""))
if err != nil { if err != nil {
app.Log.Errorw("Error trying to retrieve all timers from database", err) app.Log.Errorw("Error trying to retrieve all timers from database", err)
@ -113,22 +106,21 @@ func (app *application) PreDBSearch(title string) string {
resp, err := http.Get(escaped) resp, err := http.Get(escaped)
if err != nil { if err != nil {
app.Log.Error(err) app.Log.Error(err)
return "Something went wrong FeelsBadMan"
} }
app.Log.Info(resp)
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
app.Log.Error(err) app.Log.Error(err)
return "Something went wrong FeelsBadMan"
} }
app.Log.Info(body)
var release searchFullResult var release searchFullResult
_ = json.Unmarshal([]byte(body), &release) _ = json.Unmarshal([]byte(body), &release)
var ts []string var ts []string
app.Log.Info(release)
for i := 0; i < release.Results; i++ { for i := 0; i < release.Results; i++ {
t := fmt.Sprintf("ID: %v\nRelease timestamp: %v\nRelease: %v\nSection: %v\nFiles: %v\nSize: %v\nStatus: %v\nReason: %v\nRelease group: %v\nRelease genre: %v\npredb.net: %v\nNFO URL: %v\nNFO Image URL: %v\n\n", t := fmt.Sprintf("ID: %v\nRelease timestamp: %v\nRelease: %v\nSection: %v\nFiles: %v\nSize: %v\nStatus: %v\nReason: %v\nRelease group: %v\nRelease genre: %v\npredb.net: %v\nNFO URL: %v\nNFO Image URL: %v\n\n",
release.Data[i].ID, release.Data[i].ID,
@ -149,12 +141,6 @@ func (app *application) PreDBSearch(title string) string {
} }
// reply, err := app.uploadPaste(strings.Join(ts, ""))
// if err != nil {
// app.Log.Errorw("Error trying to retrieve all timers from database", err)
// return ""
// }
reply := app.YafUploadString(strings.Join(ts, "")) reply := app.YafUploadString(strings.Join(ts, ""))
if err != nil { if err != nil {
app.Log.Errorw("Error trying to retrieve all timers from database", err) app.Log.Errorw("Error trying to retrieve all timers from database", err)
@ -169,22 +155,21 @@ func (app *application) PreDBGroup(group string) string {
resp, err := http.Get(escaped) resp, err := http.Get(escaped)
if err != nil { if err != nil {
app.Log.Error(err) app.Log.Error(err)
return "Something went wrong FeelsBadMan"
} }
app.Log.Info(resp)
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
app.Log.Error(err) app.Log.Error(err)
return "Something went wrong FeelsBadMan"
} }
app.Log.Info(body)
var release searchFullResult var release searchFullResult
_ = json.Unmarshal([]byte(body), &release) _ = json.Unmarshal([]byte(body), &release)
var ts []string var ts []string
app.Log.Info(release)
for i := 0; i < release.Results; i++ { for i := 0; i < release.Results; i++ {
t := fmt.Sprintf("ID: %v\nRelease timestamp: %v\nRelease: %v\nSection: %v\nFiles: %v\nSize: %v\nStatus: %v\nReason: %v\nRelease group: %v\nRelease genre: %v\npredb.net: %v\nNFO URL: %v\nNFO Image URL: %v\n\n", t := fmt.Sprintf("ID: %v\nRelease timestamp: %v\nRelease: %v\nSection: %v\nFiles: %v\nSize: %v\nStatus: %v\nReason: %v\nRelease group: %v\nRelease genre: %v\npredb.net: %v\nNFO URL: %v\nNFO Image URL: %v\n\n",
release.Data[i].ID, release.Data[i].ID,
@ -205,18 +190,10 @@ func (app *application) PreDBGroup(group string) string {
} }
// reply, err := app.uploadPaste(strings.Join(ts, ""))
// if err != nil {
// app.Log.Errorw("Error trying to retrieve all timers from database", err)
// return ""
// }
reply := app.YafUploadString(strings.Join(ts, "")) reply := app.YafUploadString(strings.Join(ts, ""))
if err != nil { if err != nil {
app.Log.Errorw("Error trying to retrieve all timers from database", err) app.Log.Errorw("Error trying to retrieve all timers from database", err)
return "" return "Something went wrong FeelsBadMan"
} }
return reply return reply
return reply
} }