-
Notifications
You must be signed in to change notification settings - Fork 1
/
jdCookie.py
63 lines (56 loc) · 1.95 KB
/
jdCookie.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import requests
import json
import time
import os
import re
from datetime import datetime
from datetime import timedelta
from datetime import timezone
if "JD_COOKIE" in os.environ:
print("执行自GitHub action")
secret = os.environ["JD_COOKIE"]
cookieLists_all = []
cookieLists = []
cookieId = 0
for line in secret.split('&'):
pt_key = re.findall(r'pt_key=(.*?);', line)[0]
pt_pin = re.findall(r'pt_pin=(.*?)$', line)[0]
if cookieId <= 1:
cookieLists.append({"pt_key": pt_key, "pt_pin": pt_pin})
cookieLists_all.append({"pt_key": pt_key, "pt_pin": pt_pin})
cookieId += 1
def valid(cookies):
headers = {
'Host': 'api.m.jd.com',
'Accept': '*/*',
'Connection': 'keep-alive',
'User-Agent': 'jdapp;iPhone;8.5.5;13.5;Mozilla/5.0 (iPhone; CPU iPhone OS 13_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1',
'Accept-Language': 'zh-cn',
'Accept-Encoding': 'gzip, deflate, br',
}
params = (
('functionId', 'plantBeanIndex'),
('body', json.dumps(
{"monitor_source": "plant_m_plant_index", "version": "8.4.0.0"})),
('appid', 'ld'),
)
response = requests.get('https://api.m.jd.com/client.action',
headers=headers, params=params, cookies=cookies)
if response.json()["code"] == "3":
print(f"cookie过期")
return False
return True
def get_cookies():
return [i for i in cookieLists if valid(i)]
def get_cookies_all():
return [i for i in cookieLists_all if valid(i)]
def get_time_now():
SHA_TZ = timezone(timedelta(hours=8),name = 'Asia/Shanghai')
utc_now = datetime.utcnow().replace(tzinfo=timezone.utc)
time_now = utc_now.astimezone(SHA_TZ)
return time_now
def get_time_unix():
return round(get_time_now().timestamp()*1000)
print("***"*20)
print("***"*20)
print(get_time_now().strftime("%Y-%m-%d %H:%M:%S"))