-
Notifications
You must be signed in to change notification settings - Fork 0
/
app-v5.py
69 lines (58 loc) · 2.22 KB
/
app-v5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from flask import Flask, render_template, jsonify, request
import requests
from flask_cors import CORS
import subprocess
import os
app = Flask(__name__)
CORS(app)
@app.route('/')
def home():
# Construct the path to the "combined_output.txt" file
file_path = os.path.join("requests_combined", "combined_output.txt")
# Read content from the "combined_output.txt" file
try:
with open(file_path, "r") as file:
file_content = file.read()
except FileNotFoundError:
file_content = "File not found."
return render_template('index.html', file_content=file_content)
@app.route('/check_status')
def check_status():
try:
response = requests.get('http://192.168.10.14')
if response.status_code >= 200 and response.status_code < 350:
return jsonify({'status': 'online', 'statusCode': response.status_code})
else:
return jsonify({'status': 'offline', 'statusCode': response.status_code})
except requests.RequestException as e:
return jsonify({'status': 'error', 'message': str(e)})
@app.route('/run_load_script', methods=['POST'])
def run_load_script():
try:
# Run the load.py script using subprocess
subprocess.run(['python', 'load.py'])
return 'Script executed successfully!'
except Exception as e:
return f'Error executing script: {str(e)}'
@app.route('/file_content')
def get_file_content():
# Construct the path to the "combined_output.txt" file
file_path = os.path.join("requests_combined", "combined_output.txt")
# Read content from the "combined_output.txt" file
try:
with open(file_path, "r") as file:
file_content = file.read()
except FileNotFoundError:
file_content = "File not found."
return jsonify({'file_content': file_content})
@app.route('/save_request_website', methods=['POST'])
def save_request_website():
try:
website_data = request.form.get('website_data')
with open('request_website.txt', 'w') as file:
file.write(website_data)
return 'Website data saved successfully!'
except Exception as e:
return f'Error saving website data: {str(e)}'
if __name__ == '__main__':
app.run(debug=True)