forked from jvxis/regolancer-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
removepeers.py
64 lines (48 loc) · 1.84 KB
/
removepeers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import json
import os
def process_and_remove_from_config(file_path, channel_ids):
with open(file_path, 'r') as file:
config = json.load(file)
exclude_from = set(config.get('exclude_from', []))
to = set(config.get('to', []))
found_and_removed = (channel_ids & exclude_from) | (channel_ids & to)
exclude_from -= found_and_removed
to -= found_and_removed
config['exclude_from'] = list(exclude_from)
config['to'] = list(to)
with open(file_path, 'w') as file:
json.dump(config, file, indent=4)
return config, found_and_removed
def input_channel_ids():
ids = input("Enter the Channel IDs separated by commas: ")
return set(id.strip() for id in ids.split(','))
script_directory = os.path.dirname(os.path.abspath(__file__))
channel_ids_to_remove = input_channel_ids()
channels_list_path = os.path.join(script_directory, 'channels_list.txt')
with open(channels_list_path, 'r') as file:
channels = file.readlines()
channel_dict = {}
for line in channels:
if ':' in line:
name, id = line.split(':')
elif '|' in line:
name, id = line.split('|')
else:
name, id = line.split()
name = name.strip()
id = id.strip()
channel_dict[id] = name
results = []
file_path = os.path.join(script_directory, 'default.json')
if os.path.exists(file_path):
config, found_and_removed = process_and_remove_from_config(file_path, channel_ids_to_remove)
results.append((file_path, config, found_and_removed))
else:
print(f"File {file_path} does not exist.")
for file_path, config, found_and_removed in results:
print(f"Updated configurations for {file_path}:")
print(json.dumps(config, indent=4))
print("\nChannels removed from lists:")
for id in found_and_removed:
print(f"{channel_dict.get(id, 'Unknown')} : {id}")
print("\n" + "="*50 + "\n")