-
Notifications
You must be signed in to change notification settings - Fork 73
Update: F1 Results #413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update: F1 Results #413
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -23,6 +23,9 @@ Using different API lookup to check race calendar. This is to see how long since | |||||
| Back to one API lookup now | ||||||
| Added handling for when not all 20 drivers start the race, eg Stroll in Spain 2025 | ||||||
| Removed hard coding of Perez's name, not a driver anymore | ||||||
|
|
||||||
| 1.6 | ||||||
| Updated for 2026 season | ||||||
| """ | ||||||
|
|
||||||
| load("encoding/json.star", "json") | ||||||
|
|
@@ -31,6 +34,8 @@ load("render.star", "render") | |||||
| load("schema.star", "schema") | ||||||
| load("time.star", "time") | ||||||
|
|
||||||
| DEFAULT_TIMEZONE = "Australia/Adelaide" | ||||||
|
|
||||||
| # Alternate URL thanks to @jvivona for the hosting :) | ||||||
| F1_URL = "https://raw.githubusercontent.com/jvivona/tidbyt-data/refs/heads/main/formula1/" | ||||||
|
|
||||||
|
|
@@ -49,21 +54,21 @@ def main(config): | |||||
| MyRaceTime = "" | ||||||
|
|
||||||
| timezone = time.tz() | ||||||
| now = time.now().in_location(timezone) | ||||||
| now = time.now() | ||||||
| Year = now.format("2006") | ||||||
|
|
||||||
| RACELIST_URL = F1_URL + "races.json" | ||||||
| GetLast = get_cachable_data(RACELIST_URL, 86400) | ||||||
| F1_LAST_JSON = json.decode(GetLast) | ||||||
| TotalRaces = len(F1_LAST_JSON["MRData"]["RaceTable"]["Races"]) | ||||||
|
|
||||||
| # iterate through the race calendar | ||||||
| for x in range(0, len(F1_LAST_JSON["MRData"]["RaceTable"]["Races"]), 1): | ||||||
| for x in range(0, TotalRaces, 1): | ||||||
| LocalRaceDate = F1_LAST_JSON["MRData"]["RaceTable"]["Races"][x]["date"] | ||||||
| LocalRaceTime = F1_LAST_JSON["MRData"]["RaceTable"]["Races"][x]["time"] | ||||||
| RaceDate_Time = LocalRaceDate + " " + LocalRaceTime | ||||||
| FormatRTime = time.parse_time(RaceDate_Time, format = "2006-01-02 15:04:00Z").in_location(timezone) | ||||||
| RTimeDiff = FormatRTime - now | ||||||
| #print(RTimeDiff.hours) | ||||||
|
|
||||||
| # if we're more than 2hrs but less than 48hrs after the last race start get the race results, and break | ||||||
| # or if time next race is more than 0hrs, lets look ahead, and break when we find something | ||||||
|
|
@@ -174,7 +179,7 @@ def main(config): | |||||
| if Session == "R": | ||||||
| if ShowGap == True: | ||||||
| if ShowGrid == True: | ||||||
| for z in range(0, 20, 4): | ||||||
| for z in range(0, 22, 4): | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The loop range is hardcoded with the magic number
Suggested change
|
||||||
| renderCategory.extend([ | ||||||
| render.Column( | ||||||
| expanded = True, | ||||||
|
|
@@ -198,7 +203,7 @@ def main(config): | |||||
| ), | ||||||
| ]) | ||||||
| elif ShowGrid == False: | ||||||
| for z in range(0, 20, 4): | ||||||
| for z in range(0, 22, 4): | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The loop range is hardcoded with the magic number
Suggested change
|
||||||
| renderCategory.extend([ | ||||||
| render.Column( | ||||||
| expanded = True, | ||||||
|
|
@@ -214,7 +219,7 @@ def main(config): | |||||
|
|
||||||
| elif ShowGap == False: | ||||||
| if ShowGrid == True: | ||||||
| for z in range(0, 20, 4): | ||||||
| for z in range(0, 22, 4): | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The loop range is hardcoded with the magic number
Suggested change
|
||||||
| renderCategory.extend([ | ||||||
| render.Column( | ||||||
| expanded = True, | ||||||
|
|
@@ -228,7 +233,7 @@ def main(config): | |||||
| ), | ||||||
| ]) | ||||||
| elif ShowGrid == False: | ||||||
| for z in range(0, 20, 4): | ||||||
| for z in range(0, 22, 4): | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The loop range is hardcoded with the magic number
Suggested change
|
||||||
| renderCategory.extend([ | ||||||
| render.Column( | ||||||
| expanded = True, | ||||||
|
|
@@ -243,7 +248,7 @@ def main(config): | |||||
| ]) | ||||||
|
|
||||||
| if Session == "Q": | ||||||
| for z in range(0, 20, 4): | ||||||
| for z in range(0, 22, 4): | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The loop range is hardcoded with the magic number
Suggested change
|
||||||
| renderCategory.extend([ | ||||||
| render.Column( | ||||||
| expanded = True, | ||||||
|
|
@@ -305,17 +310,19 @@ def getDriver(z, F1_JSON, Session): | |||||
| output.extend(TitleRow) | ||||||
|
|
||||||
| for i in range(0, 4): | ||||||
| if i + z < len(F1_JSON["MRData"]["RaceTable"]["Races"][0]["Results"]): | ||||||
| if i + z < len(F1_JSON["MRData"]["RaceTable"]["Races"][0][SessionCode]): | ||||||
| DriverFont = "#fff" | ||||||
| Pos = F1_JSON["MRData"]["RaceTable"]["Races"][0][SessionCode][i + z]["position"] | ||||||
| DriverID = F1_JSON["MRData"]["RaceTable"]["Races"][0][SessionCode][i + z]["Driver"]["driverId"] | ||||||
|
|
||||||
| Driver = F1_JSON["MRData"]["RaceTable"]["Races"][0][SessionCode][i + z]["Driver"]["familyName"] | ||||||
| if DriverID == "perez": | ||||||
| Driver = "Perez" | ||||||
| elif DriverID == "hulkenberg": | ||||||
| Driver = "Hulkenberg" | ||||||
| else: | ||||||
| Driver = F1_JSON["MRData"]["RaceTable"]["Races"][0][SessionCode][i + z]["Driver"]["familyName"] | ||||||
|
Comment on lines
+318
to
+323
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This For example: DRIVER_NAME_OVERRIDES = {
"perez": "Perez",
"hulkenberg": "Hulkenberg",
}
Driver = DRIVER_NAME_OVERRIDES.get(DriverID, F1_JSON["MRData"]["RaceTable"]["Races"][0][SessionCode][i + z]["Driver"]["familyName"])The |
||||||
| ConstructorID = F1_JSON["MRData"]["RaceTable"]["Races"][0][SessionCode][i + z]["Constructor"]["constructorId"] | ||||||
|
|
||||||
| # If its a Haas, use black color | ||||||
| if ConstructorID == "haas" or ConstructorID == "sauber": | ||||||
| DriverFont = "#000" | ||||||
|
|
||||||
| TeamColor = Team_Color(ConstructorID) | ||||||
|
|
||||||
| driver = render.Row( | ||||||
|
|
@@ -371,7 +378,7 @@ def getDriverGaps(z, F1_JSON, Session): | |||||
| output.extend(TitleRow) | ||||||
|
|
||||||
| for i in range(0, 4): | ||||||
| if i + z < 20: | ||||||
| if i + z < 22: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| DriverFont = "#fff" | ||||||
| Pos = F1_JSON["MRData"]["RaceTable"]["Races"][0]["Results"][i + z]["position"] | ||||||
| DriverCode = F1_JSON["MRData"]["RaceTable"]["Races"][0]["Results"][i + z]["Driver"]["code"] | ||||||
|
|
@@ -382,6 +389,10 @@ def getDriverGaps(z, F1_JSON, Session): | |||||
| Time = "DNF" | ||||||
| elif F1_JSON["MRData"]["RaceTable"]["Races"][0]["Results"][i + z]["positionText"] == "D": | ||||||
| Time = "DQ" | ||||||
| elif F1_JSON["MRData"]["RaceTable"]["Races"][0]["Results"][i + z]["positionText"] == "W": | ||||||
| Time = "DNS" | ||||||
| elif F1_JSON["MRData"]["RaceTable"]["Races"][0]["Results"][i + z]["status"] == "Lapped": | ||||||
| Time = "LAP" | ||||||
| else: | ||||||
| Time = F1_JSON["MRData"]["RaceTable"]["Races"][0]["Results"][i + z]["status"] | ||||||
| Time = Time[:4] | ||||||
|
|
@@ -397,10 +408,6 @@ def getDriverGaps(z, F1_JSON, Session): | |||||
| Time = "" | ||||||
| ConstructorID = F1_JSON["MRData"]["RaceTable"]["Races"][0]["Results"][i + z]["Constructor"]["constructorId"] | ||||||
|
|
||||||
| # If its a Haas, use black color | ||||||
| if ConstructorID == "haas": | ||||||
| DriverFont = "#000" | ||||||
|
|
||||||
| TeamColor = Team_Color(ConstructorID) | ||||||
|
|
||||||
| driver = render.Row( | ||||||
|
|
@@ -471,7 +478,7 @@ def getDriverGrid(z, F1_JSON, Session): | |||||
| output.extend(TitleRow) | ||||||
|
|
||||||
| for i in range(0, 4): | ||||||
| if i + z < 20: | ||||||
| if i + z < 22: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| DriverFont = "#fff" | ||||||
| Pos = F1_JSON["MRData"]["RaceTable"]["Races"][0]["Results"][i + z]["position"] | ||||||
| DriverCode = F1_JSON["MRData"]["RaceTable"]["Races"][0]["Results"][i + z]["Driver"]["code"] | ||||||
|
|
@@ -489,10 +496,6 @@ def getDriverGrid(z, F1_JSON, Session): | |||||
|
|
||||||
| ConstructorID = F1_JSON["MRData"]["RaceTable"]["Races"][0]["Results"][i + z]["Constructor"]["constructorId"] | ||||||
|
|
||||||
| # If its a Haas, use black color | ||||||
| if ConstructorID == "haas": | ||||||
| DriverFont = "#000" | ||||||
|
|
||||||
| TeamColor = Team_Color(ConstructorID) | ||||||
|
|
||||||
| driver = render.Row( | ||||||
|
|
@@ -556,16 +559,18 @@ def Team_Color(ConstructorID): | |||||
| return ("#0f1c2c") | ||||||
| if ConstructorID == "mclaren": | ||||||
| return ("#fd8000") | ||||||
| if ConstructorID == "sauber": | ||||||
| return ("#00df00") | ||||||
| if ConstructorID == "audi": | ||||||
| return ("#901900") | ||||||
| if ConstructorID == "aston_martin": | ||||||
| return ("#015850") | ||||||
| if ConstructorID == "haas": | ||||||
| return ("#f7f7f7") | ||||||
| return ("#818b8e") | ||||||
| if ConstructorID == "rb": | ||||||
| return ("#022948") | ||||||
| if ConstructorID == "williams": | ||||||
| return ("#041e41") | ||||||
| if ConstructorID == "cadillac": | ||||||
| return ("#4a4a4c") | ||||||
| else: | ||||||
| return ("#fff") | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constant
DEFAULT_TIMEZONEis defined but never used. Unused code should be removed to improve clarity and avoid confusion.