Tanvir1337 commited on
Commit
d6be317
1 Parent(s): 7044e76

init scripts

Browse files
scripts/1-extract_urls.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import sys
3
+
4
+ def extract_urls_to_file(json_data, output_filename="all_urls.txt"):
5
+ """Extracts URLs from a JSON object and writes them to a text file.
6
+
7
+ Args:
8
+ json_data: The JSON object containing the URLs.
9
+ output_filename: The name of the output text file (default: all_urls.txt).
10
+ """
11
+ try:
12
+ with open(output_filename, 'w') as outfile:
13
+ for category, urls in json_data.items():
14
+ for url in urls:
15
+ outfile.write(url.strip() + '\n')
16
+
17
+ except (IOError, json.JSONDecodeError) as e:
18
+ print(f"An error occurred: {e}")
19
+
20
+
21
+
22
+ if __name__ == "__main__":
23
+ if len(sys.argv) > 1:
24
+ json_filename = sys.argv[1]
25
+ try:
26
+ with open(json_filename, 'r') as f:
27
+ json_data = json.load(f)
28
+ except FileNotFoundError:
29
+ print(f"Error: File '{json_filename}' not found.")
30
+ sys.exit(1)
31
+ except json.JSONDecodeError:
32
+ print(f"Error: Invalid JSON format in '{json_filename}'.")
33
+ sys.exit(1)
34
+
35
+
36
+ if len(sys.argv) > 2:
37
+ output_filename = sys.argv[2]
38
+ extract_urls_to_file(json_data, output_filename)
39
+ print(f"URLs extracted to '{output_filename}'")
40
+ else:
41
+ extract_urls_to_file(json_data)
42
+ print("URLs extracted to 'all_urls.txt'")
43
+
44
+
45
+ else:
46
+ print("Usage: python script_name.py <json_filename> <output_filename>(optional)")
47
+ default_json = {
48
+ "ftp": [], "tv": [], "others": [], "all": []
49
+ }
50
+ extract_urls_to_file(default_json)
51
+ print("URLs (from default JSON) extracted to 'all_urls.txt'")
scripts/12-extract_urls.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import sys
3
+
4
+ def extract_addresses(json_data, output_filename="addresses.txt"):
5
+ """Extracts server addresses from JSON data and writes them to a text file.
6
+
7
+ Args:
8
+ json_data: The JSON object containing the server data.
9
+ output_filename: The name of the output text file (default: addresses.txt).
10
+ """
11
+ try:
12
+ data = json_data.get("Data", [])
13
+
14
+ with open(output_filename, 'w', encoding='utf-8') as outfile:
15
+ for server in data:
16
+ address = server.get("Address")
17
+ if address:
18
+ outfile.write(address.strip() + '\n')
19
+
20
+
21
+ except (IOError, json.JSONDecodeError) as e:
22
+ print(f"An error occurred: {e}")
23
+
24
+
25
+ if __name__ == "__main__":
26
+ if len(sys.argv) > 1:
27
+ json_filename = sys.argv[1]
28
+
29
+ try:
30
+ with open(json_filename, 'r', encoding='utf-8') as f:
31
+ json_data = json.load(f)
32
+
33
+ except FileNotFoundError:
34
+ print(f"Error: File '{json_filename}' not found.")
35
+ sys.exit(1)
36
+ except json.JSONDecodeError:
37
+ print(f"Error: Invalid JSON format in '{json_filename}'.")
38
+ sys.exit(1)
39
+
40
+
41
+ if len(sys.argv) > 2:
42
+ output_filename = sys.argv[2]
43
+ extract_addresses(json_data, output_filename)
44
+ print(f"Addresses extracted to '{output_filename}'")
45
+
46
+ else:
47
+ extract_addresses(json_data)
48
+ print("Addresses extracted to 'addresses.txt'")
49
+
50
+
51
+
52
+ else:
53
+ print("Usage: python script_name.py <json_filename> <output_filename>(optional)")
54
+ default_json = {"Data": []}
55
+ extract_addresses(default_json)
56
+ print("Addresses (from default JSON) extracted to 'addresses.txt'")
scripts/3-extract_urls.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import sys
3
+
4
+ def extract_hosts_to_file(json_data, output_filename="hosts.txt"):
5
+ """Extracts hosts from a JSON object and writes them to a file.
6
+
7
+ Args:
8
+ json_data: The JSON object containing the hosts.
9
+ output_filename: The name of the output text file (default: hosts.txt).
10
+ """
11
+ try:
12
+ with open(output_filename, 'w') as outfile:
13
+ for host in json_data.get("hosts", []):
14
+ outfile.write(host.strip() + '\n')
15
+
16
+ except (IOError, json.JSONDecodeError) as e:
17
+ print(f"An error occurred: {e}")
18
+
19
+
20
+ if __name__ == "__main__":
21
+ if len(sys.argv) > 1:
22
+ json_filename = sys.argv[1]
23
+ try:
24
+ with open(json_filename, 'r') as f:
25
+ json_data = json.load(f)
26
+ except FileNotFoundError:
27
+ print(f"Error: File '{json_filename}' not found.")
28
+ sys.exit(1)
29
+ except json.JSONDecodeError:
30
+ print(f"Error: Invalid JSON format in '{json_filename}'.")
31
+ sys.exit(1)
32
+
33
+ if len(sys.argv) > 2:
34
+ output_filename = sys.argv[2]
35
+ extract_hosts_to_file(json_data, output_filename)
36
+ print(f"Hosts extracted to '{output_filename}'")
37
+ else:
38
+ extract_hosts_to_file(json_data)
39
+ print("Hosts extracted to 'hosts.txt'")
40
+
41
+
42
+ else:
43
+ print("Usage: python script_name.py <json_filename> <output_filename>(optional)")
44
+ default_json = {"hosts": []}
45
+ extract_hosts_to_file(default_json)
46
+ print("Hosts (from default JSON) extracted to 'hosts.txt'")
scripts/4-extract_urls.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import sys
3
+
4
+ def extract_urls_to_file(json_data, output_filename="urls.txt"):
5
+ """Extracts URLs from server data and writes them to a text file.
6
+
7
+ Args:
8
+ json_data: The JSON object containing the server data.
9
+ output_filename: The name of the output text file (default: urls.txt).
10
+ """
11
+
12
+ try:
13
+ servers = json_data.get("servers", [])
14
+ with open(output_filename, 'w', encoding='utf-8') as outfile:
15
+ for server in servers:
16
+ url = server.get("url")
17
+ if url:
18
+ outfile.write(url.strip() + '\n')
19
+
20
+ except (IOError, json.JSONDecodeError) as e:
21
+ print(f"An error occurred: {e}")
22
+
23
+
24
+ if __name__ == "__main__":
25
+ if len(sys.argv) > 1:
26
+ json_filename = sys.argv[1]
27
+ try:
28
+ with open(json_filename, 'r', encoding='utf-8') as f:
29
+ json_data = json.load(f)
30
+ except FileNotFoundError:
31
+ print(f"Error: File '{json_filename}' not found.")
32
+ sys.exit(1)
33
+ except json.JSONDecodeError:
34
+ print(f"Error: Invalid JSON format in '{json_filename}'.")
35
+ sys.exit(1)
36
+
37
+ if len(sys.argv) > 2:
38
+ output_filename = sys.argv[2]
39
+ extract_urls_to_file(json_data, output_filename)
40
+ print(f"URLs extracted to '{output_filename}'")
41
+ else:
42
+ extract_urls_to_file(json_data)
43
+ print("URLs extracted to 'urls.txt'")
44
+
45
+
46
+ else:
47
+ print("Usage: python script_name.py <json_filename> <output_filename>(optional)")
48
+ default_json = {"servers": []}
49
+ extract_urls_to_file(default_json)
50
+ print("URLs (from default JSON) extracted to 'urls.txt'")
scripts/remove-duplicate-lines.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def remove_duplicates(input_file, output_file):
2
+ with open(input_file, 'r') as file:
3
+ lines = file.readlines()
4
+
5
+ unique_lines = set()
6
+ with open(output_file, 'w') as file:
7
+ for line in lines:
8
+ if line not in unique_lines:
9
+ file.write(line)
10
+ unique_lines.add(line)
11
+
12
+ if __name__ == "__main__":
13
+ import sys
14
+ if len(sys.argv) != 2:
15
+ print("Usage: python remove_duplicates.py <input_file>")
16
+ sys.exit(1)
17
+
18
+ input_file = sys.argv[1]
19
+ output_file = 'output_no_duplicates.txt'
20
+ remove_duplicates(input_file, output_file)
scripts/remove-empty-lines.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+
3
+ def remove_empty_lines(input_file, output_file):
4
+ with open(input_file, 'r') as file:
5
+ lines = file.readlines()
6
+
7
+ with open(output_file, 'w') as file:
8
+ for line in lines:
9
+ if line.strip():
10
+ file.write(line)
11
+
12
+ if __name__ == "__main__":
13
+ if len(sys.argv) != 2:
14
+ print("Usage: python remove_empty_lines.py <input_file>")
15
+ sys.exit(1)
16
+
17
+ input_file = sys.argv[1]
18
+ output_file = 'no_empty_lines.txt'
19
+ remove_empty_lines(input_file, output_file)
scripts/sort-lines.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def sort_lines(input_file, output_file):
2
+ with open(input_file, 'r') as file:
3
+ lines = file.readlines()
4
+
5
+ sorted_lines = sorted(lines)
6
+
7
+ with open(output_file, 'w') as file:
8
+ for line in sorted_lines:
9
+ file.write(line)
10
+
11
+ if __name__ == "__main__":
12
+ import sys
13
+ if len(sys.argv) != 2:
14
+ print("Usage: python sort_lines.py <input_file>")
15
+ sys.exit(1)
16
+
17
+ input_file = sys.argv[1]
18
+ output_file = 'output_sorted.txt'
19
+ sort_lines(input_file, output_file)