Skip to content

Commit

Permalink
Allow configuring a skip-list for progress reports (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
utkuufuk authored Apr 30, 2022
1 parent 76a06f9 commit c942be8
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ GSHEETS_CLIENT_SECRET=xxxxxxxx-xxxxxxxxxxxxxxx
GSHEETS_ACCESS_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
GSHEETS_REFRESH_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SPREADSHEET_ID=xxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxx

PROGRESS_REPORT_SKIP_LIST=foo,bar,baz
3 changes: 2 additions & 1 deletion cmd/progress-report/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ func main() {
}

action := service.ReportProgressAction{
TimezoneLocation: cfg.TimezoneLocation,
SkipList: cfg.SkipList,
TelegramChatId: cfg.TelegramChatId,
TelegramToken: cfg.TelegramToken,
TimezoneLocation: cfg.TimezoneLocation,
}

_, err = action.Run(ctx, client)
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/technoweenie/multipartstreamer v1.0.1 // indirect
go.opencensus.io v0.22.5 // indirect
golang.org/x/exp v0.0.0-20220428152302-39d4317da171
golang.org/x/net v0.0.0-20201209123823-ac852fbbde11 // indirect
golang.org/x/sys v0.0.0-20210104204734-6f8348627aad // indirect
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect
golang.org/x/text v0.3.6 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d // indirect
Expand Down
5 changes: 4 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20220428152302-39d4317da171 h1:TfdoLivD44QwvssI9Sv1xwa5DcL5XQr4au4sZ2F2NV4=
golang.org/x/exp v0.0.0-20220428152302-39d4317da171/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs=
Expand Down Expand Up @@ -271,8 +273,9 @@ golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210104204734-6f8348627aad h1:MCsdmFSdEd4UEa5TKS5JztCRHK/WtvNei1edOj5RSRo=
golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
11 changes: 7 additions & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"strconv"
"strings"
"time"

"github.com/joho/godotenv"
Expand All @@ -19,15 +20,16 @@ type GoogleSheetsConfig struct {
}

type ServerConfig struct {
TimezoneLocation *time.Location
GoogleSheets GoogleSheetsConfig
TimezoneLocation *time.Location
Port int
Secret string
}

type ProgressReportConfig struct {
TimezoneLocation *time.Location
GoogleSheets GoogleSheetsConfig
TimezoneLocation *time.Location
SkipList []string
TelegramChatId int64
TelegramToken string
}
Expand Down Expand Up @@ -63,8 +65,8 @@ func ParseServerConfig() (cfg ServerConfig, err error) {
}

return ServerConfig{
loc,
common,
loc,
port,
os.Getenv("SECRET"),
}, nil
Expand All @@ -79,8 +81,9 @@ func ParseProgressReportConfig() (cfg ProgressReportConfig, err error) {
}

return ProgressReportConfig{
loc,
common,
loc,
strings.Split(os.Getenv("PROGRESS_REPORT_SKIP_LIST"), ","),
chatId,
os.Getenv("TELEGRAM_TOKEN"),
}, nil
Expand Down
8 changes: 7 additions & 1 deletion internal/service/progress_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import (
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/utkuufuk/habit-service/internal/habit"
"github.com/utkuufuk/habit-service/internal/tableimage"
"golang.org/x/exp/slices"
)

type ReportProgressAction struct {
TimezoneLocation *time.Location
SkipList []string
TelegramChatId int64
TelegramToken string
TimezoneLocation *time.Location
}

func (a ReportProgressAction) Run(ctx context.Context, client habit.Client) (string, error) {
Expand All @@ -35,6 +37,10 @@ func (a ReportProgressAction) Run(ctx context.Context, client habit.Client) (str

table := newTable()
for name, habit := range currentHabits {
if slices.Contains(a.SkipList, name) {
continue
}

table.addRow(name, previousHabits[name].Score*100, habit.Score*100)
}

Expand Down

0 comments on commit c942be8

Please sign in to comment.