-
Notifications
You must be signed in to change notification settings - Fork 0
/
ticker.sh
75 lines (40 loc) · 2.37 KB
/
ticker.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
MYID=$(cat ../fdid)
# Receive Matches
MATJSON=$(curl -s -XGET -H "X-Auth-Token: $MYID" https://api.football-data.org/v4/competitions/$1/matches)
# Parse current match day
CMD=$(echo "$MATJSON" | jq ".matches[0].season.currentMatchday")
# Check Mode
if [[ $3 == "todayonly" || $3 == "todayorgameday" || $3 == "" ]] ; then
# Parse matches only today
RESULTS=$(echo "$MATJSON" | jq -r --argjson CMD $CMD '[.matches[]|select(.utcDate[:10]==(now | strftime("%Y-%m-%d")) and (.status=="FINISHED" or .status=="PAUSED" or .status=="IN_PLAY") )|"\(.homeTeam.shortName) - \(.awayTeam.shortName) \(.score.fullTime.home) : \(.score.fullTime.away)"]|join(" .. ")')
if [[ $RESULTS == "" ]] ; then
if [[ $3 == "todayorgameday" ]] ; then
# Parse all matches of gameday with regular season (no group plays) instead
RESULTS=$(echo "$MATJSON" | jq -r --argjson CMD $CMD '[.matches[]|select(.matchday==$CMD and .stage=="REGULAR_SEASON" and (.status=="FINISHED" or .status=="PAUSED" or .status=="IN_PLAY") )|"\(.homeTeam.tla) - \(.awayTeam.tla) \(.score.fullTime.home):\(.score.fullTime.away)"]|join(" .. ")')
if [[ $RESULTS != "" ]] ; then
TXT=$2" Matchday "$CMD":;"$RESULTS
fi
fi
else
TXT=$2" Matchday "$CMD" today:;"$RESULTS
fi
else
# Parse all matches of gameday with regular season (no group plays) instead
RESULTS=$(echo "$MATJSON" | jq -r --argjson CMD $CMD '[.matches[]|select(.matchday==$CMD and .stage=="REGULAR_SEASON" and (.status=="FINISHED" or .status=="PAUSED" or .status=="IN_PLAY") )|"\(.homeTeam.tla) - \(.awayTeam.tla) \(.score.fullTime.home):\(.score.fullTime.away)"]|join(" .. ")')
if [[ $RESULTS != "" ]] ; then
TXT=$2" Matchday "$CMD":;"$RESULTS
else
if [[ $3 == "gamedayandstandings" ]] ; then
# Receive standings instead
STDJSON=$(curl -s -XGET -H "X-Auth-Token: $MYID" https://api.football-data.org/v4/competitions/$1/standings)
# Parse standings, mind groups, set text block delimiter ; before group
STANDINGS=$(echo "$STDJSON" | jq -r --argjson CMD $CMD '[.standings[]|select(.type=="TOTAL")|[.group,[.table[]|"\(.position). \(.team.shortName)"]]|(if (.[0] | length) > 6 then ";Group \(.[0][6:]):" else ";" end),"\(.[1][])"]|join(" ")')
if [[ $STANDINGS != "" ]] ; then
# Delimiter in the 12th position creates several scroll text blocks
TXT=$2" Standings: ""${STANDINGS//12./;12.}"
fi
fi
fi
fi
echo $TXT