Added binger. Fixed issue with delta string.

This commit is contained in:
tamservo 2024-03-07 21:00:01 -05:00
parent b9f10ebb0e
commit 5b58bfbb84
19 changed files with 62 additions and 11 deletions

BIN
bing/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 KiB

BIN
bing/10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 383 KiB

BIN
bing/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 KiB

BIN
bing/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 444 KiB

BIN
bing/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 KiB

BIN
bing/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 281 KiB

BIN
bing/6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 356 KiB

BIN
bing/7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 KiB

BIN
bing/8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 KiB

BIN
bing/9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 KiB

26
binger.py Executable file
View 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)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 64 KiB

View File

@ -2,6 +2,7 @@
import asyncio
from bingo import Bingo
import binger
import collections.abc
import datetime
import json
@ -619,18 +620,26 @@ class Robottas(commands.Bot):
hour_str = "hour"
day_str = "day"
delta_str = str(delta)
(days, junk, rest) = delta_str.split(" ")
rest = rest.split(".")[0]
(hours, minutes, seconds) = rest.split(":")
(hours, minutes, seconds) = (-1, -1, -1)
(days, rest) = (0, "")
if int(days) > 1:
delta_str = str(delta)
if " " in delta_str:
(days, _, rest) = delta_str.split(" ")
rest = rest.split(".")[0]
(hours, minutes, seconds) = rest.split(":")
else:
rest = delta_str.split(".")[0]
(hours, minutes, seconds) = rest.split(":")
if int(days) != 1:
day_str = "days"
if int(minutes) > 1:
if int(minutes) != 1:
min_str = "minutes"
if int(hours) > 1:
if int(hours) != 1:
hour_str = "hours"
return f"{days} {day_str} {hours} {hour_str} {minutes} {min_str}"
@ -647,13 +656,13 @@ class Robottas(commands.Bot):
query = 'select * from schedule where date_start > ? ' + \
'order by date_start asc limit 1'
cur.execute(query, (now_str,))
rows = cur.fetchall()
for row in rows:
t2 = datetime.datetime.fromisoformat(row[3] + "+00:00")
delta = t2 - t1
delta_str = self.get_delta_str(delta)
message = f"The next event is Round {row[5]}: {row[1]} in {row[4]} which is {delta_str} from now."
@ -661,8 +670,9 @@ class Robottas(commands.Bot):
break # There should only be one row anyway
except:
except Exception as e:
await ctx.send("Sorry, hit the wall trying to find the answer...")
print(e, file=sys.stderr)
async def report_next_race(self, ctx):
@ -813,6 +823,12 @@ class Robottas(commands.Bot):
con.close()
async def show_bing(self, ctx):
(image, count) = binger.get_image_count()
await self.send_image(ctx, image)
await ctx.send(f"Bing count: {count}")
def __init__(self):
# Set debug or not
self.debug = True
@ -999,7 +1015,10 @@ class Robottas(commands.Bot):
"The following register / unregister scheduled next race / event messages.\n" +
"!register_next_race_alerts - get an alert for the next race on Monday.\n" +
"!register_next_event_alerts - get an alert for the next event on Monday.\n" +
"!unregister_alerts - stop getting alerts on this channel.\n"
"!unregister_alerts - stop getting alerts on this channel.\n" +
"!bingo_card - get a random bingo card.\n" +
"!bingo - announce that you've won bingo.\n" +
"!bing - bing counter."
)
@self.command()
@ -1295,7 +1314,13 @@ class Robottas(commands.Bot):
async def bingo_card(ctx):
card_file = self.bingo.get_card()
await self.send_image(ctx, card_file)
pathlib.Path.unlink(card_file)
os.remove(card_file)
# Big counter
@self.command()
async def bing(ctx):
await self.show_bing(ctx)
if __name__ == '__main__':