吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 11150|回复: 63
收起左侧

[Python 转载] 企业微信定时推送到普通微信,每日提醒工作

  [复制链接]
modys 发表于 2021-9-15 21:32
前几个月写了一个自动推送的文章:https://www.52pojie.cn/thread-1431980-1-1.html,每天推送。由于作者接口出现问题不能使用,大概是上周四出现问题,一直到现在还不能使用。可能是提醒习惯了,而且我每天的工作日报有时候就忘记写(少一个都是money)。本想调用server酱,但是折叠起来,看起来很麻烦,通过搜索,找到一篇文章,不需要部署服务,直接通过企业微信接口调用。
接口原作者:https://ley.best/push-msgs-to-wechat-and-dingding/
原作者的文章,用的是图文消息,但推送的字体很小,而且不能超过512字节,发送的消息文字显示不全;文本消息可以达到2048字节,所以改成文本。
自己想要什么都可以更改,企业微信接口文档:https://work.weixin.qq.com/api/doc/90000/90135/90236

推送

推送

效果图如下:

everyday

everyday


[Python] 纯文本查看 复制代码
from lxml import etree
from datetime import datetime
import requests, sys, urllib, json


class Worker:
    def __init__(self):
        self.now_time = datetime.today()
        self.headers= {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36'}
        self.url = 'http://api.tianapi.com/txapi/jiejiari/index?key=自己的&date='
    def my_job(self):
        url = self.url + str(self.now_time)
        r = requests.get(url=url, headers=self.headers)
        content = eval(r.text)
        # print(content)
        newlist = content['newslist'][0]
        infos = ''
        if int(content['code']) == 200:
            if newlist['info'] == '工作日':
                infos = '\n' + '今天是工作日,要写日报!!!!' + '\n'
                return infos
            elif newlist['info'] == '双休日':
                infos = '今天是双休日,要写下周的工作计划'
                return infos
            elif newlist['tip'] != '':
                infos = '国家法定节假日,可以好好休息,别忘了周工作计划和月工作计划'
                return infos
            else:
                pass
        else:
            infos = '接口错误'
            return infos
        # print(infos)
        return infos
class YouJia:
    def __init__(self):
        self.url = 'http://api.tianapi.com/txapi/oilprice/index?key=自己的&prov=河南'
        self.data = ''
    def money(self):
        r = requests.get(url=self.url).text
        content = eval(r)
        #print(content)
        if content['code'] == 200:
            print(content['newslist'][0]['p92'])
            self.data = '92号油价:' + content['newslist'][0]['p92'] + '  95号油价:' + content['newslist'][0]['p95']
        else:
            self.data = '油价接口错误!!!'
        return self.data

class Weather():
    def __init__(self):
        self.data={
            "location":"自己的城市",
            "key":"自己的"
        }

    def get_url(self):
        # API地址用S6,也可以用V7
        data_list = requests.get('https://free-api.heweather.com/s6/weather/forecast',params=self.data).json()
        daily_forecast = data_list["HeWeather6"][0]["daily_forecast"]
        forecast_list = []
        for i in daily_forecast:
            # print(daily_forecast.index(i))
            forecast = {}
            # 取列表索引
            if daily_forecast.index(i) == 0:
                forecast['时间'] = '今天   '
            elif daily_forecast.index(i) == 1:
                forecast['时间'] = '明天   '
            else:
                forecast['时间'] = '后天   '
            all_forecast = forecast['时间'] + '  白天:'+ i['cond_txt_d'] + '  晚上:' + i['cond_txt_n'] + '  最高温度:'+ i['tmp_max'] + '°C' + '  最低温度:'+ i['tmp_min'] + '°C' + '  风力:' + i['wind_dir'] + i['wind_sc'] + '级' + '!'

            forecast_list.append(all_forecast)
        select_forecast = "".join(forecast_list)
        new_data = select_forecast.replace('!', '\n')
        return new_data

class YiQing:
    def __init__(self):
        self.url = 'http://api.tianapi.com/txapi/ncov/index?key=自己的'
        self.all_data = ''
        self.henan_news = ''
    def request_data(self):
        r = requests.get(self.url).text
        content = eval(r)
        # print(type(content))
        news_list = content["newslist"][0]
        all_news = news_list['news']
        news_num = len(all_news)
        nationwide = all_news[0]['summary']
        # print(nationwide)
        for i in range(news_num):
            if all_news[i]['id'] == 150879:
                self.henan_news = all_news[i]['summary']
                break
            else:
                self.henan_news = '河南—————————暂无疫情'
        self.all_data = nationwide + '\n' + '-'*34 + '\n' + '\n' + self.henan_news
        return self.all_data

class Weixin():
    def __init__(self,myjob_data, youjia_data, tianqi_data, yiqing_data):
        self.corpid = '自己的'
        self.corpsecret = '自己的'
        self.HEADERS = {"Content-Type": "application/json ;charset=utf-8"}
        self.myjob = myjob_data
        self.youjia = youjia_data
        self.tianqi = tianqi_data
        self.yiqing = yiqing_data
    def news(self):
        send_data = self.myjob + '\n' + '-'*34 + '\n' +  self.youjia + '\n' + '-'*34 + self.tianqi + '-'*34 +  self.yiqing
        r = requests.get('https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + self.corpid + '&corpsecret=' + self.corpsecret).text
        # print(r)
        js = json.loads(r)
        token = js['access_token']
        data = {
            'touser': '@all',
            'msgtype': 'text',
            'agentid': 1000002, #自己更改
            'text':{
                'content': send_data
                },
            'safe': 0,
            'enable_id_trans': 0,
            'enable_duplicate_check': 0,
            'duplicate_check_interval': 1800

                }
        String_testMsg = json.dumps(data)
        wechaturl = f'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={token}'
        # print(wechaturl)
        req = requests.post(wechaturl, data=String_testMsg, headers=self.HEADERS)
        # print(req.text)


def main():
    workers = Worker()
    youjias = YouJia()
    tianqis = Weather()
    yiqings = YiQing()
    wechat = Weixin(workers.my_job(), youjias.money(), tianqis.get_url(), yiqings.request_data())
    wechat.news()
if __name__ == '__main__':
    main()



我不知道对各位有用没,反正我写了好几个脚本,尤其是单位服务器,每天能及时了解情况。

代码很烂,能看就看,不能看的就划走!

免费评分

参与人数 5吾爱币 +4 热心值 +3 收起 理由
诗和远方代言人 + 1 我很赞同!
dadadad + 1 热心回复!
bingshen + 1 + 1 功能很实用。
schedule + 1 谢谢@Thanks!
ciss520 + 1 + 1 支持原创,思维分享,其实是个办公解决方案的好点子

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| modys 发表于 2021-9-16 00:10

用的全是接口,自己改一下密钥或者ID就行了
漪如家的小99 发表于 2021-9-19 00:15
modys 发表于 2021-9-18 08:44
有的模块不支持,你只能自己更改

上传了报错

START RequestId:74763515-a44a-4bfa-9a40-7a8663eeac00

ERROR RequestId:74763515-a44a-4bfa-9a40-7a8663eeac00 Result:{"errorCode":-1,"errorMessage":"Traceback (most recent call last):\n  File \"/var/runtime/python3/bootstrap.py\", line 133, in init_handler\n    func_handler = get_func_handler(file.rsplit(\".\", 1)[0], func)\n  File \"/var/runtime/python3/bootstrap.py\", line 159, in get_func_handler\n    mod = imp.load_module(mname, *imp.find_module(mname))\n  File \"/var/lang/python3/lib/python3.6/imp.py\", line 234, in load_module\n    return load_source(name, filename, file)\n  File \"/var/lang/python3/lib/python3.6/imp.py\", line 172, in load_source\n    module = _load(spec)\n  File \"\u003cfrozen importlib._bootstrap\u003e\", line 675, in _load\n  File \"\u003cfrozen importlib._bootstrap\u003e\", line 655, in _load_unlocked\n  File \"\u003cfrozen importlib._bootstrap_external\u003e\", line 678, in exec_module\n  File \"\u003cfrozen importlib._bootstrap\u003e\", line 205, in _call_with_frames_removed\n  File \"/var/user/index.py\", line 1, in \u003cmodule\u003e\n    from lxml import etree\nModuleNotFoundError: No module named 'lxml'","statusCode":443}

END RequestId:74763515-a44a-4bfa-9a40-7a8663eeac00

Report RequestId:74763515-a44a-4bfa-9a40-7a8663eeac00 Duration:0ms Memory:128MB MemUsage:0.000000MB
hxd1230 发表于 2021-9-15 21:49
xxhaishixx 发表于 2021-9-15 22:20
比我写的代码好看,我的代码就算是老乔来了看着也头疼。
lyj996 发表于 2021-9-15 23:11
感谢分享
wingsiu 发表于 2021-9-15 23:24
这是个好东西啊,学习了,感谢大佬
wshq 发表于 2021-9-15 23:27
本帖最后由 wshq 于 2021-9-15 23:31 编辑

自己用易语言写了个demo测试了下 确实可以推送到普通微信
a'ゞ_情殇 发表于 2021-9-15 23:33
wshq 发表于 2021-9-15 23:27
自己用易语言写了个demo测试了下 确实可以推送到普通微信

为啥我用精易网页助手发包测试发出去的文本都是乱码
这样的��Ŀ���ѵ�����Я������ǰ���ʼ�������ȡ
lxy5321 发表于 2021-9-15 23:58
不会用啊
无聊肤浅中 发表于 2021-9-16 02:29
测试一下确实可以,楼主厉害👍
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-27 11:49

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表