-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
41 lines (29 loc) · 1.37 KB
/
build.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
import random
import string
import argparse
def replace_wasm_with_random_string(file_path):
# Generate a random string of length 16
def generate_random_string(length=16):
characters = string.ascii_letters + string.digits # A-Z, a-z, 0-9
return ''.join(random.choice(characters) for _ in range(length))
print(file_path)
# Read the file
with open(file_path, 'r') as file:
content = file.read()
# Replace occurrences of ".wasm" with ".wasm?id=RANDOM_STRING"
updated_content = content.replace('.wasm', f'.wasm?id={generate_random_string()}')
updated_content = updated_content.replace('.js', f'.js?id={generate_random_string()}')
updated_content = updated_content.replace('.css', f'.css?id={generate_random_string()}')
print(updated_content)
# Write the updated content back to the file
with open(file_path, 'w') as file:
file.write(updated_content)
#print(f"Updated file {file_path} successfully.")
if __name__ == "__main__":
# Set up argument parser
parser = argparse.ArgumentParser(description="Replace .wasm with .wasm?id=RANDOM_STRING")
parser.add_argument("file_path", help="Path to the file you want to modify")
# Parse command-line arguments
args = parser.parse_args()
# Call the function with the file path argument
replace_wasm_with_random_string(args.file_path)