niming_igapi/app.py
2024-12-17 19:06:40 +00:00

49 lines
1.1 KiB
Python

import os
import sys
import asyncio
import threading
import logging
from sqlalchemy import create_engine
from instagrapi import Client
# from dotenv import load_dotenv
from ig import IG
from db import dbhelper
from db.pgclass import Base
from grpcServer import grpcServer, anoth
from utils.const import DEBUG, TMP_DIR
# load_dotenv()
# logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s | [%(levelname)s] %(name)s - %(message)s'
)
if DEBUG:
logging.info("===== DEBUG MODE =====")
# tmp dir
if not os.path.exists(TMP_DIR):
os.mkdir(TMP_DIR)
# Database
PG_HOST = os.environ.get("PG_HOST", None).strip()
logging.info("Connecting to Database")
dbhelper.db = dbhelper.DB(create_engine(PG_HOST))
Base.metadata.create_all(dbhelper.db._engine)
# IG Login
IG.init(Client())
if not DEBUG and not IG.login():
sys.exit(0)
# run grpc
if __name__ == "__main__":
# upload / delete processor
threading.Thread(target=anoth.run).start()
# grpc main
asyncio.get_event_loop().run_until_complete(grpcServer.serve())