-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstart.py
executable file
·51 lines (40 loc) · 1.35 KB
/
start.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
44
45
46
47
48
49
50
51
#!/bin/python
import json
import os
import platform
import subprocess
def parse_rules(filename):
with open(filename) as file:
rules = json.load(file)
host_rules = rules.get("host-rules", [])
host_resolver_rules = rules.get("host-resolver-rules", [])
return {
"host-rules": ", ".join(host_rules),
"host-resolver-rules": ", ".join(host_resolver_rules)
}
def get_chrome_path():
chrome_env = os.getenv('CHROME')
if chrome_env:
return chrome_env
# Modify your chrome install path here
os_platform = platform.system()
if os_platform == "Windows":
return r'"C:\Program Files\Google\Chrome\Application\chrome.exe"'
elif os_platform == "Linux":
return "google-chrome"
else:
return "Please enter your chrome path here"
def generate_command_line(rules):
command_line = get_chrome_path()
if "host-rules" in rules:
command_line += f' --host-rules="{rules["host-rules"]}"'
if "host-resolver-rules" in rules:
command_line += f' --host-resolver-rules="{rules["host-resolver-rules"]}"'
# Ignore certificate errors
command_line += " --ignore-certificate-errors"
return command_line
rules = parse_rules("rules.json")
command_line = generate_command_line(rules)
# Run the command
print(command_line)
subprocess.run(command_line, shell=True)