-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
59 lines (40 loc) · 1.55 KB
/
main.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
53
54
55
56
57
58
59
import socket
import logging
import asyncio
import kahoot2 as libkahoot
import kahoot_integration
import pygame # type: ignore
import qrcode # type: ignore
from sys import argv
from threading import Thread
from queue import Queue
from typing import Any
from qr_screen import qr_screen
logging.basicConfig(level=logging.INFO)
if len(argv) < 2:
logging.error("Pass the WIFI SSID in the first argument ans then we'll talk")
exit(1)
SSID = argv[1]
server = libkahoot.Server()
kahoot_queue: Queue[Any] = Queue()
loop = asyncio.new_event_loop()
def start_background_loop(loop: asyncio.AbstractEventLoop) -> None:
asyncio.set_event_loop(loop)
loop.run_forever()
async def libkahoot_main() -> None:
logging.basicConfig(level=logging.INFO)
logging.info("Starting the kahoot server")
kahoot_integration.setup_callbacks(kahoot_queue, server.game)
await server.start(8080)
kahoot_thread = Thread(target=start_background_loop, args=[loop], daemon=True)
kahoot_thread.start()
asyncio.run_coroutine_threadsafe(libkahoot_main(), loop)
pygame.init()
display_info = pygame.display.Info()
logging.info(f"Display size: {display_info.current_w}x{display_info.current_h}")
SCREEN = pygame.display.set_mode((1400, 1000))#, pygame.FULLSCREEN)
#SCREEN = pygame.display.set_mode((display_info.current_w, display_info.current_h), pygame.FULLSCREEN)
pygame.display.set_caption("Subscribe to @neomiusli on Telegram")
LOCAL_IP = socket.gethostbyname(socket.gethostname())
logging.info(f"Local IP: {LOCAL_IP}")
qr_screen(SCREEN, SSID, LOCAL_IP, kahoot_queue, server.game)