Spaces:
Paused
Paused
Update wltv_server.py
Browse files- wltv_server.py +10 -10
wltv_server.py
CHANGED
|
@@ -49,8 +49,8 @@ def extract_gz_file(gz_path, extract_to_dir):
|
|
| 49 |
except Exception as e:
|
| 50 |
logger.error(f"An error occurred while extracting the file: {e}")
|
| 51 |
|
| 52 |
-
# Function to get the current program for
|
| 53 |
-
def get_current_program(channel_id
|
| 54 |
xml_file = os.path.join(extract_to_dir, 'it_wltv_full.xml')
|
| 55 |
if not os.path.exists(xml_file):
|
| 56 |
logger.error("XML file does not exist for program data")
|
|
@@ -68,10 +68,10 @@ def get_current_program(channel_id="skytg24"):
|
|
| 68 |
start_time = datetime.strptime(programme.get('start')[:14], "%Y%m%d%H%M%S")
|
| 69 |
stop_time = datetime.strptime(programme.get('stop')[:14], "%Y%m%d%H%M%S")
|
| 70 |
if start_time <= current_time < stop_time:
|
| 71 |
-
title = programme.find('title').text
|
| 72 |
-
desc = programme.find('desc').text
|
| 73 |
return {"title": title, "description": desc}
|
| 74 |
-
logger.info("No current program found for
|
| 75 |
return None
|
| 76 |
except Exception as e:
|
| 77 |
logger.error(f"Failed to parse XML file: {e}")
|
|
@@ -122,14 +122,14 @@ def update_files():
|
|
| 122 |
|
| 123 |
return "Files updated", 200
|
| 124 |
|
| 125 |
-
# Route to serve the current program
|
| 126 |
-
@app.route('/<
|
| 127 |
-
def
|
| 128 |
-
program_info = get_current_program(
|
| 129 |
if program_info:
|
| 130 |
return jsonify(program_info)
|
| 131 |
else:
|
| 132 |
-
return "No current program found for
|
| 133 |
|
| 134 |
if __name__ == '__main__':
|
| 135 |
file_url = 'http://epg-guide.com/wltv.gz'
|
|
|
|
| 49 |
except Exception as e:
|
| 50 |
logger.error(f"An error occurred while extracting the file: {e}")
|
| 51 |
|
| 52 |
+
# Function to get the current program for a channel
|
| 53 |
+
def get_current_program(channel_id):
|
| 54 |
xml_file = os.path.join(extract_to_dir, 'it_wltv_full.xml')
|
| 55 |
if not os.path.exists(xml_file):
|
| 56 |
logger.error("XML file does not exist for program data")
|
|
|
|
| 68 |
start_time = datetime.strptime(programme.get('start')[:14], "%Y%m%d%H%M%S")
|
| 69 |
stop_time = datetime.strptime(programme.get('stop')[:14], "%Y%m%d%H%M%S")
|
| 70 |
if start_time <= current_time < stop_time:
|
| 71 |
+
title = programme.find('title').text if programme.find('title') is not None else "No title"
|
| 72 |
+
desc = programme.find('desc').text if programme.find('desc') is not None else "No description"
|
| 73 |
return {"title": title, "description": desc}
|
| 74 |
+
logger.info(f"No current program found for {channel_id}.")
|
| 75 |
return None
|
| 76 |
except Exception as e:
|
| 77 |
logger.error(f"Failed to parse XML file: {e}")
|
|
|
|
| 122 |
|
| 123 |
return "Files updated", 200
|
| 124 |
|
| 125 |
+
# Route to serve the current program for a specific channel
|
| 126 |
+
@app.route('/<channel_id>/now', methods=['GET'])
|
| 127 |
+
def current_program(channel_id):
|
| 128 |
+
program_info = get_current_program(channel_id)
|
| 129 |
if program_info:
|
| 130 |
return jsonify(program_info)
|
| 131 |
else:
|
| 132 |
+
return "No current program found for this channel.", 404
|
| 133 |
|
| 134 |
if __name__ == '__main__':
|
| 135 |
file_url = 'http://epg-guide.com/wltv.gz'
|