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