Skip to content

Commit

Permalink
add cli tool to check for earlier available slots
Browse files Browse the repository at this point in the history
  • Loading branch information
daviian committed Jun 5, 2021
1 parent 45f0682 commit 75f6a1d
Show file tree
Hide file tree
Showing 9 changed files with 424 additions and 0 deletions.
162 changes: 162 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

# Created by https://www.toptal.com/developers/gitignore/api/windows,linux,macos,go,jetbrains+iml
# Edit at https://www.toptal.com/developers/gitignore?templates=windows,linux,macos,go,jetbrains+iml

### Go ###
# Binaries for programs and plugins
*.exe
*.exe~
Expand All @@ -13,3 +18,160 @@

# Dependency directories (remove the comment below to include it)
# vendor/

### Go Patch ###
/vendor/
/Godeps/

### JetBrains+iml ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### JetBrains+iml Patch ###
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023

*.iml
modules.xml
.idea/misc.xml
*.ipr

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/windows,linux,macos,go,jetbrains+iml
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"encoding/json"
"fmt"
"net/http"
"time"
)

type slot struct {
StartDate time.Time
}

func getCovidVaccinationSlots(authority int) ([]slot, error) {
url := fmt.Sprintf("https://e-gov.ooe.gv.at/at.gv.ooe.cip/services/api/covid/slots?page=1&size=1000&orgUnitId=%d&birthdate=1990-01-01", authority)
response, err := http.Get(url)
if err != nil {
return nil, fmt.Errorf("http get slots failed: %w", err)
}
defer response.Body.Close()

var jsonSlots []map[string]interface{}
err = json.NewDecoder(response.Body).Decode(&jsonSlots)

slots, err := parseSlots(jsonSlots)
if err != nil {
return nil, err
}

return slots, err
}

// startDate of slots doesn't follow the ISO 8601 definition so we need to parse the dates by ourselves.
func parseSlots(jsonSlots []map[string]interface{}) ([]slot, error) {
slots := make([]slot, len(jsonSlots))
for _, jsonSlot := range jsonSlots {
startDate, err := time.ParseInLocation("2006-01-02T15:04:05", jsonSlot["startDate"].(string), time.Local)
if err != nil {
return nil, fmt.Errorf("parse time failed: %w", err)
}
slots = append(slots, slot{startDate})
}
return slots, nil
}
94 changes: 94 additions & 0 deletions flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package main

import (
"errors"
"flag"
"fmt"
"golang.org/x/term"
"strconv"
"strings"
"syscall"
"time"
)

var (
authorities []int
date time.Time
iftttEventName string
iftttKey string
)

func parseFlags() error {
authoritiesFlag := flag.String("authorities", "", "comma-separated list of authorities")
dateFlag := flag.String("date", "", "date in ISO format, e.g. 2021-06-30")
iftttEventNameFlag := flag.String("ifttt-event-name", "", "IFTTT event name of webhook")
flag.Parse()

if *authoritiesFlag == "" {
return errors.New("authorities flag missing")
}

if *dateFlag == "" {
return errors.New("date flag missing")
}

if *iftttEventNameFlag == "" {
return errors.New("ifttt-event-name flag missing")
}

err := parseAuthoritiesFlag(authoritiesFlag)
if err != nil {
return fmt.Errorf("parse authorities failed: %w", err)
}

err = parseDateFlag(dateFlag)
if err != nil {
return fmt.Errorf("parse date failed: %w", err)
}

parseIFTTTEventName(iftttEventNameFlag)

err = promptIFTTTKey()
if err != nil {
return fmt.Errorf("prompt for ifttt key failed: %w", err)
}

return nil
}

func parseAuthoritiesFlag(authoritiesFlag *string) error {
for _, authority := range strings.Split(*authoritiesFlag, ",") {
atoi, err := strconv.Atoi(authority)
if err != nil {
return fmt.Errorf("convert authority string to int failed: %w", err)
}
authorities = append(authorities, atoi)
}

return nil
}

func parseDateFlag(dateFlag *string) error {
var err error
date, err = time.Parse("2006-01-02", strings.TrimSpace(*dateFlag))
if err != nil {
return fmt.Errorf("parse date failed: %w", err)
}

return nil
}

func parseIFTTTEventName(iftttEventNameFlag *string) {
iftttEventName = strings.TrimSpace(*iftttEventNameFlag)
}

func promptIFTTTKey() error {
fmt.Println("Enter IFTTT Key: ")
iftttKeyBytes, err := term.ReadPassword(int(syscall.Stdin))
if err != nil {
return fmt.Errorf("read password prompt failed: %w", err)
}

iftttKey = string(iftttKeyBytes)
return nil
}
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module ooe-impf-alert

go 1.16

require golang.org/x/term v0.0.0-20210503060354-a79de5458b56
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 h1:b8jxX3zqjpqb2LklXPzKSGJhzyxCOZSz8ncv8Nv+y7w=
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
Loading

0 comments on commit 75f6a1d

Please sign in to comment.