Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Song-Xin233 authored Jun 15, 2021
1 parent 4f2acb8 commit 705f1ed
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 93 deletions.
40 changes: 40 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -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": ""
}
}
}
96 changes: 6 additions & 90 deletions main.py
Original file line number Diff line number Diff line change
@@ -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):
'''初始化日志参数'''
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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()
11 changes: 8 additions & 3 deletions sendmsg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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

0 comments on commit 705f1ed

Please sign in to comment.