LoremPizza commited on
Commit
01bba9c
·
verified ·
1 Parent(s): 86dc739

Update wltv_server.py

Browse files
Files changed (1) hide show
  1. wltv_server.py +11 -8
wltv_server.py CHANGED
@@ -2,8 +2,8 @@ import os
2
  import requests
3
  import zipfile
4
  import logging
5
- from flask import Flask, send_file, Response
6
- from io import StringIO
7
 
8
  # Set up logging
9
  log_stream = StringIO()
@@ -14,6 +14,9 @@ app = Flask(__name__)
14
 
15
  # Ensure the extracted directory exists
16
  extract_to_dir = 'extracted'
 
 
 
17
  if not os.path.exists(extract_to_dir):
18
  os.makedirs(extract_to_dir, exist_ok=True)
19
 
@@ -73,13 +76,13 @@ def serve_logs():
73
  log_contents = log_stream.getvalue()
74
  return Response(log_contents, mimetype='text/plain')
75
 
76
- if __name__ == '__main__':
77
- zip_url = 'http://api.epg-guide.com/wltv.dz'
78
- zip_path = 'it_wltv_full.zip'
79
-
80
- # Download and extract the zip file
81
  download_zip_file(zip_url, zip_path)
82
  extract_file(zip_path, extract_to_dir)
 
83
 
 
84
  # Start the Flask web server
85
- app.run(host='0.0.0.0', port=8080)
 
2
  import requests
3
  import zipfile
4
  import logging
5
+ from flask import Flask, send_file, Response, jsonify
6
+ from io import StringIO # For Python 3
7
 
8
  # Set up logging
9
  log_stream = StringIO()
 
14
 
15
  # Ensure the extracted directory exists
16
  extract_to_dir = 'extracted'
17
+ zip_path = 'it_wltv_full.zip'
18
+ zip_url = 'http://api.epg-guide.com/wltv.dz'
19
+
20
  if not os.path.exists(extract_to_dir):
21
  os.makedirs(extract_to_dir, exist_ok=True)
22
 
 
76
  log_contents = log_stream.getvalue()
77
  return Response(log_contents, mimetype='text/plain')
78
 
79
+ # Route to manually trigger the download and extraction process
80
+ @app.route('/update', methods=['POST'])
81
+ def update_files():
 
 
82
  download_zip_file(zip_url, zip_path)
83
  extract_file(zip_path, extract_to_dir)
84
+ return jsonify({'status': 'Update complete'}), 200
85
 
86
+ if __name__ == '__main__':
87
  # Start the Flask web server
88
+ app.run(host='0.0.0.0', port=8080)