diff --git a/README.md b/README.md index c03dc39b..f46291bc 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ -### 使用文档: https://zaincheung.gitee.io/netease-cloud +### 使用文档: [https://zaincheung.github.io/netease-cloud](https://zaincheung.github.io/netease-cloud) diff --git a/account.json b/account.json index bc4f37eb..46cd21eb 100644 --- a/account.json +++ b/account.json @@ -1,26 +1,35 @@ [ { + "countrycode": 86, "account": "ZainCheung@163.com", "password": "10ca5e4c316f81c5d9b56702********", "sckey": "SCU97783T70c13167b4daa422f4d419a765eb4ebb5ebc9********", "pushmethod": "", "appToken": "", - "wxpusheruid": "" + "wxpusheruid": "", + "barkServer": "https://api.day.app", + "barkKey": "" }, { + "countrycode": 86, "account": "150********", "password": "bfa834f7de58cb650ca01edb********", "sckey": "SCU97783T70c13167b4daa422f4d419a765eb4ebb5ebc9********", "pushmethod": "", "appToken": "", - "wxpusheruid": "" + "wxpusheruid": "", + "barkServer": "https://api.day.app", + "barkKey": "" }, { + "countrycode": 86, "account": "132********", "password": "f391235b15781c95384cd5bb********", "sckey": "SCU97783T70c13167b4daa422f4d419a765eb4ebb5ebc9********", "pushmethod": "", "appToken": "", - "wxpusheruid": "" + "wxpusheruid": "", + "barkServer": "https://api.day.app", + "barkKey": "" } ] \ No newline at end of file diff --git a/docs/attention/README.md b/docs/attention/README.md index 07c4025d..6b7a2911 100644 --- a/docs/attention/README.md +++ b/docs/attention/README.md @@ -4,7 +4,7 @@ 一定要绑定微信才会有效果 -Server酱的官网地址:[http://sc.ftqq.com/](http://sc.ftqq.com/) +Server酱的[官网地址](https://sct.ftqq.com/r/13288) ### MD5 @@ -36,4 +36,4 @@ time.sleep(30) ### 初衷 -使用网易云也有挺久了,听的歌也挺多,但总是会听重复的歌,而重复的歌又不算进等级里去,所以还是很想升级的。 \ No newline at end of file +使用网易云也有挺久了,听的歌也挺多,但总是会听重复的歌,而重复的歌又不算进等级里去,所以还是很想升级的。 diff --git a/index.py b/index.py index fe7a15a4..9f9d5d8d 100644 --- a/index.py +++ b/index.py @@ -8,7 +8,7 @@ ''' from configparser import ConfigParser from threading import Timer -import requests +import requests import random import hashlib import datetime @@ -22,11 +22,11 @@ api = '' class Task(object): - + ''' 对象的构造函数 ''' - def __init__(self, uin, pwd, pushmethod, sckey, appToken, wxpusheruid, countrycode=86): + def __init__(self, uin, pwd, pushmethod, sckey, appToken, wxpusheruid, barkServer, barkKey, countrycode): self.uin = uin self.pwd = pwd self.countrycode = countrycode @@ -34,6 +34,10 @@ def __init__(self, uin, pwd, pushmethod, sckey, appToken, wxpusheruid, countryco self.sckey = sckey self.appToken = appToken self.wxpusheruid = wxpusheruid + self.barkServer = barkServer + if barkServer == "": + self.barkServer = "https://api.day.app" + self.barkKey = barkKey ''' 带上用户的cookie去发送数据 url:完整的URL路径 @@ -100,7 +104,7 @@ def detail(self): Wxpusher推送 ''' def wxpusher(self): - if (self.appToken == '' or self.wxpusheruid == ''): + if self.appToken == '' or self.wxpusheruid == '': self.log('未填写WxPusher推送所需参数,请检查') return self.diyText() # 构造发送内容 @@ -118,6 +122,27 @@ def wxpusher(self): else: self.log('用户:' + self.name + ' WxPusher推送失败,请检查appToken和uid是否正确') + ''' + Bark推送 + ''' + def bark(self): + if self.barkServer == '' or self.barkKey == '': + self.log('未填写Bark推送所需参数,请检查') + return + self.diyText() # 构造发送内容 + url = self.barkServer+'/push' + data = json.dumps({ + "title": self.title, + "body": self.content, + "device_key": self.barkKey, + "ext_params": {"group": "网易云签到"} + }) + response = requests.post(url, data=data, headers={'Content-Type': 'application/json;charset=UTF-8'}) + if (response.json()['message']) == 'success': + self.log('用户:' + self.name + ' Bark推送成功') + else: + self.log('用户:' + self.name + ' bark推送失败,请检查appToken和uid是否正确') + ''' 自定义要推送到微信的内容 title:消息的标题 @@ -131,17 +156,17 @@ def wxpusher(self): def server(self): if self.sckey == '': return - self.diyText() # 构造发送内容 + self.diyText() # 构造发送内容 data = { - "text":self.title, - "desp":self.content + "text" : self.title, + "desp" : self.content } - if (self.pushmethod.lower() == 'scturbo'): #Server酱 Turbo版 + if self.pushmethod.lower() == 'scturbo': #Server酱 Turbo版 url = 'https://sctapi.ftqq.com/' + self.sckey + '.send' response = requests.post(url, data=data, headers = {'Content-type': 'application/x-www-form-urlencoded'}) errno = response.json()['data']['errno'] else: #Server酱 普通版 - url = 'http://sc.ftqq.com/' + self.sckey + '.send' + url = 'https://sct.ftqq.com/' + self.sckey + '.send' response = requests.post(url, data=data, headers = {'Content-type': 'application/x-www-form-urlencoded'}) errno = response.json()['errno'] if errno == 0: @@ -210,7 +235,7 @@ def start(self): self.sign() self.detail() counter = self.listenSongs - for i in range(1,10): + for i in range(1, 10): self.daka() #self.log('用户:' + self.name + ' 第' + str(i) + '次打卡成功,即将休眠10秒') self.log('第' + str(i) + '次打卡成功,即将休眠10秒') @@ -229,14 +254,16 @@ def start(self): self.dakaSongs_list = ''.join(self.list) if self.pushmethod.lower() == 'wxpusher': self.wxpusher() + elif self.pushmethod.lower() == 'bark': + self.bark() else: self.server() except: self.log('用户任务执行中断,请检查账号密码是否正确') else: self.log('用户:' + self.name + ' 今日任务已完成') - - + + ''' 初始化:读取配置,配置文件为init.config 返回字典类型的配置对象 @@ -255,18 +282,22 @@ def init(): sckey = config['setting']['sckey'] appToken = config['setting']['appToken'] wxpusheruid = config['setting']['wxpusheruid'] + barkServer = config['setting']['barkServer'] + barkKey = config['setting']['barkKey'] logger.info('配置文件读取完毕') conf = { 'uin': uin, 'pwd': pwd, 'countrycode': countrycode, 'api': api, - 'md5Switch': md5Switch, + 'md5Switch': md5Switch, 'peopleSwitch':peopleSwitch, 'pushmethod':pushmethod, 'sckey':sckey, 'appToken':appToken, - 'wxpusheruid':wxpusheruid + 'wxpusheruid':wxpusheruid, + 'barkServer':barkServer, + 'barkKey':barkKey } return conf @@ -304,7 +335,7 @@ def check(): 任务池 ''' def taskPool(): - + config = init() check() # 每天对api做一次检查 if config['peopleSwitch'] is True: @@ -312,7 +343,7 @@ def taskPool(): account = loadJson("account.json") for man in account: logger.info('账号: ' + man['account'] + ' 开始执行\n========================================') - task = Task(man['account'], man['password'], man['pushmethod'],man['sckey'], man['appToken'], man['wxpusheruid']) + task = Task(man['account'], man['password'], man['pushmethod'], man['sckey'], man['appToken'], man['wxpusheruid'], man['barkServer'], man['barkKey'], man['countrycode']) task.start() time.sleep(10) logger.info('所有账号已全部完成任务,服务进入休眠中,等待明天重新启动') @@ -321,7 +352,7 @@ def taskPool(): if config['md5Switch'] is True: logger.info('MD5开关已打开,即将开始为你加密,密码不会上传至服务器,请知悉') config['pwd'] = md5(config['pwd']) - task = Task(config['uin'], config['pwd'], config['pushmethod'], config['sckey'], config['appToken'], config['wxpusheruid'], config['countrycode']) + task = Task(config['uin'], config['pwd'], config['pushmethod'], config['sckey'], config['appToken'], config['wxpusheruid'], config['barkServer'], config['barkKey'], config['countrycode']) task.start() ''' @@ -329,3 +360,6 @@ def taskPool(): ''' def main(event,content): taskPool() + +if __name__ == '__main__': + taskPool() diff --git a/init.config b/init.config index a3029f25..9ddd944f 100644 --- a/init.config +++ b/init.config @@ -16,7 +16,7 @@ countrycode = 86 [setting] # 接口API,开关的选项只有 True 和 False # 如需使用本项目还请自行部署API,地址:https://github.com/ZainCheung/netease-cloud-api -api = +api = # 密码是否需要MD5加密,如果是明文密码一定要打开 # true 需要, 则直接将你的密码(明文)填入password,程序会替你进行加密 @@ -32,6 +32,7 @@ peopleSwitch = false # 可选参数wxpusher、SCTurbo或留空 # wxpusher: 使用 WxPusher 推送 # SCTurbo: 使用 Server酱Turbo版 推送 +# Bark: 使用 Bark 推送 # 留空:使用 Server酱免费版 推送或不推送 pushmethod = @@ -43,4 +44,8 @@ sckey = SCU97783T70c13167b4daa422f4d419a765eb4ebb5ebc9******** # Wxpusher 推送参数,需要将pushmethod指定为wxpusher,应用和uid的免费申请参考:https://wxpusher.zjiecode.com/ appToken = AT_6kBmt*************************** -wxpusheruid = UID_t*************************** \ No newline at end of file +wxpusheruid = UID_t*************************** + +# Bark 推送参数, 请参考https://github.com/Finb/Bark, 公用默认服务器为https://api.day.app/ +barkServer = https://api.day.app +barkKey = \ No newline at end of file diff --git a/main.py b/main.py index d67099de..fb2ad8b4 100644 --- a/main.py +++ b/main.py @@ -32,7 +32,8 @@ class Task(object): ''' 对象的构造函数 ''' - def __init__(self, uin, pwd, pushmethod, sckey, appToken, wxpusheruid, countrycode=86): + + def __init__(self, uin, pwd, pushmethod, sckey, appToken, wxpusheruid, barkServer, barkKey, countrycode): self.uin = uin self.pwd = pwd self.countrycode = countrycode @@ -40,6 +41,10 @@ def __init__(self, uin, pwd, pushmethod, sckey, appToken, wxpusheruid, countryco self.sckey = sckey self.appToken = appToken self.wxpusheruid = wxpusheruid + self.barkServer = barkServer + if barkServer == "": + self.barkServer = "https://api.day.app" + self.barkKey = barkKey ''' 带上用户的cookie去发送数据 url:完整的URL路径 @@ -132,6 +137,27 @@ def wxpusher(self): self.log('用户:' + self.name + ' WxPusher推送失败,请检查appToken和uid是否正确') logging.info('用户:' + self.name + ' WxPusher推送失败,请检查appToken和uid是否正确') + ''' + Bark推送 + ''' + def bark(self): + if self.barkServer == '' or self.barkKey == '': + self.log('未填写Bark推送所需参数,请检查') + return + self.diyText() # 构造发送内容 + url = self.barkServer+'/push' + data = json.dumps({ + "title": self.title, + "body": self.content, + "device_key": self.barkKey, + "ext_params": {"group": "网易云签到"} + }) + response = requests.post(url, data=data, headers={'Content-Type': 'application/json;charset=UTF-8'}) + if (response.json()['message']) == 'success': + self.log('用户:' + self.name + ' Bark推送成功') + else: + self.log('用户:' + self.name + ' bark推送失败,请检查appToken和uid是否正确') + ''' 自定义要推送到微信的内容 title:消息的标题 @@ -229,11 +255,11 @@ def start(self): self.detail() counter = self.listenSongs self.list.append("- 开始打卡\n\n") - for i in range(1,10): + for i in range(1, 10): self.daka() # self.log('用户:' + self.name + ' 第' + str(i) + '次打卡成功,即将休眠30秒') self.log('第' + str(i) + '次打卡成功') - logging.info('用户:' + self.name + ' 第' + str(i) + '次打卡成功,即将休眠30秒') + logging.info('用户:' + self.name + ' 第' + str(i) + '次打卡成功,即将休眠10秒') time.sleep(10) self.dakanum =i self.detail() @@ -252,6 +278,8 @@ def start(self): self.dakaSongs_list = ''.join(self.list) if self.pushmethod.lower() == 'wxpusher': self.wxpusher() + elif self.pushmethod.lower() == 'bark': + self.bark() else: self.server() except: @@ -280,6 +308,8 @@ def init(): sckey = config['setting']['sckey'] appToken = config['setting']['appToken'] wxpusheruid = config['setting']['wxpusheruid'] + barkServer = config['setting']['barkServer'] + barkKey = config['setting']['barkKey'] print('配置文件读取完毕') logging.info('配置文件读取完毕') conf = { @@ -292,7 +322,9 @@ def init(): 'pushmethod':pushmethod, 'sckey':sckey, 'appToken':appToken, - 'wxpusheruid':wxpusheruid + 'wxpusheruid':wxpusheruid, + 'barkServer':barkServer, + 'barkKey':barkKey } return conf @@ -342,7 +374,7 @@ def taskPool(): for man in account: print('账号: ' + man['account'] + ' 开始执行') logging.info('账号: ' + man['account'] + ' 开始执行========================================') - task = Task(man['account'], man['password'], man['pushmethod'],man['sckey'], man['appToken'], man['wxpusheruid']) + task = Task(man['account'], man['password'], man['pushmethod'], man['sckey'], man['appToken'], man['wxpusheruid'], man['barkServer'], man['barkKey'], man['countrycode']) task.start() time.sleep(10) print('所有账号已全部完成任务,服务进入休眠中,等待明天重新启动') @@ -354,7 +386,7 @@ def taskPool(): print('MD5开关已打开,即将开始为你加密,密码不会上传至服务器,请知悉') logging.info('MD5开关已打开,即将开始为你加密,密码不会上传至服务器,请知悉') config['pwd'] = md5(config['pwd']) - task = Task(config['uin'], config['pwd'], config['pushmethod'], config['sckey'], config['appToken'], config['wxpusheruid'], config['countrycode']) + task = Task(config['uin'], config['pwd'], config['pushmethod'], config['sckey'], config['appToken'], config['wxpusheruid'], config['barkServer'], config['barkKey'], config['countrycode']) task.start() '''