Compare commits
41 Commits
0feeb6af30
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e5219bc433 | ||
|
|
839ee6306c | ||
|
|
4b636eed7a | ||
|
|
069d2ca7d0 | ||
|
|
72f96a493b | ||
|
|
e11b2396b6 | ||
|
|
0c7d721ddd | ||
|
|
58fe1cdda6 | ||
|
|
9dd76e16b7 | ||
|
|
a0be0c7607 | ||
|
|
50a45e40d5 | ||
|
|
5b3ade2863 | ||
|
|
93364b8580 | ||
|
|
4d288e871c | ||
|
|
c3716613fe | ||
|
|
f853f6c220 | ||
|
|
fabecd836b | ||
|
|
09bdd939f2 | ||
|
|
c85d850218 | ||
|
|
083fd06395 | ||
|
|
2f9b0af5d8 | ||
|
|
b5c4c988f0 | ||
|
|
082c4c16b9 | ||
|
|
0e837958d9 | ||
|
|
116d69ece9 | ||
|
|
35f818d00d | ||
|
|
3f3b8c53b2 | ||
|
|
f197ae3ab5 | ||
|
|
5b58bfbb84 | ||
|
|
b9f10ebb0e | ||
|
|
cf2af10110 | ||
|
|
745300c921 | ||
|
|
96e9b11bdf | ||
|
|
c91c0e6e05 | ||
|
|
e960966a47 | ||
|
|
a4890aaccb | ||
|
|
e8fd9611d2 | ||
|
|
51d5331d9d | ||
|
|
ddad2674d3 | ||
|
|
986d76bd14 | ||
|
|
7234b0054d |
18
2024_schedule.csv
Normal file
@@ -0,0 +1,18 @@
|
||||
FORMULA 1 ARAMCO PRE-SEASON TESTING 2024,Practice,2024-02-21 12:00:00,Bahrain,0
|
||||
FORMULA 1 ARAMCO PRE-SEASON TESTING 2024,Practice,2024-02-22 12:00:00,Bahrain,0
|
||||
FORMULA 1 ARAMCO PRE-SEASON TESTING 2024,Practice,2024-02-23 12:00:00,Bahrain,0
|
||||
FORMULA 1 GULF AIR BAHRAIN GRAND PRIX 2024,Practice,2024-02-29 11:30:00,Bahrain,1
|
||||
FORMULA 1 GULF AIR BAHRAIN GRAND PRIX 2024,Practice,2024-02-29 15:00:00,Bahrain,1
|
||||
FORMULA 1 GULF AIR BAHRAIN GRAND PRIX 2024,Practice,2024-03-01 11:30:00,Bahrain,1
|
||||
FORMULA 1 GULF AIR BAHRAIN GRAND PRIX 2025,Qualifying,2024-03-01 15:00:00,Bahrain,1
|
||||
FORMULA 1 GULF AIR BAHRAIN GRAND PRIX 2026,Race,2024-03-02 15:00:00,Bahrain,1
|
||||
FORMULA 1 STC SAUDI ARABIAN GRAND PRIX 2024,Practice,2024-03-07 13:30:00,Saudi Arabia,2
|
||||
FORMULA 1 STC SAUDI ARABIAN GRAND PRIX 2024,Practice,2024-03-07 17:00:00,Saudi Arabia,2
|
||||
FORMULA 1 STC SAUDI ARABIAN GRAND PRIX 2024,Practice,2024-03-08 13:30:00,Saudi Arabia,2
|
||||
FORMULA 1 STC SAUDI ARABIAN GRAND PRIX 2024,Qualifying,2024-03-08 17:00:00,Saudi Arabia,2
|
||||
FORMULA 1 STC SAUDI ARABIAN GRAND PRIX 2024,Race,2024-03-09 17:00:00,Saudi Arabia,2
|
||||
FORMULA 1 ROLEX AUSTRALIAN GRAND PRIX 2024,Practice,2024-03-22 01:30:00,Australia,3
|
||||
FORMULA 1 ROLEX AUSTRALIAN GRAND PRIX 2024,Practice,2024-03-22 05:00:00,Australia,3
|
||||
FORMULA 1 ROLEX AUSTRALIAN GRAND PRIX 2024,Practice,2024-03-23 01:30:00,Australia,3
|
||||
FORMULA 1 ROLEX AUSTRALIAN GRAND PRIX 2024,Qualifying,2024-03-23 05:00:00,Australia,3
|
||||
FORMULA 1 ROLEX AUSTRALIAN GRAND PRIX 2024,Race,2024-03-24 06:00:00,Australia,3
|
||||
|
@@ -2,4 +2,4 @@
|
||||
|
||||
Discord bot for reporting F1 information.
|
||||
|
||||
Makes use of code from fastf1 python library (https://github.com/theOehrly/Fast-F1)
|
||||
Makes use of code from fastf1 python library (https://github.com/theOehrly/Fast-F1)
|
||||
|
||||
@@ -5,7 +5,10 @@ import logging
|
||||
import requests
|
||||
import time
|
||||
import sqlite3
|
||||
import sys
|
||||
|
||||
from contextlib import closing
|
||||
from filelock import Timeout, FileLock
|
||||
from fastf1.signalr_aio import Connection
|
||||
|
||||
import fastf1
|
||||
@@ -84,6 +87,8 @@ class SignalRClient:
|
||||
"SessionData", "LapCount"]
|
||||
|
||||
self.debug = debug
|
||||
self.messages_db = 'messages.db'
|
||||
self.messages_lock = FileLock('messages.lock')
|
||||
self.filename = filename
|
||||
self.filemode = filemode
|
||||
self.timeout = timeout
|
||||
@@ -91,9 +96,11 @@ class SignalRClient:
|
||||
|
||||
if not logger:
|
||||
logging.basicConfig(
|
||||
format="%(asctime)s - %(levelname)s: %(message)s"
|
||||
format="%(asctime)s - %(levelname)s: %(message)s", \
|
||||
stream=sys.stderr
|
||||
)
|
||||
self.logger = logging.getLogger('SignalR')
|
||||
self.logger.warning("Created logger for SignalR")
|
||||
else:
|
||||
self.logger = logger
|
||||
|
||||
@@ -101,17 +108,15 @@ class SignalRClient:
|
||||
self._t_last_message = None
|
||||
|
||||
def _to_file(self, msg):
|
||||
"""
|
||||
self._output_file.write(msg + '\n')
|
||||
self._output_file.flush()
|
||||
"""
|
||||
#print(msg)
|
||||
con = sqlite3.connect('messages.db')
|
||||
cur = con.cursor()
|
||||
cur.execute("insert into messages (message) values(?)", (msg,))
|
||||
con.commit()
|
||||
cur.close()
|
||||
con.close()
|
||||
try:
|
||||
with self.messages_lock:
|
||||
with closing(sqlite3.connect(self.messages_db)) as con:
|
||||
with closing(con.cursor()) as cur:
|
||||
#self.logger.warning("about to log: " + msg)
|
||||
cur.execute("insert into messages (message) values(?)", (msg,))
|
||||
con.commit()
|
||||
except:
|
||||
print(f'Error writing message to db.')
|
||||
|
||||
async def _on_do_nothing(self, msg):
|
||||
# just do nothing with the message; intended for debug mode where some
|
||||
@@ -186,7 +191,7 @@ class SignalRClient:
|
||||
f"[v{fastf1.__version__}]")
|
||||
await asyncio.gather(asyncio.ensure_future(self._supervise()),
|
||||
asyncio.ensure_future(self._run()))
|
||||
self._output_file.close()
|
||||
#self._output_file.close()
|
||||
self.logger.warning("Exiting...")
|
||||
|
||||
def start(self):
|
||||
|
||||
BIN
audio/bwoken.mp3
Normal file
BIN
audio/no.mp3
Normal file
BIN
bing/1.png
Normal file
|
After Width: | Height: | Size: 218 KiB |
BIN
bing/10.png
Normal file
|
After Width: | Height: | Size: 383 KiB |
BIN
bing/2.png
Normal file
|
After Width: | Height: | Size: 205 KiB |
BIN
bing/3.png
Normal file
|
After Width: | Height: | Size: 444 KiB |
BIN
bing/4.png
Normal file
|
After Width: | Height: | Size: 236 KiB |
BIN
bing/5.png
Normal file
|
After Width: | Height: | Size: 281 KiB |
BIN
bing/6.png
Normal file
|
After Width: | Height: | Size: 356 KiB |
BIN
bing/7.png
Normal file
|
After Width: | Height: | Size: 264 KiB |
BIN
bing/8.png
Normal file
|
After Width: | Height: | Size: 329 KiB |
BIN
bing/9.png
Normal file
|
After Width: | Height: | Size: 263 KiB |
26
binger.py
Executable file
@@ -0,0 +1,26 @@
|
||||
import glob
|
||||
from random import randrange
|
||||
import sqlite3
|
||||
|
||||
BING_IMGS_PATH = "bing/*"
|
||||
DB = "bing.db"
|
||||
|
||||
def get_image_count():
|
||||
# Choose a random image
|
||||
bing_files = glob.glob(BING_IMGS_PATH)
|
||||
image_idx = randrange(len(bing_files))
|
||||
image = bing_files[image_idx]
|
||||
|
||||
# Get the latest count and increment
|
||||
con = sqlite3.connect(DB)
|
||||
cur = con.cursor()
|
||||
cur.execute("UPDATE BING_COUNT SET COUNT = COUNT + 1")
|
||||
con.commit()
|
||||
result = cur.execute("SELECT COUNT FROM BING_COUNT")
|
||||
count = result.fetchone()
|
||||
count = count[0]
|
||||
|
||||
cur.close()
|
||||
con.close()
|
||||
|
||||
return(image, count)
|
||||
56
bingo.py
Executable file
@@ -0,0 +1,56 @@
|
||||
import glob
|
||||
from PIL import Image
|
||||
from random import randrange
|
||||
from uuid import uuid4
|
||||
|
||||
class Bingo:
|
||||
"""Class which allows creation and cleanup of F1 bingo card images."""
|
||||
def __init__(self):
|
||||
self.LAYOUT_WIDTH = 88
|
||||
self.X_OFFSET = 10
|
||||
self.Y_OFFSET = 110
|
||||
self.SQUARES_PATH = "bingo_images/squares/*.png"
|
||||
self.FREE_SQUARES_PATH = "bingo_images/free_squares/*.png"
|
||||
self.BLANK_CARD_PATH = "bingo_images/card_blank.png"
|
||||
self.TEMP_FOLDER = "bingo_images/temp/"
|
||||
|
||||
def get_card(self):
|
||||
square_files = glob.glob(self.SQUARES_PATH)
|
||||
free_square_files = glob.glob(self.FREE_SQUARES_PATH)
|
||||
used_files = set()
|
||||
|
||||
with Image.open(self.BLANK_CARD_PATH) as card_img:
|
||||
card_img.load()
|
||||
card_img = card_img.convert('RGBA')
|
||||
|
||||
# Fill the grid
|
||||
for y in range(5):
|
||||
for x in range(5):
|
||||
square_file = ""
|
||||
# If this is the center square, pick a random free square
|
||||
if x == 2 and y == 2:
|
||||
square_file = \
|
||||
free_square_files[randrange(len(free_square_files))]
|
||||
|
||||
# otherwise, find a random file that hasn't been used yet
|
||||
else:
|
||||
rand_file_idx = randrange(len(square_files))
|
||||
while rand_file_idx in used_files:
|
||||
rand_file_idx = randrange(len(square_files))
|
||||
|
||||
square_file = square_files[rand_file_idx]
|
||||
used_files.add(rand_file_idx)
|
||||
|
||||
with Image.open(square_file) as square:
|
||||
|
||||
position = (self.X_OFFSET + (x * self.LAYOUT_WIDTH),
|
||||
self.Y_OFFSET + (y * self.LAYOUT_WIDTH))
|
||||
|
||||
card_img.paste(square, position, square)
|
||||
|
||||
# Write image to temp file
|
||||
outfile = "".join((self.TEMP_FOLDER, str(uuid4()), ".png"))
|
||||
print(f"{outfile=}")
|
||||
card_img.save(outfile)
|
||||
return outfile
|
||||
|
||||
BIN
bingo_images/card_blank.png
Normal file
|
After Width: | Height: | Size: 6.1 KiB |
BIN
bingo_images/card_blank.xcf
Normal file
BIN
bingo_images/free_space.png
Normal file
|
After Width: | Height: | Size: 3.7 KiB |
BIN
bingo_images/free_squares/free_buxton_pause.png
Normal file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
bingo_images/free_squares/free_cofty_sir_lewis.png
Normal file
|
After Width: | Height: | Size: 3.7 KiB |
BIN
bingo_images/free_squares/free_rosanna_towers.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
BIN
bingo_images/squares/a_driver_does_no_laps.png
Normal file
|
After Width: | Height: | Size: 3.1 KiB |
BIN
bingo_images/squares/aerorake.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
bingo_images/squares/anyone_but_max_p1.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
bingo_images/squares/big_changes.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
bingo_images/squares/big_spin_t12.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
bingo_images/squares/car_debris_on_track.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
bingo_images/squares/car_different.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
BIN
bingo_images/squares/carbon_fiber.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
bingo_images/squares/chadlonso_time_life.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
bingo_images/squares/commentator_car_confused.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
bingo_images/squares/dnf.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
bingo_images/squares/driver_complains_impeding.png
Normal file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
bingo_images/squares/driver_crashes_no_contact.png
Normal file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
bingo_images/squares/driver_says_shutup.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
bingo_images/squares/flowviz.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
bingo_images/squares/haas_stops.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
bingo_images/squares/honda_engine_dies.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
bingo_images/squares/its_only_testing.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
bingo_images/squares/lockup_t1.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
bingo_images/squares/mercedes_downplays.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
BIN
bingo_images/squares/no_power.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
bingo_images/squares/puncture.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
bingo_images/squares/radical_concept_fails.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
bingo_images/squares/radical_concept_works.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
BIN
bingo_images/squares/red_flag.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
bingo_images/squares/redbull_run_most.png
Normal file
|
After Width: | Height: | Size: 3.1 KiB |
BIN
bingo_images/squares/sandbagging.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
bingo_images/squares/silly_season.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
bingo_images/squares/square_template.xcf
Normal file
BIN
bingo_images/squares/team_hides_work.png
Normal file
|
After Width: | Height: | Size: 3.1 KiB |
BIN
bingo_images/squares/team_misnamed.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
bingo_images/squares/teammates_collide.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
bingo_images/squares/tifosi.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
bingo_images/squares/torro_rosso_or_vcarb.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
bingo_images/squares/williams_first_out.png
Normal file
|
After Width: | Height: | Size: 3.1 KiB |
BIN
bingo_images/squares/williams_top_speed_trap.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
16
create_alerts_db.py
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/python3
|
||||
import sqlite3
|
||||
|
||||
if __name__ == '__main__':
|
||||
con = sqlite3.connect('alerts.db')
|
||||
cur = con.cursor()
|
||||
|
||||
cur.execute("""drop table alert_schedule""")
|
||||
cur.execute("""drop table alert_channels""")
|
||||
|
||||
cur.execute("""create table alert_schedule( id integer primary key, type, day, hour, minute, last_sent );""")
|
||||
cur.execute("""create table alert_channels( id integer primary key, type, channel_id);""")
|
||||
con.commit()
|
||||
cur.close()
|
||||
con.close()
|
||||
|
||||
33
load_schedule.py
Executable file
@@ -0,0 +1,33 @@
|
||||
import csv
|
||||
import datetime
|
||||
import sqlite3
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
con = sqlite3.connect('schedule.db')
|
||||
cur = con.cursor()
|
||||
cur.execute("""drop table schedule""")
|
||||
|
||||
# Create the table
|
||||
cur.execute("""create table schedule( id integer primary key, """ +
|
||||
"""title, session_type, date_start,""" +
|
||||
"""location, round );""")
|
||||
|
||||
con.commit()
|
||||
|
||||
# Open the csv file
|
||||
with open("2024_schedule.csv") as csvfile:
|
||||
schedule_reader = csv.reader(csvfile, )
|
||||
for row in schedule_reader:
|
||||
sql_line = "INSERT INTO schedule (title, session_type, " + \
|
||||
"date_start, location, round) VALUES(" + \
|
||||
f"?, ?, ?, ?, ?)"
|
||||
|
||||
cur.execute(sql_line,
|
||||
(row)
|
||||
)
|
||||
con.commit()
|
||||
|
||||
cur.close()
|
||||
con.close()
|
||||
BIN
races_backup.db
Normal file
3
requirements.txt
Executable file → Normal file
@@ -1,5 +1,6 @@
|
||||
beautifulsoup4==4.9.3
|
||||
discord.py==2.2.3
|
||||
discord==2.2.3
|
||||
fastf1==3.0.3
|
||||
jdata==0.5.3
|
||||
Requests==2.31.0
|
||||
websockets==11.0.3
|
||||
|
||||