-
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.
Merge pull request #11 from ZeusWPI/tap
Show daily scans
- Loading branch information
Showing
15 changed files
with
313 additions
and
136 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
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,40 @@ | ||
package api | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
) | ||
|
||
type header struct { | ||
Key string | ||
Value string | ||
} | ||
|
||
var jsonHeader = header{ | ||
"Accept", | ||
"application/json", | ||
} | ||
|
||
func makeGetRequest[T any](url string, headers []header, response *T) error { | ||
req, err := http.NewRequest("GET", url, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, header := range headers { | ||
req.Header.Set(header.Key, header.Value) | ||
} | ||
|
||
client := &http.Client{} | ||
resp, err := client.Do(req) | ||
if err != nil { | ||
return err | ||
} | ||
defer resp.Body.Close() | ||
|
||
if err := json.NewDecoder(resp.Body).Decode(response); err != nil { | ||
return err | ||
} | ||
|
||
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
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
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,42 @@ | ||
package api | ||
|
||
import ( | ||
"log" | ||
"scc/config" | ||
"scc/screen" | ||
"slices" | ||
"time" | ||
) | ||
|
||
type zessResponse struct { | ||
Scans []screen.ZessScan `json:"scans"` | ||
} | ||
|
||
var ( | ||
zessURL = config.GetConfig().Zess.URL | ||
zessLastOrderTimestamp = time.Time{} | ||
) | ||
|
||
func zessRunRequests(app *screen.ScreenApp) { | ||
headers := []header{jsonHeader} | ||
|
||
for { | ||
recentScans := &zessResponse{} | ||
if err := makeGetRequest(zessURL, headers, recentScans); err != nil { | ||
log.Printf("Error: Unable to get recent scans: %s\n", err) | ||
} | ||
|
||
slices.SortStableFunc(recentScans.Scans, func(a, b screen.ZessScan) int { | ||
return a.ScanTime.Compare(b.ScanTime) | ||
}) | ||
|
||
for _, order := range recentScans.Scans { | ||
if order.ScanTime.After(zessLastOrderTimestamp) { | ||
app.Zess.Update(&order) | ||
zessLastOrderTimestamp = order.ScanTime | ||
} | ||
} | ||
|
||
time.Sleep(1 * time.Minute) | ||
} | ||
} |
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,27 @@ | ||
cammie: | ||
blocked_names: | ||
- "Name 1" | ||
- "Name 2" | ||
blocked_ips: | ||
- "10.0.0.10" | ||
max_message_length: 200 | ||
spotify: | ||
client_id: "abcd" | ||
client_secret: "dcba" | ||
tap: | ||
url: "https://tap.zeus.gent/recent" | ||
beer: | ||
- "Schelfaut" | ||
- "Duvel" | ||
- "Fourchette" | ||
- "Jupiler" | ||
- "Karmeliet" | ||
- "Kriek" | ||
- "Chouffe" | ||
- "Maes" | ||
- "Somersby" | ||
- "Sportzot" | ||
- "Stella" | ||
zess: | ||
url: "https://zess.zeus.gent/recent_scans" | ||
day_amount: 40 |
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 |
---|---|---|
@@ -1,7 +1,13 @@ | ||
cammie: | ||
blocked_names: [] | ||
blocked_ips: [] | ||
max_message_length: | ||
blocked_names: [] # List of names that don't get shown | ||
blocked_ips: [] # List of IP's that don't get shown | ||
max_message_length: # Max message list | ||
spotify: | ||
client_id: | ||
client_secret: | ||
client_id: # Client ID of the Zeus spotify account | ||
client_secret: # Client secret of the Zeus spotify account | ||
tap: | ||
url: # URL of tap | ||
beer: [] # List of beers in tap, can be found in tap | ||
zess: | ||
url: # URL of zess | ||
day_amount: # Amount of days to keep track, should be the same as is displayed which depends on the screen size |
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
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
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.