forked from QianyanTech/Image-Downloader
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
69 lines (42 loc) · 1.61 KB
/
utils.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -*- coding: utf-8 -*-
# author: Yabin Zheng
# Email: [email protected]
def gen_valid_dir_name_for_keywords(keywords):
keep = ["-", "_", "."]
keywords = keywords.replace(" ", "_").replace(":", "-")
return "".join(c for c in keywords if c.isalnum() or c in keep).rstrip()
class AppConfig(object):
def __init__(self):
self.engine = "Google"
self.driver = "chrome_headless"
self.keywords = ""
self.max_number = 0
self.face_only = False
self.safe_mode = False
self.proxy_type = None
self.proxy = None
self.num_threads = 50
self.output_dir = "./output"
def to_command_paras(self):
str_paras = ""
str_paras += ' -e ' + self.engine
str_paras += ' -d ' + self.driver
str_paras += ' -n ' + str(self.max_number)
str_paras += ' -j ' + str(self.num_threads)
str_paras += ' -o "' + self.output_dir + '/' + \
gen_valid_dir_name_for_keywords(self.keywords) + '"'
if self.face_only:
str_paras += ' -F '
if self.safe_mode:
str_paras += ' -S '
if self.proxy_type is "http":
str_paras += ' -ph "' + self.proxy + '"'
elif self.proxy_type is "socks5":
str_paras += ' -ps "' + self.proxy + '"'
str_paras += ' "' + self.keywords + '"'
return str_paras
def gen_keywords_list_from_str(keywords_str, sep=","):
return keywords_str.split(sep)
def gen_keywords_list_from_file(filepath):
with open(filepath, "r", encoding="utf-8") as f:
return f.readlines()