main -> 2023.03.01 ohli24 버그 픽스 (.01. code cleanup)

This commit is contained in:
2023-03-01 18:01:39 +09:00
parent 3162911f1e
commit 10bd5e7412
6 changed files with 201 additions and 34 deletions

View File

@@ -7,12 +7,16 @@
# @Software: PyCharm
import os, sys, traceback, re, json, threading
import time
from datetime import datetime, date
import copy
import hashlib
import discord
# third-party
import requests
from discord_webhook import DiscordWebhook, DiscordEmbed
from lxml import html
from urllib import parse
import urllib
@@ -62,7 +66,7 @@ logger = P.logger
class LogicOhli24(LogicModuleBase):
db_default = {
"ohli24_db_version": "1",
"ohli24_db_version": "1.1",
"ohli24_url": "https://ohli24.org",
"ohli24_download_path": os.path.join(path_data, P.package_name, "ohli24"),
"ohli24_auto_make_folder": "True",
@@ -105,6 +109,11 @@ class LogicOhli24(LogicModuleBase):
super(LogicOhli24, self).__init__(P, "setting", scheduler_desc="ohli24 자동 다운로드")
self.name = "ohli24"
self.queue = None
self.last_post_title = ""
self.discord_webhook_url = "https://discord.com/api/webhooks/1071430127860334663/viCiM5ssS-U1_ONWgdWa-64KgvPfU5jJ8WQAym-4vkiyASB0e8IcnlLnxG4F40nj10kZ"
self.discord_color = "242424"
self.discord_title = "새로운 애니"
self.DISCORD_CHANNEL_ID = "1071430054023798958"
default_route_socketio(P, self)
@staticmethod
@@ -503,10 +512,7 @@ class LogicOhli24(LogicModuleBase):
# print(code)
whitelist_program = P.ModelSetting.get("ohli24_auto_code_list")
# whitelist_programs = [
# str(x.strip().replace(" ", ""))
# for x in whitelist_program.replace("\n", "|").split("|")
# ]
whitelist_programs = [
str(x.strip()) for x in whitelist_program.replace("\n", "|").split("|")
]
@@ -596,6 +602,8 @@ class LogicOhli24(LogicModuleBase):
# ret_data = LogicOhli24.get_auto_anime_info(self, url=url)
content_info = self.get_series_info(item, "", "")
logger.debug(content_info)
for episode_info in content_info["episode"]:
add_ret = self.add(episode_info)
if add_ret.startswith("enqueue"):
@@ -666,7 +674,7 @@ class LogicOhli24(LogicModuleBase):
else:
pass
logger.debug("url:::> %s", url)
# logger.debug("url:::> %s", url)
# self.current_headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)
# AppleWebKit/537.36 (KHTML, like Gecko) ' 'Chrome/96.0.4664.110 Whale/3.12.129.46 Safari/537.36',
@@ -933,6 +941,59 @@ class LogicOhli24(LogicModuleBase):
P.logger.error(traceback.format_exc())
return {"ret": "exception", "log": str(e)}
def check_for_new_post(self):
# Get the HTML content of the page
res = requests.get("https://ohli24.org/bbs/board.php?bo_table=ing")
soup = BeautifulSoup(res.content, "html.parser")
# Find the latest post on the page
latest_post = soup.find("div", class_="post-title").text
latest_post_image = (
soup.find("div", class_="img-item")
.find("img", class_="wr-img")
.get("src")
.replace("..", "https://ohli24.org")
)
logger.debug(f"latest_post:: {latest_post}")
logger.debug(f"self.last_post_title:: {self.last_post_title}")
logger.debug(f"latest_post_image:: {latest_post_image}")
# Compare the latest post with the last recorded post
if latest_post != self.last_post_title:
# If there is a new post, update the last recorded post
self.last_post_title = latest_post
# Send a notification to Discord channel
# discord_client = discord.Client()
# discord_client.run(self.DISCORD_BOT_TOKEN)
#
# async def on_ready():
# channel = discord_client.get_channel(self.DISCORD_CHANNEL_ID)
# await channel.send(f"A new post has been added: {latest_post}")
#
# discord_client.close()
webhook = DiscordWebhook(url=self.discord_webhook_url)
embed = DiscordEmbed(title=self.discord_title, color=self.discord_color)
embed.set_timestamp()
path = self.last_post_title
embed.set_image(url=latest_post_image)
embed.add_embed_field(name="", value=path, inline=True)
embed.set_timestamp()
webhook.add_embed(embed)
response = webhook.execute()
return self.last_post_title
return self.last_post_title
def send_notify(self):
logger.debug("send_notify() routine")
while True:
self.last_post_title = self.check_for_new_post()
logger.debug(self.last_post_title)
time.sleep(600)
# @staticmethod
def plugin_load(self):
try:
@@ -943,6 +1004,10 @@ class LogicOhli24(LogicModuleBase):
self.current_data = None
self.queue.queue_start()
logger.debug(P.ModelSetting.get_bool("ohli24_discord_notify"))
if P.ModelSetting.get_bool("ohli24_discord_notify"):
self.send_notify()
except Exception as e:
logger.error("Exception:%s", e)
logger.error(traceback.format_exc())