Files
gommi/lib/system/logic_site.py
2022-04-21 19:23:01 +09:00

101 lines
3.0 KiB
Python

# -*- coding: utf-8 -*-
#########################################################
# python
import os
import traceback
import logging
import platform
import time
# third-party
from flask import (
Blueprint,
request,
Response,
send_file,
render_template,
redirect,
jsonify,
)
# sjva 공용
from framework.logger import get_logger
from framework import path_app_root, path_data, socketio, scheduler
from framework.job import Job
from tool_base import d
# 패키지
from .plugin import logger, package_name
from .model import ModelSetting
class SystemLogicSite(object):
# pass
daum_cookie = None
@staticmethod
def process_ajax(sub, req):
try:
ret = {}
if sub == "site_daum_test":
pass
elif sub == "scheduler":
go = req.form["scheduler"]
if go == "true":
SystemLogicSite.scheduler_start()
else:
SystemLogicSite.scheduler_stop()
return jsonify(go)
except Exception as exception:
logger.error("Exception:%s", exception)
logger.error(traceback.format_exc())
ret["ret"] = False
ret["log"] = str(traceback.format_exc())
return jsonify(ret)
@staticmethod
def plugin_load():
SystemLogicSite.get_daum_cookies(force=True)
if ModelSetting.get_bool("site_daum_auto_start"):
SystemLogicSite.scheduler_start()
@staticmethod
def scheduler_function():
try:
data = SystemLogicSite.get_daum_cookie_by_selenium()
if data["ret"]:
ModelSetting.set("site_daum_cookie", data["data"])
SystemLogicSite.get_daum_cookies(force=True)
except Exception as exception:
logger.error("Exception:%s", exception)
logger.error(traceback.format_exc())
@staticmethod
def get_daum_cookies(force=False):
try:
if SystemLogicSite.daum_cookie is None or force:
ret = {}
tmp = ModelSetting.get("site_daum_cookie")
tmps = tmp.split(";")
for t in tmps:
t2 = t.split("=")
if len(t2) == 2:
ret[t2[0]] = t2[1]
SystemLogicSite.daum_cookie = ret
return SystemLogicSite.daum_cookie
except Exception as exception:
logger.error("Exception:%s", exception)
logger.error(traceback.format_exc())
return {
"TIARA": "gaXEIPluo-wWAFlwZN6l8gN3yzhkoo_piP.Kymhuy.6QBt4Q6.cRtxbKDaWpWajcyteRHzrlTVpJRxLjwLoMvyYLVi_7xJ1L"
}
daum_headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Language": "ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7",
}