changed restart_this_app to display html with data from json

This commit is contained in:
root 2023-05-26 00:25:13 +00:00
parent f11ee9f51b
commit 5f47adf1e8
4 changed files with 35 additions and 15 deletions

2
app.py
View File

@ -12,7 +12,7 @@ def webhook():
subprocess.run(['git', 'pull']) subprocess.run(['git', 'pull'])
# Restart the example_app # Restart the example_app
subprocess.run(['systemctl', 'stop', 'restart_this_app.service']) subprocess.run(['systemctl', 'restart', 'restart_this_app.service'])
return 'Success!', 200 return 'Success!', 200
else: else:

3
data.json Normal file
View File

@ -0,0 +1,3 @@
{
"text": "Hello World!"
}

View File

@ -1,14 +1,14 @@
from flask import Flask, request from flask import Flask, render_template
import json import json
app = Flask(__name__) app = Flask(__name__)
@app.route('/restart-this-app') @app.route('/restart-this-app')
def funky_function(): def render_message():
data = { 'message': "Joe mama" } with open('data.json', encoding='UTF-8') as file:
response = json.dumps(data) data = json.load(file)
return response, 200, { 'Content-Type': 'application/json' } return render_template('index.html', data=data)
if __name__ == '__main__': if __name__ == '__main__':
app.run(host='0.0.0.0', port=5002) app.run(host='0.0.0.0', port=5002)

17
templates/index.html Normal file
View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Recipe</title>
</head>
<body>
<h1>{{ data.text }}</h1>
</body>
</html>