Skip to content

Commit

Permalink
Add pre-startup checks
Browse files Browse the repository at this point in the history
  • Loading branch information
essesoul committed Mar 18, 2024
1 parent 1bb6756 commit 700ac66
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/afdian.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
try:
from dotenv import load_dotenv
except:
os.system("pip install -r requirements.txt")
from dotenv import load_dotenv
print("未找到dotenv模块")


def db_file():
Expand Down
35 changes: 29 additions & 6 deletions src/cloudreve_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,42 @@
try:
from flask import Flask, request, Response
except:
os.system('pip install -r requirements.txt')
from flask import Flask, request, Response
print("未找到flask模块")

try:
from gevent import pywsgi
except:
os.system('pip install -r requirements.txt')
from gevent import pywsgi
print("未找到gevent模块")
try:
from dotenv import load_dotenv
except:
os.system('pip install -r requirements.txt')
from dotenv import load_dotenv
print("未找到dotenv模块")
app = Flask(__name__)


# 初始化检查
def check():
# 判断.env文件是否存在
if os.path.exists('.env'):
if os.environ.get('SITE_URL') == "":
print("SITE_URL未设置,已停止运行")
exit()
if os.environ.get('USER_ID') == "":
print("USER_ID未设置,已停止运行")
exit()
if os.environ.get('TOKEN') == "":
print("TOKEN未设置,已停止运行")
exit()
if os.environ.get('PORT') == "":
print("PORT未设置,已停止运行")
exit()
print("初始化检查通过")
return
else:
print("未找到.env文件,已停止运行")
exit()


@app.route('/afdian', methods=['POST'])
def respond():
# 解析返回的json值
Expand Down Expand Up @@ -104,6 +124,9 @@ def order():
return Response(back, mimetype='application/json')


# 初始化检查
check()

print("Cloudreve Afdian Pay Server\t已启动\nGithub: https://github.com/essesoul/Cloudreve-AfdianPay")
print("-------------------------")
load_dotenv('.env')
Expand Down

0 comments on commit 700ac66

Please sign in to comment.