aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorXe Iaso <me@xeiaso.net>2024-05-27 17:08:46 -0400
committerXe Iaso <me@xeiaso.net>2024-05-27 17:08:54 -0400
commit3ad650f549a0cdf960e475108d0c80efbf1cfe0c (patch)
treedc93ad82985a1c32edbb384a26bbf4edb2bcff4b /internal
parentb045736a19d3a45a2fdf86853f451fc69047d083 (diff)
downloadxesite-3ad650f549a0cdf960e475108d0c80efbf1cfe0c.tar.xz
xesite-3ad650f549a0cdf960e475108d0c80efbf1cfe0c.zip
internal/fly/flighttracker: move this to Xe/x
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'internal')
-rw-r--r--internal/fly/flyghttracker/flyghttracker.go89
1 files changed, 0 insertions, 89 deletions
diff --git a/internal/fly/flyghttracker/flyghttracker.go b/internal/fly/flyghttracker/flyghttracker.go
deleted file mode 100644
index 4d960cf..0000000
--- a/internal/fly/flyghttracker/flyghttracker.go
+++ /dev/null
@@ -1,89 +0,0 @@
-package flyghttracker
-
-import (
- "encoding/json"
- "flag"
- "fmt"
- "net/http"
- "strings"
- "time"
-
- "within.website/x/web"
-)
-
-var (
- flyghttrackerURL = flag.String("flyghttracker-url", "https://flyght-tracker.fly.dev/api/upcoming_events", "Flyghttracker URL")
-)
-
-// Date represents a date in the format "YYYY-MM-DD"
-type Date struct {
- time.Time
-}
-
-// UnmarshalJSON parses a JSON string in the format "YYYY-MM-DD" to a Date
-func (d *Date) UnmarshalJSON(b []byte) error {
- s := strings.Trim(string(b), "\"")
- t, err := time.Parse("2006-01-02", s)
- if err != nil {
- return err
- }
- d.Time = t
- return nil
-}
-
-// MarshalJSON returns a JSON string in the format "YYYY-MM-DD"
-func (d Date) MarshalJSON() ([]byte, error) {
- return json.Marshal(d.Time.Format("2006-01-02"))
-}
-
-// Event represents an event that members of DevRel will be attending.
-type Event struct {
- Name string `json:"name"`
- URL string `json:"url"`
- StartDate Date `json:"start_date"`
- EndDate Date `json:"end_date"`
- Location string `json:"location"`
- People []string `json:"people"`
-}
-
-// Fetch new events from the Flyght Tracker URL.
-//
-// It returns a list of events that end in the future and that have "Xe" as one of the attendees.
-func Fetch() ([]Event, error) {
- resp, err := http.Get(*flyghttrackerURL)
- if err != nil {
- return nil, fmt.Errorf("failed to fetch flyghttracker events: %w", err)
- }
- defer resp.Body.Close()
-
- if resp.StatusCode != http.StatusOK {
- return nil, web.NewError(http.StatusOK, resp)
- }
-
- var events []Event
- if err := json.NewDecoder(resp.Body).Decode(&events); err != nil {
- return nil, fmt.Errorf("failed to decode flyghttracker events: %w", err)
- }
-
- var result []Event
-
- for _, event := range events {
- if event.EndDate.Before(time.Now()) {
- continue
- }
-
- found := false
- for _, person := range event.People {
- if person == "Xe" {
- found = true
- break
- }
- }
-
- if found {
- result = append(result, event)
- }
- }
-
- return result, nil
-}