LoremPizza commited on
Commit
0b22be1
·
verified ·
1 Parent(s): 55d0ad5

Update wltv_server.py

Browse files
Files changed (1) hide show
  1. wltv_server.py +15 -3
wltv_server.py CHANGED
@@ -1,31 +1,43 @@
1
  import os
2
  import requests
3
  import zipfile
 
4
  from flask import Flask, send_file
5
 
 
 
 
 
6
  app = Flask(__name__)
7
 
8
  # Step 1: Download the zip file
9
  def download_zip_file(url, output_path):
 
10
  response = requests.get(url)
11
  with open(output_path, 'wb') as f:
12
  f.write(response.content)
13
- print(f"Downloaded zip file to {output_path}")
14
 
15
  # Step 2: Extract the file from the zip file
16
  def extract_file(zip_path, extract_to_dir):
 
17
  with zipfile.ZipFile(zip_path, 'r') as zip_ref:
18
  zip_ref.extractall(extract_to_dir)
19
- print(f"Extracted zip file to {extract_to_dir}")
20
 
21
  # Step 3: Set up a Flask route to expose the extracted file
22
  @app.route('/wltv', methods=['GET'])
23
  def serve_extracted_file():
24
- # Assuming the file is named "it_wltv_full" inside the extracted directory
 
 
 
25
  file_path = os.path.join('extracted', 'it_wltv_full')
26
  if os.path.exists(file_path):
 
27
  return send_file(file_path, as_attachment=False, mimetype='text/plain')
28
  else:
 
29
  return "File not found", 404
30
 
31
  if __name__ == '__main__':
 
1
  import os
2
  import requests
3
  import zipfile
4
+ import logging
5
  from flask import Flask, send_file
6
 
7
+ # Set up logging
8
+ logging.basicConfig(level=logging.INFO)
9
+ logger = logging.getLogger(__name__)
10
+
11
  app = Flask(__name__)
12
 
13
  # Step 1: Download the zip file
14
  def download_zip_file(url, output_path):
15
+ logger.info(f"Downloading from {url}...")
16
  response = requests.get(url)
17
  with open(output_path, 'wb') as f:
18
  f.write(response.content)
19
+ logger.info(f"Downloaded zip file to {output_path}")
20
 
21
  # Step 2: Extract the file from the zip file
22
  def extract_file(zip_path, extract_to_dir):
23
+ logger.info(f"Extracting {zip_path} to {extract_to_dir}...")
24
  with zipfile.ZipFile(zip_path, 'r') as zip_ref:
25
  zip_ref.extractall(extract_to_dir)
26
+ logger.info(f"Extracted zip file to {extract_to_dir}")
27
 
28
  # Step 3: Set up a Flask route to expose the extracted file
29
  @app.route('/wltv', methods=['GET'])
30
  def serve_extracted_file():
31
+ # Log contents of extracted directory for debugging
32
+ extracted_files = os.listdir('extracted')
33
+ logger.info(f"Files in 'extracted' directory: {extracted_files}")
34
+
35
  file_path = os.path.join('extracted', 'it_wltv_full')
36
  if os.path.exists(file_path):
37
+ logger.info(f"Serving file from {file_path}")
38
  return send_file(file_path, as_attachment=False, mimetype='text/plain')
39
  else:
40
+ logger.error("File not found")
41
  return "File not found", 404
42
 
43
  if __name__ == '__main__':