-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython.py
More file actions
32 lines (23 loc) · 874 Bytes
/
python.py
File metadata and controls
32 lines (23 loc) · 874 Bytes
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
import sys
def normalize_netscape_file(infile, outfile):
with open(infile, "r", encoding="utf-8") as f:
lines = f.readlines()
out_lines = []
out_lines.append("# Netscape HTTP Cookie File\n")
for line in lines:
line = line.strip()
if not line or line.startswith("#"):
continue
parts = line.split()
if len(parts) != 7:
print(f"Skipping invalid line: {line}")
continue
# Re-join strictly with tabs
out_lines.append("\t".join(parts) + "\n")
with open(outfile, "w", encoding="utf-8", newline="\n") as f:
f.writelines(out_lines)
print(f"✅ Normalized file written to {outfile}")
if __name__ == "__main__":
infile = sys.argv[1]
outfile = sys.argv[2] if len(sys.argv) > 2 else infile + ".fixed"
normalize_netscape_file(infile, outfile)