|
@@ -0,0 +1,150 @@
|
|
|
|
+#!/usr/bin/env python
|
|
|
|
+# -*- encoding: utf-8 -*-
|
|
|
|
+'''
|
|
|
|
+@File : alive.py
|
|
|
|
+@Time : 2019/05/26 12:14:04
|
|
|
|
+@Author : Liuyuqi
|
|
|
|
+@Version : 1.0
|
|
|
|
+@Contact : liuyuqi.gov@msn.cn
|
|
|
|
+@License : (C)Copyright 2019
|
|
|
|
+@Desc : 保持心跳
|
|
|
|
+
|
|
|
|
+https://live.kuaishou.com/rest/wd/live/liveStream/myfollow
|
|
|
|
+Request URL: https://live.kuaishou.com/rest/wd/live/liveStream/myfollow
|
|
|
|
+Request Method: POST
|
|
|
|
+Status Code: 200 OK
|
|
|
|
+Remote Address: 127.0.0.1:1080
|
|
|
|
+Referrer Policy: unsafe-url
|
|
|
|
+
|
|
|
|
+Accept: application/json
|
|
|
|
+Accept-Encoding: gzip, deflate, br
|
|
|
|
+Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
|
|
|
|
+Connection: keep-alive
|
|
|
|
+Content-Length: 0
|
|
|
|
+Cookie: did=web_4095924dbbb4d12df7a87725a16104b6; didv=1558790317127; Hm_lvt_86a27b7db2c5c0ae37fee4a8a35033ee=1558790317; kuaishou.live.bfb1s=9b8f70844293bed778aade6e0a8f9942; clientid=3; client_key=65890b29; Hm_lpvt_86a27b7db2c5c0ae37fee4a8a35033ee=1558793089; userId=1365365171; userId=1365365171; kuaishou.live.web_st=ChRrdWFpc2hvdS5saXZlLndlYi5zdBKgAZFHcXmdSz0ZqgeR8-TTgoi9QQRV_2I1NT-eK4Wr46MXF-NpYe4Fo00puYYJRRdqB4nJLluPiMpO7YGwHtxLbnttpwFVvU0_aelP9U7kgg9s1BVI9U1dGQsZ0_JLfL8137gJKr4CqwJaq-9LBhM5a_ATTdc5Te1meUd1st2HGg-Dy_g18QwLY84WirWBIaKm8R7r6Dd3fFKYm-gdtJYmMukaEk2hY_LIikBot7IUVtJ3ydB6KCIgx-OxXNSqmT0GdbC5rtc3vchNEkamnb0pAQf6txb5g3YoBTAB; kuaishou.live.web_ph=b1dec6f6601bf17d2cb5b72665242eea8524
|
|
|
|
+Host: live.kuaishou.com
|
|
|
|
+kpf: PC_WEB
|
|
|
|
+kpn: GAME_ZONE
|
|
|
|
+Origin: https://live.kuaishou.com
|
|
|
|
+Referer: https://live.kuaishou.com/u/fengyeYS
|
|
|
|
+User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36
|
|
|
|
+
|
|
|
|
+res:
|
|
|
|
+
|
|
|
|
+'''
|
|
|
|
+
|
|
|
|
+import queue
|
|
|
|
+import threading
|
|
|
|
+import time
|
|
|
|
+
|
|
|
|
+import requests
|
|
|
|
+
|
|
|
|
+# import pymysql
|
|
|
|
+import utils.get_cookie as get_cookie
|
|
|
|
+
|
|
|
|
+baseUrl = "https://live.kuaishou.com"
|
|
|
|
+# baseUrl = "http://nginx.ok.yoqi.me:88"
|
|
|
|
+
|
|
|
|
+proxies = {"http": "http://120.26.110.59:8080"}
|
|
|
|
+# sessionClient=requests.session()
|
|
|
|
+sessionClients = []
|
|
|
|
+
|
|
|
|
+baseHeader = {
|
|
|
|
+ "Accept": "application/json",
|
|
|
|
+ "Content-Type": "application/json;charset=UTF-8",
|
|
|
|
+ "Origin": baseUrl,
|
|
|
|
+ "kpf": "PC_WEB",
|
|
|
|
+ "kpn": "GAME_ZONE",
|
|
|
|
+}
|
|
|
|
+account_alive_count = 0
|
|
|
|
+detail_url_queue = queue.Queue(maxsize=1000)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def login(userPhone, cookies, userAgent, threadid):
|
|
|
|
+ """
|
|
|
|
+ 登录快手,执行一次即可。
|
|
|
|
+ param :
|
|
|
|
+ return:
|
|
|
|
+ """
|
|
|
|
+ url = baseUrl + "/rest/wd/live/liveStream/myfollow"
|
|
|
|
+ mPartHeader = {
|
|
|
|
+ "Referer": "https://live.kuaishou.com/u/3xphut7zrw7zcbq",
|
|
|
|
+ "User-Agent": userAgent
|
|
|
|
+ }
|
|
|
|
+ mHeader = baseHeader.copy()
|
|
|
|
+ mHeader.update(mPartHeader)
|
|
|
|
+ proxies = ""
|
|
|
|
+ res = sessionClients[threadid].get(url=url, headers=mHeader, cookies=cookies,
|
|
|
|
+ # proxies=proxies
|
|
|
|
+ )
|
|
|
|
+ print(res.text)
|
|
|
|
+ if eval(res.text)["result"] != "200":
|
|
|
|
+ return False
|
|
|
|
+ else:
|
|
|
|
+ return True
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def myfollow(userPhone, cookies, userAgent, threadid):
|
|
|
|
+ '''
|
|
|
|
+ 维持心跳,更新cookie。
|
|
|
|
+ :param userPhone:
|
|
|
|
+ :param cookies:
|
|
|
|
+ :param userAgent:
|
|
|
|
+ :param threadid:
|
|
|
|
+ :return:
|
|
|
|
+ '''
|
|
|
|
+ url = baseUrl + "/rest/wd/live/liveStream/myfollow"
|
|
|
|
+ mPartHeader = {
|
|
|
|
+ "Referer": "https://live.kuaishou.com/u/3xphut7zrw7zcbq",
|
|
|
|
+ "User-Agent": userAgent
|
|
|
|
+ }
|
|
|
|
+ mHeader = baseHeader.copy()
|
|
|
|
+ mHeader.update(mPartHeader)
|
|
|
|
+ # cookies = requests.utils.dict_from_cookiejar(session.cookies)
|
|
|
|
+ # print(session)
|
|
|
|
+ res = sessionClients[threadid].get(
|
|
|
|
+ url=url, headers=mHeader, cookies=cookies,
|
|
|
|
+ # proxies=proxies
|
|
|
|
+ )
|
|
|
|
+ if eval(res.text)["result"] != "200":
|
|
|
|
+ return False
|
|
|
|
+ else:
|
|
|
|
+ return True
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def run(userPhone, cookies, userAgent, threadid):
|
|
|
|
+ '''
|
|
|
|
+ 执行多线程批量登录,维持在线
|
|
|
|
+ :param userPhone: 用户手机号
|
|
|
|
+ :param cookies: 用户初始化cookie
|
|
|
|
+ :param userAgent: 用户agent
|
|
|
|
+ :param threadid: 线程id
|
|
|
|
+ :return:
|
|
|
|
+ '''
|
|
|
|
+ state = False # 登录状态
|
|
|
|
+ state = login(userPhone, cookies, userAgent, threadid)
|
|
|
|
+ if state == False:
|
|
|
|
+ print("thread {id}: User {userPhone}.login failure".format(id=threadid, userPhone=userPhone))
|
|
|
|
+ return
|
|
|
|
+ else:
|
|
|
|
+ print("thread {id}: User {userPhone}.login success".format(id=threadid, userPhone=userPhone))
|
|
|
|
+ while True:
|
|
|
|
+ state = myfollow(userPhone, cookies, userAgent, threadid)
|
|
|
|
+ if state == False:
|
|
|
|
+ print("thread {id}: User {userPhone}. is alive".format(id=threadid, userPhone=userPhone))
|
|
|
|
+ break
|
|
|
|
+ else:
|
|
|
|
+ print("thread {id}: User {userPhone}. is alive".format(id=threadid, userPhone=userPhone))
|
|
|
|
+ time.sleep(10)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+if __name__ == "__main__":
|
|
|
|
+ start_time = time.time()
|
|
|
|
+ mUser = get_cookie.getUser()
|
|
|
|
+ account_alive_count = len(mUser["userPhone"])
|
|
|
|
+ for i in range(3):
|
|
|
|
+ sessionClients.append(requests.session()) # 新建一个session
|
|
|
|
+ threading.Thread(target=run,
|
|
|
|
+ args=(mUser["userPhone"][i], mUser["cookies"][i], mUser["userAgent"][i], i)).start()
|
|
|
|
+
|
|
|
|
+ print("last time: {} s".format(time.time() - start_time))
|