-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
52 lines (39 loc) · 1.29 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
import asyncio
import datetime
import dateutil.relativedelta
import puzzle
import matrix
import database
async def main():
client = matrix.Client()
print("Checking if database is initialized... ", end="")
if not database.is_initialized():
print("Not initialized")
print("Initializing... ", end="")
database.initialize()
print("Initialized")
yesterday = datetime.date.today() - dateutil.relativedelta.relativedelta(days=1)
print(f"Receiving puzzle for date {yesterday} from database... ", end="")
old_puzzle = database.retrieve_puzzle(yesterday)
if old_puzzle:
print("Found")
print("Sending solution for yesterday's puzzle... ", end="")
await client.send_solution(old_puzzle)
print("Ok")
else:
print("Not found")
print("Fetching today's puzzle... ", end="")
new_puzzle = puzzle.get_daily_puzzle()
print("Ok")
print("Storing today's puzzle in the database... ", end="")
database.store_puzzle(new_puzzle)
print("Ok")
print("Sending board to group... ", end="")
await client.send_board(new_puzzle)
print("Ok")
await client.close()
if __name__ == "__main__":
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
asyncio.run(main())