-
Notifications
You must be signed in to change notification settings - Fork 3
/
extensor.py
31 lines (23 loc) · 1020 Bytes
/
extensor.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
import os
import re
import sys
def check_extension(file_path, extension):
with open(file_path, 'r') as file:
urls = file.readlines()
urls_with_extension = []
for url in urls:
url = url.strip()
if url.endswith(f".{extension}"):
urls_with_extension.append(url)
return urls_with_extension
def save_to_file(urls, file_name):
with open(file_name, 'w') as file:
for url in urls:
file.write(f"{url}\n")
if __name__ == "__main__":
file_path = input("Enter the file path: ")
extension = input("Enter the file extension (e.g., .js, .css): ")
file_name = input("Enter the file name to save the URLs: ")
urls_with_extension = check_extension(file_path, extension)
save_to_file(urls_with_extension, file_name)
print(f"{len(urls_with_extension)} URLs with {extension} extension have been saved to {file_name}.")