Spaces:
Paused
Paused
Update wltv_server.py
Browse files- wltv_server.py +22 -15
wltv_server.py
CHANGED
|
@@ -5,7 +5,7 @@ import logging
|
|
| 5 |
from flask import Flask, send_file, jsonify
|
| 6 |
|
| 7 |
# Set up logging
|
| 8 |
-
logging.basicConfig(level=logging.INFO)
|
| 9 |
logger = logging.getLogger(__name__)
|
| 10 |
|
| 11 |
app = Flask(__name__)
|
|
@@ -15,16 +15,23 @@ extract_to_dir = 'extracted'
|
|
| 15 |
if not os.path.exists(extract_to_dir):
|
| 16 |
os.makedirs(extract_to_dir, exist_ok=True)
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
# Step 1: Download the zip file
|
| 19 |
def download_zip_file(url, output_path):
|
| 20 |
logger.info(f"Downloading from {url}...")
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# Step 2: Extract the file from the zip file
|
| 30 |
def extract_file(zip_path, extract_to_dir):
|
|
@@ -55,11 +62,14 @@ def update_files():
|
|
| 55 |
# Route to view logs
|
| 56 |
@app.route('/logs', methods=['GET'])
|
| 57 |
def get_logs():
|
| 58 |
-
# Read logs from the log file
|
| 59 |
try:
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
except Exception as e:
|
| 64 |
logger.error(f"Failed to read logs: {e}")
|
| 65 |
return jsonify({'error': 'Failed to read logs'}), 500
|
|
@@ -85,8 +95,5 @@ def serve_extracted_file():
|
|
| 85 |
return "File not found", 404
|
| 86 |
|
| 87 |
if __name__ == '__main__':
|
| 88 |
-
zip_url = 'http://epg-guide.com/wltv.dz' # Updated URL
|
| 89 |
-
zip_path = 'it_wltv_full.zip'
|
| 90 |
-
|
| 91 |
# Start the Flask web server
|
| 92 |
app.run(host='0.0.0.0', port=8080)
|
|
|
|
| 5 |
from flask import Flask, send_file, jsonify
|
| 6 |
|
| 7 |
# Set up logging
|
| 8 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
| 9 |
logger = logging.getLogger(__name__)
|
| 10 |
|
| 11 |
app = Flask(__name__)
|
|
|
|
| 15 |
if not os.path.exists(extract_to_dir):
|
| 16 |
os.makedirs(extract_to_dir, exist_ok=True)
|
| 17 |
|
| 18 |
+
# Update URL to the correct location
|
| 19 |
+
zip_url = 'http://epg-guide.com/wltv.dz'
|
| 20 |
+
zip_path = 'it_wltv_full.zip'
|
| 21 |
+
|
| 22 |
# Step 1: Download the zip file
|
| 23 |
def download_zip_file(url, output_path):
|
| 24 |
logger.info(f"Downloading from {url}...")
|
| 25 |
+
try:
|
| 26 |
+
response = requests.get(url)
|
| 27 |
+
if response.status_code == 200:
|
| 28 |
+
with open(output_path, 'wb') as f:
|
| 29 |
+
f.write(response.content)
|
| 30 |
+
logger.info(f"Downloaded zip file to {output_path} with size {len(response.content)} bytes")
|
| 31 |
+
else:
|
| 32 |
+
logger.error(f"Failed to download file. Status code: {response.status_code}")
|
| 33 |
+
except Exception as e:
|
| 34 |
+
logger.error(f"An error occurred while downloading the file: {e}")
|
| 35 |
|
| 36 |
# Step 2: Extract the file from the zip file
|
| 37 |
def extract_file(zip_path, extract_to_dir):
|
|
|
|
| 62 |
# Route to view logs
|
| 63 |
@app.route('/logs', methods=['GET'])
|
| 64 |
def get_logs():
|
|
|
|
| 65 |
try:
|
| 66 |
+
if os.path.exists('app.log'):
|
| 67 |
+
with open('app.log', 'r') as f:
|
| 68 |
+
logs = f.read()
|
| 69 |
+
return jsonify({'logs': logs}), 200
|
| 70 |
+
else:
|
| 71 |
+
logger.error("Log file does not exist")
|
| 72 |
+
return jsonify({'error': 'Log file does not exist'}), 500
|
| 73 |
except Exception as e:
|
| 74 |
logger.error(f"Failed to read logs: {e}")
|
| 75 |
return jsonify({'error': 'Failed to read logs'}), 500
|
|
|
|
| 95 |
return "File not found", 404
|
| 96 |
|
| 97 |
if __name__ == '__main__':
|
|
|
|
|
|
|
|
|
|
| 98 |
# Start the Flask web server
|
| 99 |
app.run(host='0.0.0.0', port=8080)
|