Skip to content

Commit

Permalink
ignore sme zatvoreni
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Jirku <[email protected]>
  • Loading branch information
martinjirku committed Apr 9, 2024
1 parent 92ecf98 commit 53bade6
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 12 deletions.
9 changes: 5 additions & 4 deletions .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ follow_symlink = false
# full_bin = ""
include_dir = ["handlers", "models", "services", "utils", "pkg", "template"]
include_ext = ["go", "templ"]
include_file = ["main.go", "dist/assets/style-*.css"]
kill_delay = "0.3s"
include_file = ["main.go", "dist/assets/style-*.css", "dist/main.css"]
kill_delay = 5000000000 # nanosecond
log = "build-errors.log"
poll = false
poll_interval = 0
post_cmd = []
# Workaround for shutting down the server (https://github.com/cosmtrek/air/issues/534)
post_cmd = ["lsof -i tcp:8080 | awk 'NR==2{print $2}' | xargs kill"]
pre_cmd = []
rerun = false
rerun_delay = 500
send_interrupt = false
send_interrupt = true
stop_on_error = true

[color]
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ vendor/**/*
*_templ.txt
template**/*.html
.data/
.tasks/
.task/
15 changes: 10 additions & 5 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ tasks:
- ./node_modules/

watch:
deps: [watch:ts, watch:css, watch:templ, watch:server]
deps: [watch:ts, watch:css, watch:templ, watch:server:wait]
watch:templ:
deps: [bin:templ]
cmds:
Expand All @@ -58,15 +58,20 @@ tasks:
watch:ts:
cmds:
- npx vite build -w
watch:server:wait:
cmds:
- sleep 1
- task: watch:server
watch:server:
deps: [bin:air]
# sources:
# - main.go
# - services/**/*.go
# generates:
# - ./tmp/main
cmds:
- sleep 1
- .task/bin/air -c .air.toml

buildserver:
- go build -v -i main.go

db:start:
cmds:
- docker run --name mcmamina -e POSTGRES_PASSWORD=$POSTGRES_PASSWORD -e POSTGRES_DB=$POSTGRES_DB -e POSTGRES_USER=$POSTGRES_USER -v ./.data:/var/lib/postgresql/data -p 5432:5432 -d postgres:alpine
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module jirku.sk/mcmamina
go 1.22.0

require (
github.com/a-h/templ v0.2.648
github.com/a-h/templ v0.2.663
github.com/alecthomas/chroma v0.10.0
github.com/gorilla/mux v1.8.1
github.com/joho/godotenv v1.5.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ github.com/a-h/templ v0.2.543 h1:8YyLvyUtf0/IE2nIwZ62Z/m2o2NqwhnMynzOL78Lzbk=
github.com/a-h/templ v0.2.543/go.mod h1:jP908DQCwI08IrnTalhzSEH9WJqG/Q94+EODQcJGFUA=
github.com/a-h/templ v0.2.648 h1:A1ggHGIE7AONOHrFaDTM8SrqgqHL6fWgWCijQ21Zy9I=
github.com/a-h/templ v0.2.648/go.mod h1:SA7mtYwVEajbIXFRh3vKdYm/4FYyLQAtPH1+KxzGPA8=
github.com/a-h/templ v0.2.663 h1:aa0WMm27InkYHGjimcM7us6hJ6BLhg98ZbfaiDPyjHE=
github.com/a-h/templ v0.2.663/go.mod h1:SA7mtYwVEajbIXFRh3vKdYm/4FYyLQAtPH1+KxzGPA8=
github.com/alecthomas/chroma v0.10.0 h1:7XDcGkCQopCNKjZHfYrNLraA+M7e0fMiJ/Mfikbfjek=
github.com/alecthomas/chroma v0.10.0/go.mod h1:jtJATyUxlIORhUOFNA9NZDWGAQ8wpxQQqNSB4rjA/1s=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down
31 changes: 30 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"embed"
"flag"
"fmt"
Expand All @@ -10,8 +11,11 @@ import (
"net/http/httputil"
"net/url"
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"
"time"

"github.com/gorilla/mux"
"github.com/joho/godotenv"
Expand Down Expand Up @@ -124,9 +128,34 @@ func setupWebserver(log *slog.Logger, calendarService *services.CalendarService)
// MCMAMINA <<-- GENERATED CODE
handleFiles(router, http.FS(workingFolder))

sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGABRT)

addr := fmt.Sprintf("%s:%d", config.host, config.port)
srv := &http.Server{
Addr: addr,
Handler: router,
}
log.Info(fmt.Sprintf("starting server at %s", addr))
http.ListenAndServe(addr, router)
go func() {
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Error(fmt.Errorf("failed to start server %s", err).Error())
os.Exit(1)
}
}()
// Block until we receive our signal.
signal := <-sigs
log.Info(fmt.Sprintf("received \"%s\" signal, shutting down", signal))

ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
defer cancel()

// Doesn't block if no connections, but will otherwise wait
// until the timeout deadline.
log.Info("shutting down...")
srv.Shutdown(ctx)
log.Info("server shutted down")
os.Exit(0)
}

func handleFiles(r *mux.Router, folder http.FileSystem) {
Expand Down
9 changes: 9 additions & 0 deletions services/calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package services
import (
"context"
"fmt"
"strings"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -45,13 +46,17 @@ func (s *CalendarService) getEvents(ctx context.Context, timeMin, timeMax time.T

var result []models.Event

eventTitleToIgnore := strings.ToLower("Prestávka - sme zatvorení")

var eventsToGet []string
for _, event := range events.Items {
if event == nil {
continue
}
if event.Recurrence != nil && len(event.Recurrence) > 0 {
eventsToGet = append(eventsToGet, event.Id)
} else if strings.EqualFold(strings.ToLower(event.Summary), eventTitleToIgnore) {
continue
} else {
result = append(result, newEventFromGoogle(event))
}
Expand Down Expand Up @@ -79,6 +84,9 @@ func (s *CalendarService) getEvents(ctx context.Context, timeMin, timeMax time.T
close(gatheredEvents)
}()
for events := range gatheredEvents {
if len(events) > 0 && strings.EqualFold(strings.ToLower(events[0].Title), eventTitleToIgnore) {
continue
}
result = append(result, events...)
}
return result, nil
Expand Down Expand Up @@ -111,6 +119,7 @@ func (s *CalendarService) GetEvents(ctx context.Context, timeMin, timeMax time.T
if ok {
return events, nil
}

}

events, err := s.getEvents(ctx, timeMin, timeMax)
Expand Down

0 comments on commit 53bade6

Please sign in to comment.