一、添文章来源(Source):https://www.dqzboy.com加机器人
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import requests
import re
import urllib.request
import json
import sys
import os
headers = {'Content-Type': 'application/json;charset=utf-8'}
##拷贝企业微信机器人生成的webhook
webhook = "企业微信机器人webhook"
def msg(text):
message= {
"msgtype": "text",
"text": {
"content": text, ##注意后面跟【逗号】
"mentioned_list":["@all"] ##@群里所有人,可以不加
},
"at": {
"isAtAll": True
}
}
print(requests.post(webhook,json.dumps(message),headers=headers).content)
url = "https://tianqi.moji.com/weather/china/shanghai/minhang-district" ##要爬取天气预报的网址(china后面是各个省市的地址)
par = '(<meta name="description" content=")(.*?)(">)'
opener = urllib.request.build_opener()
urllib.request.install_opener(opener)
html = urllib.request.urlopen(url).read().decode("utf-8")
##提取需要爬取的内容
data = re.search(par,html).group(2)
msg(data)
三、执行p原文链接:https://www.dqzboy.comy脚本
[root@localhost script]# chmod +x weather.py
[root@localhost script]# ./weather.py
b'{"errcode":0,"errmsg":"ok"}'
文章来源(Source):https://www.dqzboy.com四文章来源(Source):浅时光博客、查看群消息
- 最后可以结合Linux的crontab去进行定时发送消息
- 根据工作日和节假日进行消息推送,实现工作日进行推送,节假日则不进行推送消息;最后完原文链接:https://www.dqzboy.com整脚本如下。
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import requests
import re
import urllib.request
import json
import sys
import os
import time
import time,datetime
holiday_info = {}
CUR_YEAR = '2020' #定义年份
##这里字符集改为了gbk
headers = {'Content-Type': 'application/json;charset=gbk'}
webhook = "企业微信机器人webhook"
url = "https://tianqi.moji.com/weather/china/shanghai/minhang-district"
par = '(<meta name="description" content=")(.*?)(">)'
opener = urllib.request.build_opener()
urllib.request.install_opener(opener)
html = urllib.request.urlopen(url).read().decode("utf-8")
data = re.search(par,html).group(2)
def msg(text):
message= {
"msgtype": "text",
"text": {
"content": text,
"mentioned_list":["@all"]
}
}
print(requests.post(webhook,json.dumps(message),headers=headers).content)
def init_holiday_info():
global holiday_info
rep = requests.get('http://tool.bitefu.net/jiari/?d=' + CUR_YEAR)
info_txt = rep.content.decode()
holiday_info = json.loads(info_txt)
def check_if_is_work_day():
day_info = time.strftime("%m%d",time.localtime(time.time()))
print(day_info)
if day_info in holiday_info[CUR_YEAR]:
return False
week = datetime.datetime.now().weekday()
if 0 <= week and 4 >= week:
msg(data) #调用期企业微信推送内容
return False
if __name__ == "__main__":
init_holiday_info()
check_if_is_work_day()
能推送其他消息吗,比如生产使用的ERP,MES的生产数据
你可以根据你们平台,去爬取想要的数据去推送
好的,谢谢
这个好,666
666