feishu_inform_util.py 925 B

123456789101112131415161718192021222324252627282930
  1. # -*- coding: utf-8 -*-
  2. import json
  3. from datetime import datetime
  4. import pytz
  5. import requests
  6. def send_card_msg_to_feishu(webhook, card_json):
  7. """发送消息到飞书"""
  8. headers = {'Content-Type': 'application/json'}
  9. payload_message = {
  10. "msg_type": "interactive",
  11. "card": card_json
  12. }
  13. print(f"推送飞书消息webhook地址 - {webhook}, 消息内容: {json.dumps(payload_message)}")
  14. response = requests.request('POST', url=webhook, headers=headers, data=json.dumps(payload_message))
  15. print(f"推送飞书消息返回结果: {response.text}")
  16. def timestamp_format(timestamp: str) -> str:
  17. try:
  18. return (datetime.utcfromtimestamp(int(timestamp))
  19. .replace(tzinfo=pytz.UTC)
  20. .astimezone(pytz.timezone('Asia/Shanghai'))
  21. .strftime('%Y-%m-%d %H:%M:%S')
  22. )
  23. except ValueError as e:
  24. return timestamp