-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathrun.py
81 lines (73 loc) · 3.2 KB
/
run.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#python 3.8
import time,hmac,hashlib,base64,urllib.parse,sys,requests,json
from function import *
from lxml import etree
def sent_message(token:str,secret:str,text:str,title:str,picUrl:str,messageUrl:str):
timestamp = str(round(time.time() * 1000))
secret_enc = secret.encode('utf-8')
string_to_sign = '{}\n{}'.format(timestamp, secret)
string_to_sign_enc = string_to_sign.encode('utf-8')
hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest()
sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
url="https://oapi.dingtalk.com/robot/send?access_token={2}×tamp={0}&sign={1}".format(timestamp,sign,token)
data={
"msgtype": "link",
"link": {
"text": text,
"title": title,
"picUrl": picUrl,
"messageUrl": messageUrl
}
}
headers={"Content-Type": "application/json"}
data=json.dumps(data)
rsp=requests.post(url=url,data=data,headers=headers)
print(rsp.json().get('errmsg'))
if __name__ == "__main__":
try:
token=sys.argv[1]
secret = sys.argv[2]
try:
mids = sys.argv[3]
bili_subscribe = True
except:
bili_subscribe = False
China_stp=int(time.time())#action获取的系统时间突然变成了utc+8,原因不明
#小刀网线报处理
datas=get_message()
try:
for url,img,info in datas:
rsp=requests.get(url=url)
s=etree.HTML(rsp.text)
title=s.xpath("//h1[@class='article-title']")[0].text
date=s.xpath("//time")[0].xpath('string(.)')
timeArray = time.strptime(date+":00", "%Y-%m-%d %H:%M:%S")
timestamp = time.mktime(timeArray)
ac_time=China_stp-timestamp+28800
#默认时间频率为两小时,单位秒即7200,可以根据自己需求更改。
if ac_time<7200 :
sent_message(token=token,secret=secret,text=date+"\n"+info,title=title,picUrl=img,messageUrl=url)
print("log:",date,title,info,"\n")
else:
break
except:
print("error \n",rsp.text)
#bilibili投稿处理
if bili_subscribe == True :
mid_list = mids.split(',')
for i in mid_list:
video_list = get_video(i)
for j in video_list:
ac_time = China_stp- j['created']
if ac_time<7200 :
import datetime
dateArray = datetime.datetime.fromtimestamp(j['created']+28800)
otherStyleTime = dateArray.strftime("%m-%d %H:%M:%S")
sent_message(token=token,secret=secret,text=j['author']+" "+otherStyleTime+"\n"+j['description'],title=j['title'],picUrl="https:{}".format(j['pic']),messageUrl="https://www.bilibili.com/video/{}".format(j['bvid']))
print("log:",j['created'],j['author'],j['title'],"\n")
else:
break
else:
pass
except:
print('secret loss')