-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
43 lines (39 loc) · 1.3 KB
/
main.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
import base64
# Read files
with open("_add.txt", "r", encoding="utf-8") as add_file:
_add = add_file.read().strip()
with open("_delete.txt", "r", encoding="utf-8") as delete_file:
_delete = delete_file.read().strip()
with open("index.html", "rb") as index_file:
_list = base64.b64decode(index_file.read()).decode("utf-8")
# Process _add.txt contents
add_list = [
line.strip().replace("*.", "||", 1)
for line in _add.split("\n")
if line.strip().startswith("*.")
]
# Process _delete.txt contents
delete_list = [
line.strip().split()[0]
for line in _delete.split("\n")
if line.strip().startswith("||")
]
# Combine lists, remove duplicates,then delete items in _delete.txt
final_list = ["[AutoProxy]"] + sorted(
[
item
for item in list(set(_list.split("\n")[1:] + add_list))
if item not in delete_list and item.count("||") == 1
]
)
# Write back to index.html as base64
with open("index.html", "wb") as index_file:
index_file.write(base64.b64encode("\n".join(final_list).encode("utf-8")))
print("index.html updated!")
# Clear _add.txt and _delete.txt
with open("_add.txt", "w") as add_file:
add_file.write("")
print("_add.txt cleaned!")
with open("_delete.txt", "w") as delete_file:
delete_file.write("")
print("_delete.txt cleaned!")