-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch.py
More file actions
44 lines (37 loc) · 1.52 KB
/
launch.py
File metadata and controls
44 lines (37 loc) · 1.52 KB
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
from configparser import ConfigParser
from argparse import ArgumentParser
from utils.server_registration import get_cache_server
from utils.config import Config
from crawler import Crawler
import os
import shutil
def clear_folder(folder_name):
# Check if the folder exists
if os.path.exists(folder_name):
# Remove all files inside the folder
for filename in os.listdir(folder_name):
file_path = os.path.join(folder_name, filename)
try:
if os.path.isfile(file_path) or os.path.islink(file_path):
os.unlink(file_path) # Remove the file or link
elif os.path.isdir(file_path):
shutil.rmtree(file_path) # Remove a directory and its contents
except Exception as e:
print(f'Failed to delete {file_path}. Reason: {e}')
else:
# If the folder doesn't exist, create it
os.makedirs(folder_name)
def main(config_file, restart):
clear_folder('tokens_by_subdomain')
cparser = ConfigParser()
cparser.read(config_file)
config = Config(cparser)
config.cache_server = get_cache_server(config, restart)
crawler = Crawler(config, restart)
crawler.start()
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("--restart", action="store_true", default=False)
parser.add_argument("--config_file", type=str, default="config.ini")
args = parser.parse_args()
main(args.config_file, args.restart)