main.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import os
  2. import requests
  3. import json
  4. from flask import Flask,request,redirect
  5. from flask_cors import CORS
  6. app = Flask(__name__,static_folder="static")
  7. CORS(app, resources=r'/*')
  8. # current_path
  9. current_path = os.getcwd()
  10. # 1.小程序打包
  11. # def build_mini_program():
  12. # command_str = (
  13. # "git clone https://git.yishihui.com/weapp/longVideoFactory.git;"
  14. # "cd longVideoFactory;"
  15. # "git pull;"
  16. # "git checkout dev;"
  17. # "git pull;"
  18. # "n 8;"
  19. # "cnpm install && npm install ;"
  20. # "npm run build && npm run build:other;"
  21. # )
  22. # if os.system(command_str) == 0:
  23. # print("1.打包成功")
  24. # # create_preview()
  25. # else:
  26. # print("1.打包失败")
  27. # # 2.微信编译图片
  28. # def create_preview():
  29. # # 小程序 cli path for mac
  30. # wx_cli ="/Applications/wechatwebdevtools.app/Contents/MacOS/cli"
  31. # dist_path = os.path.join(current_path,'longVideoFactory/dist/vlog')
  32. # code_img_path = os.path.join(current_path,'1.png')
  33. # f_read = os.popen(wx_cli+" preview --project "+dist_path+" --qr-output "+code_img_path+" --qr-format image").read()
  34. # if "[error]" in f_read:
  35. # print(f_read)
  36. # else:
  37. # print("2.微信小程序编译成功")
  38. # # create_preview()
  39. # # https://open.feishu.cn/open-apis/bot/v2/hook/a924b6a5-86ef-4c76-a7e4-eb42056f70cc
  40. # def upload_img_by_feishu(token):
  41. # key = ""
  42. # url = "https://open.feishu.cn/open-apis/im/v1/images"
  43. # files = {
  44. # "image_type":(None,"message"),
  45. # "image":('1.png',open(os.path.join(current_path,"1.png"),"rb"),"image/png")
  46. # }
  47. # headers = {
  48. # "Authorization":"Bearer "+token,
  49. # }
  50. # res = requests.post(url,headers=headers,files=files,verify = False).json()
  51. # if res["code"] == 0:
  52. # key = res["data"]["image_key"]
  53. # else:
  54. # print("飞书上传图片失败")
  55. # return key
  56. # def tenant_access_token_by_feishu():
  57. # token = ""
  58. # url = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal"
  59. # params = {
  60. # "app_id":"cli_a1ec07458838d00c",
  61. # "app_secret":"Ngm0kfaLkZnpM2T2DH7L8cM5hdAqY0hI"
  62. # }
  63. # res = requests.post(url,data=params,verify = False).json()
  64. # if res["code"] == 0:
  65. # token = res["tenant_access_token"]
  66. # else:
  67. # print("获取飞书签名失败")
  68. # return token
  69. # def send_msg_by_feishu(token,img_key):
  70. # # webhook
  71. # webhook_url = "https://open.feishu.cn/open-apis/bot/v2/hook/a924b6a5-86ef-4c76-a7e4-eb42056f70cc"
  72. # headers = {
  73. # "Authorization":"Bearer "+token,
  74. # "Content-Type": "application/json;charset=UTF-8"
  75. # }
  76. # params = {
  77. # "msg_type": "post",
  78. # "content": {
  79. # "post": {
  80. # "zh_cn": {
  81. # "title": "Vlog小程序预览码",
  82. # "content": [
  83. # [
  84. # {
  85. # "tag": "img",
  86. # "image_key": "img_v2_223c3413-488a-4af6-bd36-6563a9ef185g",
  87. # "width": 500,
  88. # "height": 500
  89. # }
  90. # ]]
  91. # }
  92. # }
  93. # }
  94. # }
  95. # res = requests.post(webhook_url,headers=headers,data=json.dumps(params),verify = False).json()
  96. # if res["StatusCode"] == 0:
  97. # print("飞书消息发送成功")
  98. # else:
  99. # print("飞书消息发送失败")
  100. # # ------- 微信打包 ------
  101. # # 1.小程序打包
  102. # # build_mini_program()
  103. # # 2.微信编译图片
  104. # # create_preview()
  105. # # 3.切换小程序环境
  106. # # -------- 飞书 --------
  107. # # 1.获取签名
  108. # # token = tenant_access_token_by_feishu()
  109. # # 2.获取imgKey
  110. # # img_key = upload_img_by_feishu(token)
  111. # # 3.飞书发送消息
  112. # # send_msg_by_feishu(token,img_key)
  113. @app.route('/')
  114. def func():
  115. return 'Welcome to auto-mini-program-build-preview server. only can run on MacOS.'
  116. # @app.route('/send',methods=['POST'])
  117. # def send():
  118. # form_webhook_url = request.form["webrhook_url"]
  119. # form_branch = request.form["branch"]
  120. # form_name = request.form["name"]
  121. # res = {"code":0,"msg":'发送成功'}
  122. # res = {"code":1,"msg":''}
  123. # return request.form
  124. @app.route("/getBranch")
  125. def get_branch():
  126. # 查看所有分支
  127. command_str= (
  128. "cd longVideoFactory;"
  129. "git branch -a;"
  130. )
  131. f_read = os.popen(command_str).read()
  132. branch_list = []
  133. for item in f_read.split():
  134. if "->" not in item and "origin/master" not in item and "HEAD" not in item and "*" not in item:
  135. branch_list.append(item.replace("remotes/origin/",""))
  136. res = {"code":0,"data":branch_list}
  137. return res
  138. if __name__ == '__main__':
  139. app.run(host='0.0.0.0', port=7777, debug=False)
  140. # 修改环境文件
  141. def edit_mode_by_file(project,mode):
  142. path = os.path.join(current_path,"longVideoFactory/dist/"+project+"/network/volatileConfig.js")
  143. file_lines = []
  144. with open(path,"r") as f:
  145. for item in f.readlines():
  146. if "export const currentMode" in item:
  147. item = "export const currentMode = MODE."+mode+" \n"
  148. file_lines.append(item)
  149. f.close()
  150. with open(path,"w") as f2:
  151. f2.writelines(file_lines)
  152. f2.close()
  153. # edit_mode_by_file("vlog")