5/29/2019

Code Python ส่ง Slack ใหม่

Code Python ส่ง Slack ใหม่
Code เดิมส่งรูปสุดท้าย บางครั้งได้รูปว่าง
แก้ Code ใหม่เอารูปที่ 4 นับจากที่ Video มีการบันทึก
แล้วลบ jpg ทิ้ง
  1.  
  2. from slackclient import SlackClient
  3.  
  4. sc = SlackClient("xoxb-XXXXXXX")
  5.  
  6. import glob
  7. import os
  8.  
  9. #list jpg to array
  10. list_of_files = glob.glob('/home/pi/Pictures/*.jpg')
  11. if len(list_of_files) > 4:
  12.   file_select = list_of_files[4]
  13.   with open(file_select) as file_content:
  14.        sc.api_call(
  15.          "files.upload",
  16.          channels="CF6GEHBDF",
  17.          file=file_content,
  18.          title="IP Camera Room A 192.168.2.133."
  19.        )
  20. #delete jpg
  21. for i in glob.glob("/home/pi/Pictures/*.jpg"):
  22.   os.remove(i)

No comments:

Post a Comment