Spaces:
Build error
Build error
Commit ·
53dc202
1
Parent(s): 40df71d
try fix 3
Browse files- LoadBalancer.py +9 -47
LoadBalancer.py
CHANGED
|
@@ -93,7 +93,8 @@ class LoadBalancer:
|
|
| 93 |
self.remove_instance(instance_url)
|
| 94 |
|
| 95 |
# Compare and update actual JSON files after processing all reports
|
| 96 |
-
self.
|
|
|
|
| 97 |
|
| 98 |
def process_report(self, instance_url, report, temp_film_store, temp_tv_store):
|
| 99 |
film_store = report.get('film_store', {})
|
|
@@ -132,10 +133,10 @@ class LoadBalancer:
|
|
| 132 |
logging.info("Stopping polling.")
|
| 133 |
self.stop_event.set()
|
| 134 |
|
| 135 |
-
def
|
| 136 |
# Load current data
|
| 137 |
film_store_data = self.read_json(self.FILM_STORE_JSON_PATH)
|
| 138 |
-
|
| 139 |
|
| 140 |
# Compare and update film store
|
| 141 |
for title in list(film_store_data.keys()):
|
|
@@ -150,6 +151,11 @@ class LoadBalancer:
|
|
| 150 |
|
| 151 |
print(f'Film store updated.')
|
| 152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
# Compare and update TV store
|
| 154 |
for title in list(tv_store_data.keys()):
|
| 155 |
if title not in temp_tv_store:
|
|
@@ -205,50 +211,6 @@ class LoadBalancer:
|
|
| 205 |
print(f"Error getting system proxies: {e}")
|
| 206 |
return {}
|
| 207 |
|
| 208 |
-
def update_film_store_json(self,title, url):
|
| 209 |
-
"""
|
| 210 |
-
Updates the film store JSON with the new file.
|
| 211 |
-
|
| 212 |
-
Args:
|
| 213 |
-
title (str): The title of the film.
|
| 214 |
-
url (str): The url.
|
| 215 |
-
"""
|
| 216 |
-
FILM_STORE_JSON_PATH = self.FILM_STORE_JSON_PATH
|
| 217 |
-
|
| 218 |
-
film_store_data = {}
|
| 219 |
-
if os.path.exists(FILM_STORE_JSON_PATH):
|
| 220 |
-
with open(FILM_STORE_JSON_PATH, 'r') as json_file:
|
| 221 |
-
film_store_data = json.load(json_file)
|
| 222 |
-
|
| 223 |
-
film_store_data[title] = url
|
| 224 |
-
|
| 225 |
-
with open(FILM_STORE_JSON_PATH, 'w') as json_file:
|
| 226 |
-
json.dump(film_store_data, json_file, indent=2)
|
| 227 |
-
print(f'Film store updated with {title}.')
|
| 228 |
-
|
| 229 |
-
def update_tv_store_json(self, title, season, episode, url):
|
| 230 |
-
"""
|
| 231 |
-
Updates the TV store JSON with the new file, organizing by title, season, and episode.
|
| 232 |
-
"""
|
| 233 |
-
TV_STORE_JSON_PATH = self.TV_STORE_JSON_PATH
|
| 234 |
-
|
| 235 |
-
tv_store_data = {}
|
| 236 |
-
if os.path.exists(TV_STORE_JSON_PATH):
|
| 237 |
-
with open(TV_STORE_JSON_PATH, 'r') as json_file:
|
| 238 |
-
tv_store_data = json.load(json_file)
|
| 239 |
-
|
| 240 |
-
if title not in tv_store_data:
|
| 241 |
-
tv_store_data[title] = {}
|
| 242 |
-
|
| 243 |
-
if season not in tv_store_data[title]:
|
| 244 |
-
tv_store_data[title][season] = {}
|
| 245 |
-
|
| 246 |
-
tv_store_data[title][season][episode] = url
|
| 247 |
-
|
| 248 |
-
with open(TV_STORE_JSON_PATH, 'w') as json_file:
|
| 249 |
-
json.dump(tv_store_data, json_file, indent=2)
|
| 250 |
-
|
| 251 |
-
print(f'TV store updated with {title}, {season}, {episode}.')
|
| 252 |
|
| 253 |
@staticmethod
|
| 254 |
def clear_json_file(file_path):
|
|
|
|
| 93 |
self.remove_instance(instance_url)
|
| 94 |
|
| 95 |
# Compare and update actual JSON files after processing all reports
|
| 96 |
+
self.update_film_store_json(temp_film_store)
|
| 97 |
+
self.update_tv_store_json(temp_tv_store)
|
| 98 |
|
| 99 |
def process_report(self, instance_url, report, temp_film_store, temp_tv_store):
|
| 100 |
film_store = report.get('film_store', {})
|
|
|
|
| 133 |
logging.info("Stopping polling.")
|
| 134 |
self.stop_event.set()
|
| 135 |
|
| 136 |
+
def update_film_store_json(self, temp_film_store, ):
|
| 137 |
# Load current data
|
| 138 |
film_store_data = self.read_json(self.FILM_STORE_JSON_PATH)
|
| 139 |
+
|
| 140 |
|
| 141 |
# Compare and update film store
|
| 142 |
for title in list(film_store_data.keys()):
|
|
|
|
| 151 |
|
| 152 |
print(f'Film store updated.')
|
| 153 |
|
| 154 |
+
def update_tv_store_json(self, temp_tv_store):
|
| 155 |
+
"""
|
| 156 |
+
Updates the TV store JSON with the new file, organizing by title, season, and episode.
|
| 157 |
+
"""
|
| 158 |
+
tv_store_data = self.read_json(self.TV_STORE_JSON_PATH)
|
| 159 |
# Compare and update TV store
|
| 160 |
for title in list(tv_store_data.keys()):
|
| 161 |
if title not in temp_tv_store:
|
|
|
|
| 211 |
print(f"Error getting system proxies: {e}")
|
| 212 |
return {}
|
| 213 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
|
| 215 |
@staticmethod
|
| 216 |
def clear_json_file(file_path):
|