minor fix, update hot patch

This commit is contained in:
BennyThink 2022-02-04 12:36:13 +08:00
parent 4bfbc93029
commit a2f29df98c
No known key found for this signature in database
GPG Key ID: 6CD0DBDA5235D481
6 changed files with 33 additions and 25 deletions

View File

@ -1,20 +1,19 @@
pyrogram==1.4.0
pyrogram==1.4.1
tgcrypto==1.2.3
yt-dlp==2022.1.21
yt-dlp==2022.2.4
APScheduler==3.8.1
beautifultable==1.0.1
ffmpeg-python==0.2.0
PyMySQL==1.0.2
celery==5.2.3
filetype==1.0.9
filetype==1.0.10
flower==1.0.0
psutil==5.9.0
influxdb==5.3.1
beautifulsoup4==4.10.0
fakeredis
supervisor
tgbot-ping
redis
requests
tqdm
fakeredis==1.7.0
supervisor==4.2.4
tgbot-ping==1.0.2
redis==4.0.2
requests==2.27.1
tqdm==4.62.3

View File

@ -72,7 +72,8 @@ class Redis:
self.r.hincrby("metrics", all_)
self.r.hincrby("metrics", today)
def generate_table(self, header, all_data: "list"):
@staticmethod
def generate_table(header, all_data: "list"):
table = BeautifulTable()
for data in all_data:
table.rows.append(data)
@ -107,7 +108,7 @@ class Redis:
fd = []
for key in self.r.keys("*"):
if re.findall(r"\d+", key):
if re.findall(r"^\d+$", key):
value = self.r.get(key)
date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(self.r.ttl(key) + time.time()))
fd.append([key, value, sizeof_fmt(int(value)), date])
@ -152,7 +153,7 @@ class Redis:
class MySQL:
vip_sql = """
create table if not exists VIP
create table if not exists vip
(
user_id bigint not null,
username varchar(256) null,
@ -187,7 +188,7 @@ class MySQL:
latest_video varchar(256) null,
constraint channel_pk
primary key (channel_id)
);
) CHARSET=utf8mb4;
"""
subscribe_sql = """
@ -195,12 +196,12 @@ class MySQL:
(
user_id bigint null,
channel_id varchar(256) null
);
) CHARSET=utf8mb4;
"""
def __init__(self):
if MYSQL_HOST:
self.con = pymysql.connect(host=MYSQL_HOST, user=MYSQL_USER, passwd=MYSQL_PASS, db="vip", charset="utf8mb4")
self.con = pymysql.connect(host=MYSQL_HOST, user=MYSQL_USER, passwd=MYSQL_PASS, db="ytdl", charset="utf8mb4")
else:
self.con = MagicMock()

View File

@ -97,7 +97,7 @@ def download_hook(d: dict, bot_msg):
raise ValueError(f"\nYour video is too large. "
f"{filesize} will exceed Telegram's max limit {sizeof_fmt(max_size)}")
percent = remove_bash_color(d.get("_percent_str", "N/A"))
# percent = remove_bash_color(d.get("_percent_str", "N/A"))
speed = remove_bash_color(d.get("_speed_str", "N/A"))
if ENABLE_VIP and not r.exists(key):
result, err_msg = check_quota(total, bot_msg.chat.id)

View File

@ -8,10 +8,10 @@
__author__ = "Benny <benny.think@gmail.com>"
import hashlib
import re
import logging
import math
import os
import re
import tempfile
import time
from unittest.mock import MagicMock
@ -93,9 +93,15 @@ class VIP(Redis, MySQL):
return "You have subscribed too many channels. Please upgrade to VIP to subscribe more channels."
data = self.get_channel_info(share_link)
self.cur.execute("INSERT IGNORE INTO channel values("
"%(link)s,%(title)s,%(description)s,%(channel_id)s,%(playlist)s,%(last_video)s)", data)
self.cur.execute("INSERT INTO subscribe values(%s,%s)", (user_id, data["channel_id"]))
channel_id = data["channel_id"]
self.cur.execute("select user_id from subscribe where user_id=%s and channel_id=%s", (user_id, channel_id))
if self.cur.fetchall():
raise ValueError("You have already subscribed this channel.")
self.cur.execute("INSERT IGNORE INTO channel values"
"(%(link)s,%(title)s,%(description)s,%(channel_id)s,%(playlist)s,%(last_video)s)", data)
self.cur.execute("INSERT INTO subscribe values(%s,%s)", (user_id, channel_id))
self.con.commit()
logging.info("User %s subscribed channel %s", user_id, data["title"])
return "Subscribed to {}".format(data["title"])

View File

@ -12,12 +12,12 @@ import os
import pathlib
import re
import subprocess
import sys
import tempfile
import threading
import time
from urllib.parse import quote_plus
import psutil
import requests
from apscheduler.schedulers.background import BackgroundScheduler
from celery import Celery
@ -287,17 +287,19 @@ def hot_patch(*args):
git_path = pathlib.Path().cwd().parent.as_posix()
logging.info("Hot patching on path %s...", git_path)
pip_install = "pip install -r requirements.txt"
unset = "git config --unset http.https://github.com/.extraheader"
pull_unshallow = "git pull origin --unshallow"
pull = "git pull"
subprocess.call(pip_install, shell=True, cwd=git_path)
subprocess.call(unset, shell=True, cwd=git_path)
if subprocess.call(pull_unshallow, shell=True, cwd=git_path) != 0:
logging.info("Already unshallow, pulling now...")
subprocess.call(pull, shell=True, cwd=git_path)
logging.info("Code is updated, applying hot patch now...")
psutil.Process().kill()
sys.exit(2)
def run_celery():

View File

@ -103,10 +103,10 @@ def subscribe_handler(client: "Client", message: "types.Message"):
if message.text == "/sub":
result = vip.get_user_subscription(chat_id)
else:
link = message.text.split(" ")[1]
link = message.text.split()[1]
try:
result = vip.subscribe_channel(chat_id, link)
except (IndexError,ValueError):
except (IndexError, ValueError):
result = f"Error: \n{traceback.format_exc()}"
client.send_message(chat_id, result or "You have no subscription.", disable_web_page_preview=True)