From 107a7155543ef106296e27ab728a0aad176dd78f Mon Sep 17 00:00:00 2001 From: Daphel Date: Thu, 20 Aug 2020 10:05:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=91=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E7=9A=84=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.py | 67 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/index.py b/index.py index 4b96980..c3795ca 100644 --- a/index.py +++ b/index.py @@ -1,10 +1,10 @@ #coding:utf-8 ''' @author: ZainCheung -@LastEditors: ZainCheung +@LastEditors: Daphel @description:网易云音乐全自动每日打卡云函数版 @Date: 2020-06-25 14:28:48 -@LastEditTime: 2020-06-26 17:38:18 +@LastEditTime: 2020-08-20 10:09:15 ''' from configparser import ConfigParser from threading import Timer @@ -15,6 +15,7 @@ import datetime import time import json import logging +import math logger = logging.getLogger() grade = [10,40,70,130,200,400,1000,3000,8000,20000] @@ -41,7 +42,7 @@ class Task(object): return response ''' - 登陆 + 登录 ''' def login(self): data = {"uin":self.uin,"pwd":self.pwd,"r":random.random()} @@ -56,10 +57,10 @@ class Task(object): if code==200: self.error = '' else: - self.error = '登陆失败,请检查账号' + self.error = '登录失败,请检查账号' self.cookies = response.cookies.get_dict() - self.log('登陆成功') - logger.info("登陆成功") + self.log('登录成功') + logger.info("登录成功") ''' 每日签到 @@ -130,26 +131,33 @@ class Task(object): self.tip = '还需听歌' + str(count-self.listenSongs) + '首即可升级' break else: - self.tip = '你已经听够20000首歌曲,如果登陆天数达到800天即可满级' + self.tip = '你已经听够20000首歌曲,如果登录天数达到800天即可满级' else: self.tip = '恭喜你已经满级!' if self.error == '': - state = '目前已完成签到,300百首歌也已听完' - self.title = '网易云听歌任务已完成' + state = ("- 目前已完成签到\n" + "- 今日共打卡" + str(self.dakanum) + "次\n" + "- 今日共播放" + str(self.dakaSongs) + "首歌\n" + "- 还需要打卡" + str(self.day) +"天") + self.title = ("网易云今日打卡" + str(self.dakaSongs) + "首,已播放" + str(self.listenSongs) + "首") else: state = self.error self.title = '网易云听歌任务出现问题!' - self.content = ("> tip:等级数据每天下午2点更新 \n\n" + self.content = ( "------\n" - "| 用户名 | " + str(self.name) + " |\n" - "| -------- | :----------------: |\n" - "| 当前等级 | " + str(self.level) + "级 |\n" - "| 累计播放 | " + str(self.listenSongs) + "首 |\n" - "| 升级提示 | " + self.tip + " |\n" + "#### 账户信息\n" + "- 用户名称:" + str(self.name) + "\n" + "- 当前等级:" + str(self.level) + "级\n" + "- 累计播放:" + str(self.listenSongs) + "首\n" + "- 升级提示:" + self.tip + "\n\n" "------\n" - "### 任务状态\n" + str(state) + "\n\n" - "### 考研倒计时\n距考研还有" + str(date) + "天,主人要加油学习啊\n" - "### 今日一句\n" + one + "\n\n") + "#### 任务状态\n" + str(state) + "\n\n" + "------\n" + "#### 打卡日志\n" + self.dakaSongs_list + "\n\n" + "------\n" + "#### 考研倒计时\n- 距考研还有" + str(date) + "天,主人要加油学习啊!\n\n" + "------\n" + "#### 今日一句\n- " + one + "\n\n") ''' 打印日志 @@ -157,20 +165,37 @@ class Task(object): def log(self, text): time_stamp = datetime.datetime.now() print(time_stamp.strftime('%Y.%m.%d-%H:%M:%S') + ' ' + str(text)) + self.time =time_stamp.strftime('%H:%M:%S') + self.list.append("- [" + self.time + "] " + str(text) + "\n\n") ''' 开始执行 ''' def start(self): try: + self.list = [] + self.list.append("- 初始化完成\n\n") self.login() self.sign() self.detail() - for i in range(1,3): + counter = self.listenSongs + for i in range(1,10): self.daka() - self.log('用户:' + self.name + ' 第' + str(i) + '次打卡成功,即将休眠30秒') - logger.info('用户:' + self.name + ' 第' + str(i) + '次打卡成功,即将休眠30秒') + #self.log('用户:' + self.name + ' 第' + str(i) + '次打卡成功,即将休眠10秒') + self.log('第' + str(i) + '次打卡成功,即将休眠10秒') time.sleep(10) + self.dakanum = i + self.detail() + self.dakaSongs = self.listenSongs - counter + self.log('今日已打卡播放' + str(self.dakaSongs) + '首') + if self.dakaSongs == 300: + break + if self.listenSongs >= 20000: + self.day = 0 + else: + self.day = math.ceil((20000 - self.listenSongs)/300) + self.list.append("- 打卡结束,消息推送\n\n") + self.dakaSongs_list = ''.join(self.list) self.server() except: self.log('用户任务执行中断,请检查账号密码是否正确') -- GitLab