Took user restrictions off starting race reporting. Tried to improve sql writes to fix db locking error.

This commit is contained in:
tamservo
2025-04-21 16:47:05 -04:00
parent 069d2ca7d0
commit 4b636eed7a
2 changed files with 66 additions and 51 deletions

View File

@@ -5,6 +5,7 @@ import logging
import requests import requests
import time import time
import sqlite3 import sqlite3
import sys
from fastf1.signalr_aio import Connection from fastf1.signalr_aio import Connection
@@ -84,6 +85,7 @@ class SignalRClient:
"SessionData", "LapCount"] "SessionData", "LapCount"]
self.debug = debug self.debug = debug
self._db_is_open = False
self.filename = filename self.filename = filename
self.filemode = filemode self.filemode = filemode
self.timeout = timeout self.timeout = timeout
@@ -91,7 +93,8 @@ class SignalRClient:
if not logger: if not logger:
logging.basicConfig( 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 = logging.getLogger('SignalR')
else: else:
@@ -107,11 +110,17 @@ class SignalRClient:
""" """
#print(msg) #print(msg)
con = sqlite3.connect('messages.db') con = sqlite3.connect('messages.db')
cur = con.cursor()
cur.execute("insert into messages (message) values(?)", (msg,)) try:
con.commit() with con:
cur.close() self._db_is_open = True
con.close() con.execute("insert into messages (message) values(?)", (msg,))
con.close()
self.db_is_open = False
except:
if con is not None:
con.close()
self._db_is_open = False
async def _on_do_nothing(self, msg): async def _on_do_nothing(self, msg):
# just do nothing with the message; intended for debug mode where some # just do nothing with the message; intended for debug mode where some
@@ -186,7 +195,9 @@ class SignalRClient:
f"[v{fastf1.__version__}]") f"[v{fastf1.__version__}]")
await asyncio.gather(asyncio.ensure_future(self._supervise()), await asyncio.gather(asyncio.ensure_future(self._supervise()),
asyncio.ensure_future(self._run())) asyncio.ensure_future(self._run()))
self._output_file.close() #self._output_file.close()
while(self._db_is_open):
asyncio.sleep(1)
self.logger.warning("Exiting...") self.logger.warning("Exiting...")
def start(self): def start(self):

View File

