LoremPizza commited on
Commit
5b10e73
·
verified ·
1 Parent(s): a9f1355

Create run.py

Browse files
Files changed (1) hide show
  1. run.py +45 -0
run.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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__':
32
+ zip_url = 'http://api.epg-guide.com/wltv.dz'
33
+ zip_path = 'it_wltv_full.zip'
34
+ extract_to_dir = 'extracted'
35
+
36
+ # Create the directory if it doesn't exist
37
+ if not os.path.exists(extract_to_dir):
38
+ os.makedirs(extract_to_dir)
39
+
40
+ # Download and extract the zip file
41
+ download_zip_file(zip_url, zip_path)
42
+ extract_file(zip_path, extract_to_dir)
43
+
44
+ # Start the Flask web server
45
+ app.run(host='0.0.0.0', port=8080)