Use Tencent cloud function to realize daily automatic login with Whale Community

Please add a picture description

Hejing Community is a relatively good machine learning computing power platform in China. It can accumulate growth value through daily login, and will also give Whale Coin rewards every month. For a period of time, it will log in once a day, but sometimes it still forgets. Recently, cloud functions are deployed according to Tencent Cloud Serverless to realize automatic login and free hands.

First of all, WeChat will be pushed after each login. I use the pushplus platform and get the token.

WeChat push

# 从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)

Login and get whale value:

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

main function part

# -*- 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"]

Deployment method

1. Register a Tencent Cloud account.
2. Enter the console to search for cloud functions and open them. Next, you will perform operations such as WeChat scanning and authentication. 3.
Click the "New" button to create a cloud function, and configure the cloud function
Please add a picture description
as shown in the figure below. Next, we will create a cloud function
Please add a picture description
locally. After configuring the code environment, we use the requests library and open cmd in the project directory to execute:

pip3 install requests -t .

Next, our project will look like this
Please add a picture description
Next, we select the upload folder in the cloud function code section, upload the project folder, and click Finish.
Please add a picture description
In order to ensure daily execution, we need to configure a trigger, select Trigger Management on the left, click Create Trigger, and
Please add a picture description
insert image description here
after submitting, it is configured to automatically log in at 8 o'clock every day, and the Cron expression of the trigger can be modified by modifying the time.

The next step is to start the happy road of freeing hands and automatically logging in.

Guess you like

Origin blog.csdn.net/BWQ2019/article/details/122748316