-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
59 lines (44 loc) · 1.63 KB
/
main.py
File metadata and controls
59 lines (44 loc) · 1.63 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
# @Author: LogicJake
# @Date: 2019-01-16 11:25:12
# @Last Modified time: 2019-01-22 19:21:05
from config import logger
from lib.database import db_object
import argparse
from get_proxy import GetProxy
from validate import ValidateOrigin
from test import TestAvailable
import threading
def init(db_type):
db_obj = db_object.new_db(db_type)
db_obj.connect()
db_obj.create_required_tables()
num = db_obj.select('available', ['COUNT(*)'])
num = num[0][0]
logger.info('There are {} available proxies'.format(num))
logger.info('The proxy pool is initialized successfully')
db_obj.close()
def start(args):
db_type = args.database
init(db_type)
get_proxy = GetProxy(db_type)
validate_origin = ValidateOrigin(db_type)
test_available = TestAvailable(db_type)
thread_get_proxy = threading.Thread(
target=get_proxy.cycle_get, name="thread-get-ip") # 定时从网站获取ip
thread_validate_proxy = threading.Thread(
target=validate_origin.cycle_validate, name="thread-validate-ip") # 定时测试能用代理
thread_test_proxy = threading.Thread(
target=test_available.cycle_test, name="Thread-test-ip") # 定时检查,剔除不能用的代理
thread_get_proxy.start()
thread_validate_proxy.start()
thread_test_proxy.start()
def parse_args():
# Parses arguments
parser = argparse.ArgumentParser(
description="collect proxy from internet.")
parser.add_argument('--database', nargs='?', default='mysql', type=str)
return parser.parse_args()
if __name__ == '__main__':
args = parse_args()
start(args)