From 705f1eda83d2af88db01063e240c59e5b18195a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8A=E6=9D=89=E5=A4=8F=E7=9B=B8?= Date: Tue, 15 Jun 2021 22:57:47 +0800 Subject: [PATCH] Add files via upload --- config.json | 40 ++++++++++++++++++++++ main.py | 96 ++++------------------------------------------------- sendmsg.py | 11 ++++-- 3 files changed, 54 insertions(+), 93 deletions(-) create mode 100644 config.json diff --git a/config.json b/config.json new file mode 100644 index 0000000..949dcd2 --- /dev/null +++ b/config.json @@ -0,0 +1,40 @@ +/* 本文件仅供本地运行时使用 + 本文件格式使用json5标准 */ +{ + "version": "0.1.0", // 配置文件版本,谨慎修改 + "http_header": { + // http头部,访问B站时使用 注:User-Agent建议改为常用的浏览器UA(下面是google浏览器),其他的不改 + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36", + "Referer": "https://www.bilibili.com/", + "Connection": "keep-alive" + }, + "default": { + "send_msg": "签到" // 向UP主幽蓝伊梦的直播间发送消息(作用是点亮粉丝牌和增加其密度),值为字符串,为空字符串则不发送 + }, + "webhook": { + // 用于自定义消息推送,如果使用其他推送平台,请自行查阅相应平台数据格式,按照本模板添加到本配置中 + "enable": false, // 开关,需要开启请将本项设置为true + "http_header": { "User-Agent": "Mozilla/5.0" } // 定义http头部,访问消息推送接口时使用 + /*"hooks": { + "name": "server酱Turbo版消息推送", + "msg_separ": "\n\n", + "method": 1, + "url": "https://sc.ftqq.com/{key}.send", + "params": { + "text": "{title}", + "desp": "{msg}" + } + }*/ + }, + "log_file": "lulu.log", // 输出日志文件,不输出请留空,也可填写完整路径 + "log_console": true, // 是否把日志输出到控制台 + "users": { + // 账户配置 + "cookieDatas": { + // cookie获取方式见项目说明 + "SESSDATA": "", + "bili_jct": "", + "DedeUserID": "" + } + } +} diff --git a/main.py b/main.py index 4fc399f..56432fe 100644 --- a/main.py +++ b/main.py @@ -1,93 +1,15 @@ # -*- coding: utf-8 -*- -import sys, os, logging, json, sendmsg +import sys, os, logging from collections import OrderedDict from getopt import getopt from json5 import loads from BiliClient import BiliApi -from PyQt5.QtWidgets import QApplication, QMainWindow, QLineEdit, QMessageBox -from PyQt5 import QtGui -from mainwin import Ui_Form -#from push_message import webhook - +import sendmsg +# from push_message import webhook main_version = (0, 1, 0) main_version_str = '.'.join(map(str, main_version)) -class Mainwin(QMainWindow,Ui_Form): - def __init__(self,parent=None): - super(Mainwin, self).__init__(parent) - self.setupUi(self) - self.setWindowTitle("awa") - self.pushButton.clicked.connect(self.display) - try: - with open("data.json",'r') as f: - logdata = json.load(f) - if logdata[0]: - self.checkBox.setChecked(True) - self.lineEdit.setText(logdata[1]) - self.lineEdit_2.setText(logdata[2]) - self.lineEdit_3.setText(logdata[3]) - except: - pass - - def display(self): - SESSDATA = self.lineEdit.text() - bili_jct = self.lineEdit_2.text() - DedeUserID = self.lineEdit_3.text() - - maindata = {"version": "0.1.0", - "http_header": { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36","Referer": "https://www.bilibili.com/", - "Referer": "https://www.bilibili.com/", - "Connection": "keep-alive" - }, - "default": { - "send_msg": "签到" - }, - "webhook": { - "enable": False, - "http_header": {"User-Agent":"Mozilla/5.0"}, - }, - "log_file": "lulu.log", - "log_console": True, - "users": { - "cookieDatas":{ - "SESSDATA": SESSDATA, - "bili_jct": bili_jct, - "DedeUserID": DedeUserID - } - } - } - - with open("config.json","w") as f: - json.dump(maindata,f) - # with open("config.txt","r",encoding="UTF-8") as f: - # maindata = f.read().split("@") - - # maindata.insert(1,SESSDATA) - # maindata.insert(3,bili_jct) - # maindata.append(DedeUserID) - - # maindata_2 = "" - # for i in maindata: - # maindata_2 += i - # with open("config.json","w",1,"gbk") as f: - # f.write(maindata_2) - - startdata = [False,"","",""] - if self.checkBox.isChecked(): - startdata[0] = True - startdata[1] = SESSDATA - startdata[2] = bili_jct - startdata[3] = DedeUserID - with open("data.json","w") as f: - json.dump(startdata,f) - - try: - main_main() - QMessageBox.information(self,"消息","发送成功!",QMessageBox.Yes | QMessageBox.No) - except: - QMessageBox.warning(self,"警告","发送失败!详细请看日志(lulu.log)",QMessageBox.Yes | QMessageBox.No) def init_log(log_file: str, log_console: bool): '''初始化日志参数''' @@ -116,7 +38,7 @@ def init_message(configData: dict): try: init_log(configData["log_file"], configData["log_console"]) #if configData["webhook"]["enable"]: - #webhook.set(configData["webhook"]) + #webhook.set(configData["webhook"]) except Exception as e: print(f'初始化消息推送异常,原因为{str(e)},退出程序') sys.exit(1) @@ -196,7 +118,8 @@ def main(**kwargs): init_message(configData) #初始化消息推送 start(configData) #启动任务 -def main_main(): + +if __name__ == "__main__": kwargs = {} opts, args = getopt(sys.argv[1:], "hvc:l:", ["configfile=", "logfile="]) for opt, arg in opts: @@ -205,10 +128,3 @@ def main_main(): elif opt in ('-l', '--logfile'): kwargs["log"] = arg main(**kwargs) - -if __name__ == "__main__": - app = QApplication(sys.argv) - win = Mainwin() - win.show() - sys.exit(app.exec_()) - # main_main() diff --git a/sendmsg.py b/sendmsg.py index 7264491..98b3e8d 100644 --- a/sendmsg.py +++ b/sendmsg.py @@ -3,6 +3,7 @@ from BiliClient import BiliApi #from push_message import webhook + def send_msg_task(biliapi: BiliApi, msg: str, roomid: int = 1): rid = roomid retry = 2 @@ -16,7 +17,8 @@ def send_msg_task(biliapi: BiliApi, msg: str, roomid: int = 1): if ret['code'] == 0: rid = ret['data']['room_id'] else: - logging.warning(f'{biliapi.name}:获取房间{rid}的真实id失败,错误信息为{ret["message"]}') + logging.warning( + f'{biliapi.name}:获取房间{rid}的真实id失败,错误信息为{ret["message"]}') try: ret = biliapi.xliveMsgSend(rid, msg) @@ -31,10 +33,13 @@ def send_msg_task(biliapi: BiliApi, msg: str, roomid: int = 1): #webhook.addMsg(f'{biliapi.name}:在直播间{rid}发送信息成功\n\n') break else: - logging.warning(f'{biliapi.name}:在直播间{rid}发送信息失败,错误信息为{ret["message"]},重试') + logging.warning( + f'{biliapi.name}:在直播间{rid}发送信息失败,错误信息为{ret["message"]},重试' + ) retry -= 1 else: - logging.warning(f'{biliapi.name}:在直播间{rid}发送信息失败,错误信息为{ret["message"]},跳过') + logging.warning( + f'{biliapi.name}:在直播间{rid}发送信息失败,错误信息为{ret["message"]},跳过') #webhook.addTitle('Love lulu failure') #webhook.addMsg(f'{biliapi.name}:在直播间{rid}发送信息失败,错误信息为{ret["message"]},跳过\n\n') break \ No newline at end of file