main.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import os
  2. import requests
  3. import json
  4. # current_path
  5. current_path = os.getcwd()
  6. # 1.小程序打包
  7. def build_mini_program():
  8. command_str = (
  9. "git clone https://git.yishihui.com/weapp/longVideoFactory.git;"
  10. "cd longVideoFactory;"
  11. "git pull;"
  12. "git checkout dev;"
  13. "git pull;"
  14. "n 8;"
  15. "cnpm install && npm install ;"
  16. "npm run build && npm run build:other;"
  17. )
  18. if os.system(command_str) == 0:
  19. print("1.打包成功")
  20. # create_preview()
  21. else:
  22. print("1.打包失败")
  23. # 2.微信编译图片
  24. def create_preview():
  25. # 小程序 cli path for mac
  26. wx_cli ="/Applications/wechatwebdevtools.app/Contents/MacOS/cli"
  27. dist_path = os.path.join(current_path,'longVideoFactory/dist/vlog')
  28. code_img_path = os.path.join(current_path,'1.png')
  29. f_read = os.popen(wx_cli+" preview --project "+dist_path+" --qr-output "+code_img_path+" --qr-format image").read()
  30. if "[error]" in f_read:
  31. print(f_read)
  32. else:
  33. print("2.微信小程序编译成功")
  34. # create_preview()
  35. # https://open.feishu.cn/open-apis/bot/v2/hook/a924b6a5-86ef-4c76-a7e4-eb42056f70cc
  36. def upload_img_by_feishu(token):
  37. key = ""
  38. url = "https://open.feishu.cn/open-apis/im/v1/images"
  39. files = {
  40. "image_type":(None,"message"),
  41. "image":('1.png',open(os.path.join(current_path,"1.png"),"rb"),"image/png")
  42. }
  43. headers = {
  44. "Authorization":"Bearer "+token,
  45. }
  46. res = requests.post(url,headers=headers,files=files,verify = False).json()
  47. if res["code"] == 0:
  48. key = res["data"]["image_key"]
  49. else:
  50. print("飞书上传图片失败")
  51. return key
  52. def tenant_access_token_by_feishu():
  53. token = ""
  54. url = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal"
  55. params = {
  56. "app_id":"cli_a1ec07458838d00c",
  57. "app_secret":"Ngm0kfaLkZnpM2T2DH7L8cM5hdAqY0hI"
  58. }
  59. res = requests.post(url,data=params,verify = False).json()
  60. if res["code"] == 0:
  61. token = res["tenant_access_token"]
  62. else:
  63. print("获取飞书签名失败")
  64. return token
  65. def send_msg_by_feishu(token,img_key):
  66. # webhook
  67. webhook_url = "https://open.feishu.cn/open-apis/bot/v2/hook/a924b6a5-86ef-4c76-a7e4-eb42056f70cc"
  68. headers = {
  69. "Authorization":"Bearer "+token,
  70. "Content-Type": "application/json;charset=UTF-8"
  71. }
  72. params = {
  73. "msg_type": "post",
  74. "content": {
  75. "post": {
  76. "zh_cn": {
  77. "title": "Vlog小程序预览码",
  78. "content": [
  79. # [
  80. # {
  81. # "tag": "text",
  82. # "text": "第二行 :"
  83. # },
  84. # {
  85. # "tag": "text",
  86. # "text": "文本测试"
  87. # }
  88. # ],
  89. [
  90. {
  91. "tag": "img",
  92. "image_key": "img_v2_223c3413-488a-4af6-bd36-6563a9ef185g",
  93. "width": 500,
  94. "height": 500
  95. }
  96. ]]
  97. }
  98. }
  99. }
  100. }
  101. res = requests.post(webhook_url,headers=headers,data=json.dumps(params),verify = False).json()
  102. if res["StatusCode"] == 0:
  103. print("飞书消息发送成功")
  104. else:
  105. print("飞书消息发送失败")
  106. # ------- 微信打包 ------
  107. # 1.小程序打包
  108. build_mini_program()
  109. # 2.微信编译图片
  110. create_preview()
  111. # -------- 飞书 --------
  112. # 1.获取签名
  113. token = tenant_access_token_by_feishu()
  114. # 2.获取imgKey
  115. img_key = upload_img_by_feishu(token)
  116. # 3.飞书发送消息
  117. send_msg_by_feishu(token,img_key)