利用腾讯云函数实现和鲸社区每日自动登录

请添加图片描述

和鲸社区算是国内比较不错的机器学习算力平台,可以通过每日登录积累成长值,每月还会给鲸币奖励,有一段时间每天都会登登陆一次,但是有时候还是会忘记。最近根据腾讯云Serverless部署云函数实现自动登录,解放双手。

首先每次登陆后将进行微信推送,我采用的是pushplus平台,获取token即可。

微信推送

# 从pushplus平台获取token
token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
def sendToWechat(title, content):
    url = 'http://www.pushplus.plus/send'
    headers = {
    
    'Content-Type': 'application/json'}
    data = {
    
    
        "token": token,
        "title": title,
        "content": content
    }
    body = json.dumps(data).encode(encoding='utf-8')
    requests.post(url, data=body, headers=headers)

登录并获取鲸币值:

def login():
    login_info = {
    
    
        "identity": "[email protected]",		#你的注册邮箱
        "password": "xxxxxxxxxx"					#你的登录密码
    }
    headers = {
    
    
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36',
        'referer': 'https://www.heywhale.com/auth/login?redirect=https%3A%2F%2Fwww.heywhale.com%2Fhome%2Fproject'
    }
    session.post(url="https://www.heywhale.com/api/auth/loginByPassword", data=login_info, headers=headers)
    session.get(url='https://www.heywhale.com/api/auth/login')
    resp = session.get(url='https://www.heywhale.com/api/wallets', params={
    
    
        'Type': 'WHALECOIN'
    })
    return resp

主函数部分

# -*- coding: utf8 -*-
# index.py

import json
import requests

session = requests.session()
# 本地运行将参数删掉
def main_handler(event, content):
    resp = login()
    if resp is not None:
        title = '登陆完毕'  # 标题内容
        content = f'登陆完毕,现在的鲸币余额为:{resp.json()["WHALECOIN"]}'  # 正文内容
        sendToWechat(title, content)
        print(resp.json()["WHALECOIN"])
    return resp.json()["WHALECOIN"]

部署方式

1、注册腾讯云账号
2、进入控制台搜索云函数并打开,接下来就是微信扫码认证之类的操作
3、点击"新建"按钮创建云函数,
请添加图片描述
按照下图配置云函数
请添加图片描述
接下来我们在本地将代码环境配置好,我们使用了requests库,在项目目录下打开cmd执行:

pip3 install requests -t .

接下来我们的项目会成为这个样子
请添加图片描述
接下来我们在云函数代码部分选择上传文件夹,将项目文件夹上传,单击完成即可。
请添加图片描述
为了保证每日执行,我们要配置一个触发器,在左侧选择触发管理,单击创建触发器
请添加图片描述
在这里插入图片描述
提交后就配置成了每天8点自动登录,修改时间可以修改触发器的Cron表达式。

接下来就开启了解放双手自动登录的快乐之路了。

猜你喜欢

转载自blog.csdn.net/BWQ2019/article/details/122748316