Skip to content

Commit

Permalink
Fix manga chapter number on semichapters
Browse files Browse the repository at this point in the history
  • Loading branch information
vaughnw128 committed Jul 7, 2024
1 parent 5c1936a commit ae3bdbd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions cmd/eternalpose/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Manga struct {
Title string `json:"title"`
Regex string `json:"regex"`
Users []string `json:"users"`
CurrentChapter int `json:"currentChapter"`
CurrentChapter float64 `json:"currentChapter"`
}

type Image struct {
Expand All @@ -44,7 +44,7 @@ var (
logger = slog.New(slog.NewTextHandler(os.Stdout, nil))
)

func updateChapter(title string, cNum int) {
func updateChapter(title string, cNum float64) {
// Update the chapter number in manga.json
var mangaData []Manga
jsonFile, _ := os.Open("manga.json")
Expand Down Expand Up @@ -129,7 +129,7 @@ func sendManga(title string, link string, users []string) {
logger.Info(fmt.Sprintf("Sending %s to webhook.", title))
resp, err := http.Post(webhookURL, "application/json", bytes.NewBuffer(jsonData))
if err != nil {
logger.Error("Unable to send JSON: ", err)
logger.Error(fmt.Sprintf("Unable to send JSON: %s", err))
}
defer func(Body io.ReadCloser) {
err := Body.Close()
Expand Down Expand Up @@ -167,7 +167,7 @@ func scrapeManga() {

//If it matches, get chapter number, send the manga, then update chapter
if matches != nil {
chapterNumber, _ := strconv.Atoi(matches[r.SubexpIndex("Chapter")])
chapterNumber, _ := strconv.ParseFloat(matches[r.SubexpIndex("Chapter")], 64)
if chapterNumber > manga.CurrentChapter {
sendManga(mangaTitle, mangaLink, manga.Users)
updateChapter(manga.Title, chapterNumber)
Expand Down Expand Up @@ -198,7 +198,7 @@ func main() {

_, err = s.NewJob(
gocron.CronJob(
"0 * * * *",
"* * * * *",
false,
),
gocron.NewTask(
Expand Down
2 changes: 1 addition & 1 deletion manga.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"title":"One Piece","regex":"One Piece Chapter (?P\u003cChapter\u003e\\d{4})$","users":["\u003c@173232081575346178\u003e"],"currentChapter":1119},{"title":"Jujutsu Kaisen","regex":"Jujutsu Kaisen Chapter (?P\u003cChapter\u003e\\d{3})$","users":["\u003cc@228997488563060736\u003e","\u003c@262637906865291264\u003e"],"currentChapter":262}]
[{"title":"One Piece","regex":"One Piece Chapter (?P\u003cChapter\u003e\\d{4})$","users":["\u003c@173232081575346178\u003e"],"currentChapter":1119},{"title":"Jujutsu Kaisen","regex":"Jujutsu Kaisen Chapter (?P\u003cChapter\u003e\\d{3}(.\\d|)$)$","users":["\u003c@228997488563060736\u003e","\u003c@262637906865291264\u003e"],"currentChapter":262}]

0 comments on commit ae3bdbd

Please sign in to comment.