86 lines
No EOL
1.9 KiB
Python
86 lines
No EOL
1.9 KiB
Python
import importlib.util
|
|
import logging
|
|
import threading
|
|
import os
|
|
import time
|
|
|
|
from backend import backend
|
|
from backend.ig import IG
|
|
from backend.db import dbhelper
|
|
from backend.utils import ld_interface
|
|
from backend.utils import ld_picturemaker
|
|
from config.config import DEBUG, TMP, FRONTEND
|
|
#if DEBUG:
|
|
# from dotenv import load_dotenv
|
|
# load_dotenv()
|
|
|
|
|
|
def main():
|
|
# logging init
|
|
logging.basicConfig(
|
|
level=logging.DEBUG,
|
|
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
|
datefmt="%Y-%m-%d %H:%M:%S"
|
|
)
|
|
|
|
# logging
|
|
loaderlog = logging.getLogger("loader")
|
|
loaderlog.setLevel(level=logging.INFO)
|
|
|
|
# debug
|
|
if DEBUG:
|
|
loaderlog.info("DEBUG MODE ENABLED")
|
|
|
|
##################
|
|
|
|
# tmp dir
|
|
if not os.path.exists(TMP):
|
|
loaderlog.info("Temporary directory not found, creating...")
|
|
os.mkdir(TMP)
|
|
|
|
##################
|
|
|
|
# load interface module
|
|
ld_interface.init()
|
|
|
|
# load picture_maker module
|
|
ld_picturemaker.init()
|
|
|
|
##################
|
|
|
|
# init backend modules
|
|
## id2igid.db
|
|
loaderlog.info("Connecting to id2igid.db...")
|
|
dbhelper.init()
|
|
|
|
## instagram
|
|
loaderlog.info("Initializing IG...")
|
|
IG.init()
|
|
|
|
##################
|
|
|
|
# load frontend
|
|
loaderlog.info("Loading frontend")
|
|
spec = importlib.util.spec_from_file_location("frontend", FRONTEND)
|
|
femod = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(femod)
|
|
fe = threading.Thread(target=femod.main)
|
|
fe.start()
|
|
|
|
# load backend
|
|
loaderlog.info("Loading backend")
|
|
be = threading.Thread(target=backend.main)
|
|
be.start()
|
|
|
|
##################
|
|
|
|
# end
|
|
loaderlog.info("Loaded")
|
|
|
|
# infinity waiting - prevent main thread from exiting
|
|
while True:
|
|
time.sleep(60)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |