python如何修改运动数据
这篇文章给大家分享的是有关python如何修改运动数据的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
我们提供的服务有:做网站、网站制作、微信公众号开发、网站优化、网站认证、易门ssl等。为成百上千企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的易门网站制作公司
方法
1、用手机号注册运动APP并登录。
2、复制相关代码并保存到一个文件中。
如文件名xiaomiyundong.py;
3、修改第144行手机号码及第146行密码,保存。
4、在python环境下运行文件。
python3xiaomiyundong.py;
5、可以设置定时任务。
例如,在软路由OpenWrt中设置的计划任务是:
0 18,19 * * * /usr/bin/python3
/usr/share/XiaoMiYunDong/xiaomiyundong.py >/tmp/xiaomiyundong.log 2>&1
实例
# -*- coding: utf8 -*- # python >=3.8 """当然在学习Python的道路上肯定会困难,没有好的学习资料,怎么去学习呢? 学习Python中有不明白推荐加入交流群号:928946953 群里有志同道合的小伙伴,互帮互助, 群里有不错的视频学习教程和PDF!还有大牛解答!""" import requests,time,re,json,random import os TG_BOT_TOKEN = "" # telegram bot token 自行申请 TG_USER_ID = "" # telegram 用户ID def telegram_bot(title, content): print("\n") tg_bot_token = TG_BOT_TOKEN tg_user_id = TG_USER_ID if "TG_BOT_TOKEN" in os.environ and "TG_USER_ID" in os.environ: tg_bot_token = os.environ["TG_BOT_TOKEN"] tg_user_id = os.environ["TG_USER_ID"] if not tg_bot_token or not tg_user_id: print("Telegram推送的tg_bot_token或者tg_user_id未设置!!\n取消推送") return print("Telegram 推送开始") send_data = {"chat_id": tg_user_id, "text": title + '\n\n'+content, "disable_web_page_preview": "true"} response = requests.post( url='https://api.telegram.org/bot%s/sendMessage' % (tg_bot_token), data=send_data) print(response.text) now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) headers = { 'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 9; MI 6 MIUI/20.6.18)' } #获取登录code def get_code(location): code_pattern = re.compile("(?<=access=).*?(?=&)") code = code_pattern.findall(location)[0] return code #登录 def login(user,password): url1 = "https://api-user.huami.com/registrations/+86" + user + "/tokens" headers = { "Content-Type":"application/x-www-form-urlencoded;charset=UTF-8", "User-Agent":"MiFit/4.6.0 (iPhone; iOS 14.0.1; Scale/2.00)" } data1 = { "client_id":"HuaMi", "password":f"{password}", "redirect_uri":"https://s3-us-west-2.amazonaws.com/hm-registration/successsignin.html", "token":"access" } r1 = requests.post(url1,data=data1,headers=headers,allow_redirects=False) location = r1.headers["Location"] try: code = get_code(location) except: return 0,0 #print("access_code获取成功!")ste #print(code) url2 = "https://account.huami.com/v2/client/login" data2 = { "app_name":"com.xiaomi.hm.health", "app_version":"4.6.0", "code":f"{code}", "country_code":"CN", "device_id":"2C8B4939-0CCD-4E94-8CBA-CB8EA6E613A1", "device_model":"phone", "grant_type":"access_token", "third_name":"huami_phone", } r2 = requests.post(url2,data=data2,headers=headers).json() login_token = r2["token_info"]["login_token"] #print("login_token获取成功!") #print(login_token) userid = r2["token_info"]["user_id"] #print("userid获取成功!") #print(userid) return login_token,userid #主函数 def main(user, passwd, step): user = str(user) password = str(passwd) step = str(step) if user == '' or password == '': print ("用户名或密码填写有误!") return if step == '': print ("已设置为随机步数(20000-29999)") step = str(random.randint(20000,29999)) login_token = 0 login_token,userid = login(user,password) if login_token == 0: print("登陆失败!") return "login fail!" t = get_time() app_token = get_app_token(login_token) today = time.strftime("%F") data_json = finddate = re.compile(r'.*?date%22%3A%22(.*?)%22%2C%22data.*?') findstep = re.compile(r'.*?ttl%5C%22%3A(.*?)%2C%5C%22dis.*?') data_json = re.sub(finddate.findall(data_json)[0], today, str(data_json)) data_json = re.sub(findstep.findall(data_json)[0], step, str(data_json)) url = f'https://api-mifit-cn.huami.com/v1/data/band_data.json?&t={t}' head = { "apptoken": app_token, "Content-Type": "application/x-www-form-urlencoded" } data = f'userid={userid}&last_sync_data_time=1597306380&device_type=0&last_deviceid=DA932FFFFE8816E7&data_json={data_json}' response = requests.post(url, data=data, headers=head).json() #print(response) result = f"{user[:4]}****{user[-4:]}: [{now}] 修改步数({step})"+ response['message'] print(result) return result #获取时间戳 def get_time(): url = 'http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp' response = requests.get(url,headers=headers).json() t = response['data']['t'] return t #获取app_token def get_app_token(login_token): url = f"https://account-cn.huami.com/v1/client/app_tokens?app_name=com.xiaomi.hm.health&dn=api-user.huami.com%2Capi-mifit.huami.com%2Capp-analytics.huami.com&login_token={login_token}" response = requests.get(url,headers=headers).json() app_token = response['token_info']['app_token'] #print("app_token获取成功!") #print(app_token) return app_token if __name__ == "__main__": # 用户名(单用户的格式为 13800138000 ,多用户用#隔开,例如13800138000#13800138000#13800138000) user = "13800138000" # 登录密码(用#隔开,例如123456#123456#123456) passwd = "123456" # 要修改的步数,直接输入想要修改的步数值,留空为随机步数20000至29999之间 step = "" user_list = user.split('#') passwd_list = passwd.split('#') setp_array = step.split('-') if len(user_list) == len(passwd_list): push = '' for line in range(0,len(user_list)): if len(setp_array) == 2: step = str(random.randint(int(setp_array[0]),int(setp_array[1]))) elif str(step) == '0': step = '' push += main(user_list[line], passwd_list[line], step) + '\n' telegram_bot("小米运动", push) else: print('用户名和密码数量不对')
感谢各位的阅读!关于“python如何修改运动数据”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
网站标题:python如何修改运动数据
新闻来源:http://myzitong.com/article/pgpiji.html