整體實現(xiàn)思路:
1. python編寫http接口(需要開機自啟)
2.python中調(diào)用shell
3.sh腳本中編寫svn自動拉取代碼
4.編寫網(wǎng)頁調(diào)用該接口
1.python編寫http接口(update_pc.py)
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
from flask import Flask
from flask import request
from flask import jsonify
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def getDouYinVideo():
? ? return jsonify({'noWatermarkUrl': 'videourl'})
if __name__ == '__main__':
? ? app.run(host='0.0.0.0')
注意:需要提前導(dǎo)入flask模塊窟勃,負(fù)責(zé)會報No module named flask粱腻。執(zhí)行命令:pip install flask
2.編寫svn拉取shell腳本(svn_update.sh)
#!/bin/sh
echo '>>>>>>>>update code>>>>>>>>>>'
cd /usr/local/apache/htdocs/PC
svn up
注意:此步驟需要提前安裝svn巩那。執(zhí)行命令:yum -y install ?subversion
首次檢出代碼時,要執(zhí)行:svn checkout svn://xxxx.xxx.xxx/project /usr/local/apache/htdocs/PC? (后面這個是指定目錄)
3.賦予svn_update.sh可執(zhí)行命令
chmod +x?svn_update.sh
4.python腳本編寫調(diào)用svn_update.sh
5.update_pc.py加入開機自啟
/etc/rc.local文件中添加一行:python /usr/local/python_shell/update_pc.py &?
6.網(wǎng)頁中ajax請求該接口即可
注意:若是阿里服務(wù)器即舌,需要開啟5000端口
附錄:
添加支持跨域請求:
def after_request(resp):
? ? resp.headers['Access-Control-Allow-Origin'] = '*'
? ? return resp
app.after_request(after_request);