updateDomains: controlla anche i findhost, elimina se canale non più esistente

This commit is contained in:
mac12m99
2021-04-11 17:17:21 +02:00
parent 2ef9f08bd7
commit e1fb73139a

View File

@@ -42,9 +42,14 @@ if __name__ == '__main__':
with open(fileJson) as f:
data = json.load(f)
result = data['direct']
chList = os.listdir('channels')
for chann, host in sorted(data['direct'].items()):
for k in data.keys():
for chann, host in sorted(data[k].items()):
if chann + '.json' not in chList:
print(chann + ' not exists anymore')
del data[k][chann]
continue
# to get an idea of the timing
# useful only if you control all channels
# for channels with error 522 about 40 seconds are lost ...
@@ -54,11 +59,11 @@ if __name__ == '__main__':
# all right
if rslt['code'] == 200:
result[chann] = host
data[k][chann] = host
# redirect
elif str(rslt['code']).startswith('3'):
# result[chann] = str(rslt['code']) +' - '+ rslt['redirect'][:-1]
result[chann] = rslt['redirect']
# data[k][chann] = str(rslt['code']) +' - '+ rslt['redirect'][:-1]
data[k][chann] = rslt['redirect']
# cloudflare...
elif rslt['code'] in [429, 503, 403]:
from lib import proxytranslate
@@ -67,7 +72,7 @@ if __name__ == '__main__':
print('Cloudflare riconosciuto')
try:
page_data = proxytranslate.process_request_proxy(host).get('data', '')
result[chann] = re.search('<base href="([^"]+)', page_data).group(1)
data[k][chann] = re.search('<base href="([^"]+)', page_data).group(1)
rslt['code_new'] = 200
except Exception as e:
import traceback
@@ -83,10 +88,9 @@ if __name__ == '__main__':
print('Errore Sconosciuto - '+str(rslt['code']) +' - '+ host)
print("check #### FINE #### rslt :%s " % (rslt))
if result[chann].endswith('/'):
result[chann] = result[chann][:-1]
if data[k][chann].endswith('/'):
data[k][chann] = data[k][chann][:-1]
result = {'findhost': data['findhost'], 'direct': result}
# I write the updated file
with open(fileJson, 'w') as f:
json.dump(result, f, sort_keys=True, indent=4)
json.dump(data, f, sort_keys=True, indent=4)