-
Notifications
You must be signed in to change notification settings - Fork 0
/
anki_vac.py
56 lines (41 loc) · 1.41 KB
/
anki_vac.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
from anki_connect import AnkiConnect
from bing_api import *
from interface import GraphicInterface
from tts.tts_config import TTSConfig
import time
from enum import Enum
import json
BING_KEY = None
TTS_KEY = None
class Logger:
__instance = None
class LoggerHandler:
def __init__(self):
self.arq = open("log.txt", "a")
def __del__(self):
self.arq.close()
def write_log(self, text):
self.arq.write(text)
class LogType(Enum):
INFO = "[INFO] "
ERROR = "[ERROR] "
@classmethod
def log(cls, text: str, type: LogType = LogType.INFO):
if Logger.__instance is None:
Logger.__instance = Logger.LoggerHandler()
t = time.localtime()
current_time = time.strftime("%d/%m/%Y %H:%M:%S ", t)
Logger.__instance.write_log(f"[{current_time}]{type.value}{text}")
if __name__ == "__main__":
# Load config file
with open("config.json", "r", encoding="utf-8") as fp:
config = json.load(fp)
# Define APIs urls
BingImageAPI.BING_API = config["apis-urls"]["BING_API"]
TTSConfig.TTS_API = config["apis-urls"]["TTS_API"]
AnkiConnect.ANKI_CONNECT = config["apis-urls"]["ANKI_CONNECT"]
# Define APIs keys
BingImageAPI.BING_KEY = config["apis-keys"]["BING"]
TTSConfig.TTS_KEY = config["apis-keys"]["TTS"]
# Start graphic interface
GraphicInterface.start_main(config)