您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關(guān)python如何修改運動數(shù)據(jù)的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
方法
1、用手機號注冊運動APP并登錄。
2、復制相關(guān)代碼并保存到一個文件中。
如文件名xiaomiyundong.py;
3、修改第144行手機號碼及第146行密碼,保存。
4、在python環(huán)境下運行文件。
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 #主函數(shù) def main(user, passwd, step): user = str(user) password = str(passwd) step = str(step) if user == '' or password == '': print ("用戶名或密碼填寫有誤!") return if step == '': print ("已設置為隨機步數(shù)(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}] 修改步數(shù)({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" # 要修改的步數(shù),直接輸入想要修改的步數(shù)值,留空為隨機步數(shù)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('用戶名和密碼數(shù)量不對')
感謝各位的閱讀!關(guān)于“python如何修改運動數(shù)據(jù)”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。