-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add cli tool to check for earlier available slots
- Loading branch information
Showing
9 changed files
with
424 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= |
Oops, something went wrong.