forked from huangshihai/mimotion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
92df0ef
commit 0eaa23c
Showing
1 changed file
with
98 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,98 @@ | ||
name: 刷步数 | ||
|
||
on: | ||
#push: | ||
# branches: [ main ] | ||
#pull_request: | ||
# branches: [ main ] | ||
schedule: | ||
- cron: '0 0,4,7,10,12,14 * * *' | ||
watch: | ||
types: started | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout codes | ||
uses: actions/checkout@v2 | ||
- name: Update system and install zsh | ||
run: | | ||
sudo -E apt-get -qq update | ||
sudo -E apt-get install zsh -y | ||
- name: 初始化Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.8 | ||
|
||
- name: 开始 | ||
run: | | ||
pip3 install requests | ||
user='${{ secrets.USER }}' | ||
passwd='${{ secrets.PWD }}' | ||
open_get_weather='${{ secrets.OPEN_GET_WEATHER }}' | ||
area='${{ secrets.AREA }}' | ||
python3 main.py ${user} ${passwd} ${open_get_weather} ${area} | ||
#运动步数修改 | ||
|
||
import requests | ||
import json | ||
import hashlib | ||
import time | ||
import datetime | ||
|
||
|
||
class LexinSport: | ||
def __init__(self, username, password, step): | ||
self.username = username | ||
self.password = password | ||
self.step = step | ||
|
||
# 登录 | ||
def login(self): | ||
url = 'https://sports.lifesense.com/sessions_service/login?systemType=2&version=4.6.7' | ||
data = {'loginName': self.username, 'password': hashlib.md5(self.password.encode('utf8')).hexdigest(), | ||
'clientId': '49a41c9727ee49dda3b190dc907850cc', 'roleType': 0, 'appType': 6} | ||
headers = { | ||
'Content-Type': 'application/json; charset=utf-8', | ||
'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 7.1.2; LIO-AN00 Build/LIO-AN00)' | ||
} | ||
response_result = requests.post(url, data=json.dumps(data), headers=headers) | ||
status_code = response_result.status_code | ||
response_text = response_result.text | ||
# print('登录状态码:%s' % status_code) | ||
# print('登录返回数据:%s' % response_text) | ||
if status_code == 200: | ||
response_text = json.loads(response_text) | ||
user_id = response_text['data']['userId'] | ||
access_token = response_text['data']['accessToken'] | ||
return user_id, access_token | ||
else: | ||
return '登录失败' | ||
|
||
# 修改步数 | ||
def change_step(self): | ||
# 登录结果 | ||
login_result = self.login() | ||
if login_result == '登录失败': | ||
return '登录失败' | ||
else: | ||
url = 'https://sports.lifesense.com/sport_service/sport/sport/uploadMobileStepV2?systemType=2&version=4.6.7' | ||
data = {'list': [{'DataSource': 2, 'active': 1, 'calories': int(self.step/4), 'dataSource': 2, | ||
'deviceId': 'M_NULL', 'distance': int(self.step/3), 'exerciseTime': 0, 'isUpload': 0, | ||
'measurementTime': time.strftime('%Y-%m-%d %H:%M:%S'), 'priority': 0, 'step': self.step, | ||
'type': 2, 'updated': int(round(time.time() * 1000)), 'userId': login_result[0]}]} | ||
headers = { | ||
'Content-Type': 'application/json; charset=utf-8', | ||
'Cookie': 'accessToken=%s' % login_result[1] | ||
} | ||
response_result = requests.post(url, data=json.dumps(data), headers=headers) | ||
status_code = response_result.status_code | ||
# response_text = response_result.text | ||
# print('修改步数状态码:%s' % status_code) | ||
# print('修改步数返回数据:%s' % response_text) | ||
if status_code == 200: | ||
return '修改步数为【%s】成功' % self.step | ||
else: | ||
return '修改步数失败' | ||
|
||
|
||
# 睡眠到第二天执行修改步数的时间 | ||
def get_sleep_time(): | ||
# 第二天日期 | ||
tomorrow = datetime.date.today() + datetime.timedelta(days=1) | ||
# 第二天7点时间戳 | ||
tomorrow_run_time = int(time.mktime(time.strptime(str(tomorrow), '%Y-%m-%d'))) + 25200 | ||
# print(tomorrow_run_time) | ||
# 当前时间戳 | ||
current_time = int(time.time()) | ||
# print(current_time) | ||
return tomorrow_run_time - current_time | ||
|
||
|
||
if __name__ == "__main__": | ||
# 最大运行出错次数 | ||
fail_num = 3 | ||
while 1: | ||
while fail_num > 0: | ||
try: | ||
# 修改步数结果 | ||
result = LexinSport('18663413868', 'Goodmorning66.', '11000').change_step() | ||
print(result) | ||
break | ||
except Exception as e: | ||
print('运行出错,原因:%s' % e) | ||
fail_num -= 1 | ||
if fail_num == 0: | ||
print('修改步数失败') | ||
# 重置运行出错次数 | ||
fail_num = 3 | ||
# 获取睡眠时间 | ||
sleep_time = get_sleep_time() | ||
time.sleep(sleep_time) | ||
|