企业微信定时推送到普通微信,每日提醒工作

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

效果图如下:
wechat

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()

centos7安装vim8.2

1.卸载原有的vim

sudo yum remove vim
2.使用Git下载vim8源码
git clone git@github.com:vim/vim.git
Git的简单配置可以参考CentOS7-Git配置

3.安装依赖文件

sudo yum install -y python-devel python3-devel ruby ruby-devel lua lua-devel perl per-devel perl-ExtUtils-Embed libX11-devel ncurses-devel

4.编译安装vim8

./configure --with-features=huge \
            --enable-multibyte \
            --enable-python3interp=yes \
            --with-python3-config-dir=/usr/local/python/lib/python3.9/config-3.9-aarch64-linux-gnu \
            --enable-gui=gtk2 \
            --enable-pythoninterp \
            --enable-cscope \
            --prefix=/usr/local/vim

make
make install
添加环境变量
export PATH=$PATH:/usr/local/vim/bin

5.创建软链接
sudo ln -s /usr/local/vim/bin/vim /usr/bin/vim
创建成功后,可以方便的使用vim命令打开vim编辑器

配置选项说明

--with-features=huge:支持最大特性
--enable-pythoninterp:支持python2编写的插件
--enable-python3interp:支持python3编写的插件
--enable-rubyinterp:支持ruby编写的插件
--enable-luainterp:支持lua编写的插件
--enable-perlinterp:支持perl编写的插件
--with-python-config-dir=/usr/lib64/python2.7/config/:指定python2的位置,不同的机器位置不同,确保指定的文件夹中包含config.c文件
--with-python3-config-dir=/usr/local/python3.6/lib/python3.6/config-3.6m-x86_64-linux-gnu/:同上,也要确保有config.c文件
关于python3的安装可以参考CentOS7-Python3安装
--enable-cscope:打开cscope支持
--enable-multibyte:支持多字节,可以输入中文
--prefix=/usr/local/vim:指定vim的安装位置

作者:Gpeko
链接:https://www.jianshu.com/p/a828441cd354
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

ubuntu server安装桌面并开启VNC

刚买了个机顶盒4+32的,在网上找的img刷ubuntu系统,挂载移动硬盘,当个服务器用,总功率也就5W左右,长期开启,也不耗电。由于没有桌面,不能下载电影,所以找个教程,找了很多,拼凑来的。
先更新
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install tasksel -y
sudo tasksel
选择 ubuntu desktop
重启

开启共享:
settings→sharing→screen sharing→开启设置密码
如果不能选择网络,添加如下
network:
version: 2
renderer: NetworkManager

完成后可以关掉设置了, 但是现在你依然无法使用VNC来连接, 继续操作, 安装系统配置图形软件dconf-editor。
sudo apt-get install dconf-editor

搜索dconf
进入org/gnome/desktop/remote-access目录

关闭notify-on-connect、prompt-enabled、require-encryption

然后可以vnc登陆

PS:这个只能开机登陆后才能远程,如果关机不登陆图形界面是不能登陆VNC。开机启动按照网上教程没有成功,后期再测试