Compare commits

...

2 Commits

Author SHA1 Message Date
5b58bfbb84 Added binger. Fixed issue with delta string. 2024-03-07 21:00:01 -05:00
b9f10ebb0e added variety of free squares 2024-02-17 10:25:31 -05:00
23 changed files with 71 additions and 19 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)

17
bingo.py Normal file → Executable file
View File

@ -10,13 +10,13 @@ class Bingo:
self.X_OFFSET = 10
self.Y_OFFSET = 110
self.SQUARES_PATH = "bingo_images/squares/*.png"
self.FREE_SQUARE_PATH = "bingo_images/free_space.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/"
self.square_files = glob.glob(self.SQUARES_PATH)
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:
@ -27,17 +27,18 @@ class Bingo:
for y in range(5):
for x in range(5):
square_file = ""
# If this is the center square, use the free square
# If this is the center square, pick a random free square
if x == 2 and y == 2:
square_file = self.FREE_SQUARE_PATH
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(self.square_files))
rand_file_idx = randrange(len(square_files))
while rand_file_idx in used_files:
rand_file_idx = randrange(len(self.square_files))
rand_file_idx = randrange(len(square_files))
square_file = self.square_files[rand_file_idx]
square_file = square_files[rand_file_idx]
used_files.add(rand_file_idx)
with Image.open(square_file) as square:

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 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__':