欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用python3調(diào)用wxpy模塊監(jiān)控linux日志并定時發(fā)送消息給群組或好友

 更新時間:2019年06月05日 09:38:48   作者:榮曉  
這篇文章主要介紹了使用python3調(diào)用wxpy模塊,監(jiān)控linux日志并定時發(fā)送消息給群組或好友,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下

使用python3調(diào)用wxpy模塊,監(jiān)控linux日志并定時發(fā)送消息給群組或好友,具體代碼如下所示:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from threading import Timer
from wxpy import *
import requests
import subprocess
import time
from PIL import Image, ImageDraw, ImageFont
from apscheduler.schedulers.blocking import BlockingScheduler
#cache_path=true 表示登陸一次之后,進(jìn)行緩存,下次登陸只需要手機(jī)確認(rèn)
bot = Bot(console_qr=2,cache_path=True)
#獲取topic是否消費(fèi)延遲
def get_Lag():
  text=""
  p = subprocess.Popen('kafka-consumer-offset-checker --zookeeper 192.168.1.116 --group t_sync --topic SYNC_DATABASE_UPDATE', shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE,universal_newlines=True) #universal_newlines=True,表示輸出為字符串,默認(rèn)是byte
  while True:
    line =p.stdout.readline()
    if not line:
      break
    else:
      text+=line + '\n'
  return text
def get_news():
  text=[]
  count=0
  t=True
  p = subprocess.Popen('tail -F /home/hadoop/da.txt', shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE,universal_newlines=True)
  while True:
    line =str(p.stdout.readline())
    if not line:
      break
    elif "send data" in line and t:
      for item in line.split(','):
        count +=1
        if count <= 200:
           text.append(item)
      break
  return text
def get_context():
  result=""
  word=get_news()
  for i in range(len(word)):
    if(i % 4 ==0):
      result= result+word[i]+"\n"
    else:
      result= result+word[i]+"  "
  return result
def send_image():
  try:
    lags=get_Lag()
    print(lags)
    content=get_context()
#發(fā)送消費(fèi)延遲的數(shù)據(jù)
    lagImage= Image.new('RGB', (1000, 600),(255,255,255))
    draw = ImageDraw.Draw(lagImage)
    font = ImageFont.truetype("/usr/share/fonts/cjkuni-ukai/ukai.ttc", 18, encoding="unic")
    draw.text((10, 10), lags, 'black', font)
    lagImage.save('/home/hadoop/lags.jpg')
#發(fā)送日志消息
    image= Image.new('RGB', (1000, 810),(255,255,255))
    draw = ImageDraw.Draw(image)
    font = ImageFont.truetype("/usr/share/fonts/cjkuni-ukai/ukai.ttc", 18, encoding="unic") #ukai.ttc 字體
    draw.text((10, 10), content, 'black', font)
    image.save('/home/hadoop/123.jpg')
 
 #發(fā)送群組
    group = bot.groups().search("大數(shù)據(jù)小組")[0]
    group.send_image('/home/hadoop/123.jpg')
 #發(fā)送好友
    my_friend = bot.friends().search(u'濤')[0]
    my_friend.send_image('/home/hadoop/lags.jpg')
    my_friend.send_image('/home/hadoop/123.jpg')
    # t = Timer(100, send_image)
    #t.start()
  except:
    my_friend.send(u"今天消息發(fā)送失敗了")
if __name__ == "__main__":
  #send_image()
  scheduler = BlockingScheduler()
  scheduler.add_job(send_image, 'cron', hour='15', minute='01')
  scheduler.add_job(send_image, 'cron', hour='14', minute='58')
  scheduler.start()

總結(jié)

以上所述是小編給大家介紹的使用python3調(diào)用wxpy模塊監(jiān)控linux日志并定時發(fā)送消息給群組或好友,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

相關(guān)文章

  • 詳解python的運(yùn)算符與表達(dá)式

    詳解python的運(yùn)算符與表達(dá)式

    這篇文章主要為大家介紹了python的運(yùn)算符與表達(dá)式,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-01-01
  • Django實(shí)現(xiàn)文章詳情頁面跳轉(zhuǎn)代碼實(shí)例

    Django實(shí)現(xiàn)文章詳情頁面跳轉(zhuǎn)代碼實(shí)例

    這篇文章主要介紹了Django實(shí)現(xiàn)文章詳情頁面跳轉(zhuǎn)代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-09-09
  • python安裝cxOracle避坑總結(jié)不要直接pip install

    python安裝cxOracle避坑總結(jié)不要直接pip install

    這篇文章主要為大家介紹了python安裝cx_Oracle是遇到的一些問題的解決辦法的總結(jié),來幫大家避避坑有需要的朋友可以借鑒參考下,希望能夠有所幫助祝大家多多進(jìn)步
    2021-10-10
  • pytorch交叉熵?fù)p失函數(shù)的weight參數(shù)的使用

    pytorch交叉熵?fù)p失函數(shù)的weight參數(shù)的使用

    這篇文章主要介紹了pytorch交叉熵?fù)p失函數(shù)的weight參數(shù)的使用,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-05-05
  • Python繪制圓形方法及turtle模塊詳解

    Python繪制圓形方法及turtle模塊詳解

    這篇文章主要給大家介紹了關(guān)于Python繪制圓形方法及turtle模塊詳解的相關(guān)資料,Turtle庫是Python語言中一個很流行的繪制圖像的函數(shù)庫,文中介紹的非常詳細(xì),需要的朋友可以參考下
    2023-12-12
  • Python實(shí)現(xiàn)圖片灰度化以及圖片顯示的兩種方法

    Python實(shí)現(xiàn)圖片灰度化以及圖片顯示的兩種方法

    這篇文章給大家介紹了Python實(shí)現(xiàn)圖片,灰度化以及圖片顯示的兩種方法并通過代碼示例和圖文結(jié)合的方式給大家講解的非常詳細(xì),需要的朋友可以參考下
    2024-02-02
  • 解析Sentry?Relay?二次開發(fā)調(diào)試

    解析Sentry?Relay?二次開發(fā)調(diào)試

    這篇文章主要介紹了Sentry?Relay?二次開發(fā)調(diào)試簡介,集成測試要求?Redis?和?Kafka?在其默認(rèn)配置中運(yùn)行,獲取所有必需服務(wù)的最便捷方式是通過?sentry?devservices,這需要最新的?Sentry?開發(fā)環(huán)境,本文給大家介紹的非常詳細(xì),需要的朋友參考下吧
    2022-03-03
  • python獲取http請求響應(yīng)頭headers中的數(shù)據(jù)的示例

    python獲取http請求響應(yīng)頭headers中的數(shù)據(jù)的示例

    這篇文章主要介紹了python獲取http請求響應(yīng)頭headers中的數(shù)據(jù),本文通過示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-02-02
  • Python實(shí)現(xiàn)partial改變方法默認(rèn)參數(shù)

    Python實(shí)現(xiàn)partial改變方法默認(rèn)參數(shù)

    這篇文章主要介紹了Python實(shí)現(xiàn)partial改變方法默認(rèn)參數(shù),需要的朋友可以參考下
    2014-08-08
  • Python的Lambda函數(shù)用法詳解

    Python的Lambda函數(shù)用法詳解

    在Python中有兩種函數(shù),一種是def定義的函數(shù),另一種是lambda函數(shù),也就是大家常說的匿名函數(shù)。這篇文章主要介紹了Python的Lambda函數(shù)用法,需要的朋友可以參考下
    2019-09-09

最新評論