@@ -904,56 +904,60 @@ class Robottas(commands.Bot):
self.driver_dict = { self.driver_dict = {
'1': '<:VER:1067541523748630570>', '1': '<:VER:1067541523748630570>',
'3': '<:RIC:1067870312949108887>', '3': '<:RIC:1067870312949108887>',
'5': '<:VET:1067964065516884079>', '4': '<:NOR:1067840487593082941>',
'5': '<:BOR:1345026018938716161>',
'6': '<:HAD:1345027038104387674>',
'7': '<:DOO:1289936390993215601>',
'10': '<:GAS:1067836596495327283>',
'11': '<:PER:1067822335123525732>', '11': '<:PER:1067822335123525732>',
'12': '<:ANT:1289237308805222491>', '12': '<:ANT:1289237308805222491>',
'14': '<:ALO:1067876094033793054>', '14': '<:ALO:1067876094033793054>',
'16': '<:LEC:1067544797050585198>',
'18': '<:STR:1067871582854336663>',
'20': '<:MAG:1067883814992486510>',
'22': '<:TSU:1067888851676315660>',
'23': '<:ALB:1067874026871074887>',
'24': '<:ZHO:1067865955117568010>',
'27': '<:HUL:1067880110918742187>',
'30': '<:LAW:1289237140051464204>', '30': '<:LAW:1289237140051464204>',
'31': '<:OCO:1067834157465612398>',
'43': '<:COL:1289237227049844849>', '43': '<:COL:1289237227049844849>',
'44': '<:HAM:1067828533746991165>', '44': '<:HAM:1067828533746991165>',
'55': '<:SAI:1067824776502067270>', '55': '<:SAI:1067824776502067270>',
'63': '<:RUS:1067831294748274728>', '63': '<:RUS:1067831294748274728>',
'16': '<:LEC:1067544797050585198>',
'18': '<:STR:1067871582854336663>',
'4': '<:NOR:1067840487593082941>',
'10': '<:GAS:1067836596495327283>',
'27': '<:HUL:1067880110918742187>',
'31': '<:OCO:1067834157465612398>',
'77': '<:BOT:1067819716527276032>', '77': '<:BOT:1067819716527276032>',
'81': '<:PIA:1067844998369914961>', '81': '<:PIA:1067844998369914961>',
'24': '<:ZHO:1067865955117568010>', '87': '<:BEA:1289237392649224278>'
'22': '<:TSU:1067888851676315660>',
'20': '<:MAG:1067883814992486510>',
'23': '<:ALB:1067874026871074887>',
'38': '<:BEA:1289237392649224278>',
} }
# Holds dictionary for driver 3-letter code to icon # Holds dictionary for driver 3-letter code to icon
self.name_dict = { self.name_dict = {
'VER': '<:VER:1067541523748630570>', 'ALB': '<:ALB:1067874026871074887>',
'RIC': '<:RIC:1067870312949108887>',
'VET': '<:VET:1067964065516884079>',
'PER': '<:PER:1067822335123525732>',
'ALO': '<:ALO:1067876094033793054>', 'ALO': '<:ALO:1067876094033793054>',
'HAM': '<:HAM:1067828533746991165>', 'ANT': '<:ANT:1289237308805222491>',
'SAI': '<:SAI:1067824776502067270>', 'BEA': '<:BEA:1289237392649224278>',
'RUS': '<:RUS:1067831294748274728>', 'BOR': '<:BOR:1345026018938716161>',
'LEC': '<:LEC:1067544797050585198>', 'BOT': '<:BOT:1067819716527276032>',
'STR': '<:STR:1067871582854336663>', 'COL': '<:COL:1289237227049844849>',
'NOR': '<:NOR:1067840487593082941>', 'DOO': '<:DOO:1289936390993215601>',
'GAS': '<:GAS:1067836596495327283>', 'GAS': '<:GAS:1067836596495327283>',
'HAD': '<:HAD:1345027038104387674>',
'HAM': '<:HAM:1067828533746991165>',
'HUL': '<:HUL:1067880110918742187>', 'HUL': '<:HUL:1067880110918742187>',
'LAW': '<:LAW:1289237140051464204>', 'LAW': '<:LAW:1289237140051464204>',
'OCO': '<:OCO:1067834157465612398>', 'LEC': '<:LEC:1067544797050585198>',
'BOT': '<:BOT:1067819716527276032>',
'PIA': '<:PIA:1067844998369914961>',
'ZHO': '<:ZHO:1067865955117568010>',
'TSU': '<:TSU:1067888851676315660>',
'MAG': '<:MAG:1067883814992486510>', 'MAG': '<:MAG:1067883814992486510>',
'ALB': '<:ALB:1067874026871074887>', 'NOR': '<:NOR:1067840487593082941>',
'BEA': '<:BEA:1289237392649224278>', 'OCO': '<:OCO:1067834157465612398>',
'COL': '<:COL:1289237227049844849>', 'PIA': '<:PIA:1067844998369914961>',
'ANT': '<:ANT:1289237308805222491>' 'RIC': '<:RIC:1067870312949108887>',
'RUS': '<:RUS:1067831294748274728>',
'SAI': '<:SAI:1067824776502067270>',
'STR': '<:STR:1067871582854336663>',
'TSU': '<:TSU:1067888851676315660>',
'VER': '<:VER:1067541523748630570>',
'VET': '<:VET:1067964065516884079>',
'ZHO': '<:ZHO:1067865955117568010>'
} }
# Holds dictionary for race states to icons # Holds dictionary for race states to icons
@@ -986,7 +990,7 @@ class Robottas(commands.Bot):
self.started = False self.started = False
# Hold message delay # Hold message delay
self.delay = 45 self.delay = 25
self.message_queue = [] self.message_queue = []
# Hold whether to report deleted lap messages # Hold whether to report deleted lap messages
@@ -1127,24 +1131,24 @@ class Robottas(commands.Bot):
@self.command() @self.command()
async def race(ctx): async def race(ctx):
if ctx.author.id == 581960756271251457 or \ #if ctx.author.id == 581960756271251457 or \
ctx.author.guild_permissions.administrator: # ctx.author.guild_permissions.administrator:
await ctx.send(":robot::peach: Ready to report for the race!") await ctx.send(":robot::peach: Ready to report for the race!")
await self._race_report(ctx) await self._race_report(ctx)
@self.command() @self.command()
async def quali(ctx): async def quali(ctx):
if ctx.author.id == 581960756271251457 or \ #if ctx.author.id == 581960756271251457 or \
ctx.author.guild_permissions.administrator: # ctx.author.guild_permissions.administrator:
await ctx.send(":robot::peach: Ready to report on quali!") await ctx.send(":robot::peach: Ready to report on quali!")
await self._quali_report(ctx) await self._quali_report(ctx)
@self.command() @self.command()
async def practice(ctx): async def practice(ctx):
if ctx.author.id == 581960756271251457 or \ #if ctx.author.id == 581960756271251457 or \
ctx.author.guild_permissions.administrator: # ctx.author.guild_permissions.administrator:
await ctx.send(":robot::peach: Ready to report on practice!") await ctx.send(":robot::peach: Ready to report on practice!")
await self._practice_report(ctx) await self._practice_report(ctx)
@self.command() @self.command()
async def flap(ctx): async def flap(ctx):