-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
141 lines (115 loc) · 3.33 KB
/
config.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File : config.py
# @Author: Wanglei
# @Date : 2018/4/29
# @Desc :
import os
from configparser import ConfigParser
MINNUM_PROXY = 100 # 当有效的代理数目小于该值 需要启动爬虫进行爬取
PAGE_PROXY = 10
FLUSH_TIME = 600 # 刷新代理的周期
'''
数据库的配置
'''
HOST = "101.200.38.103"
PORT = 6379
NAME = "gatherproxy"
PASSWORD = "fromtrain!QAZ"
DB_CONFIG = {
'MYSQL_DB_URL': 'mysql+mysqldb://root:root@localhost/proxy?charset=utf8',
'REDIS_DB_URL': 'redis://:[email protected]:6379/9',
}
mysql_host="101.200.38.103"
mysql_port=3306
mysql_db="dev_ticket"
mysql_user="dev"
mysql_password="dev@WSX"
mysql_charset="utf8mb4"
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
CRAWL_DATE = "2018-07-07"
TABLE_NAME = {
"url": "crawler_url_" + CRAWL_DATE.replace("-", ""),
"train": "crawler_train_info_" + CRAWL_DATE.replace("-", ""),
"station": "crawler_stop_station_" + CRAWL_DATE.replace("-", "")
}
MAX_DOWNLOAD_CONCURRENT = 10
PROXY_MINNUM = 500
UPDATE_TIME = 30 * 60
CHECK_TARGET = 'https://kyfw.12306.cn/otn/leftTicket/init'
LOGCONFIG = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'default': {
'format': '%(asctime)s %(name)s %(filename)s [line:%(lineno)d] %(levelname)s %(message)s',
'datefmt': '%Y-%m-%d %H:%M:%S'
}
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'level': 'DEBUG',
'formatter': 'default',
'stream': 'ext://sys.stderr'
},
'info_file_handler': {
'class': 'logging.handlers.TimedRotatingFileHandler',
'level': 'INFO',
'formatter': 'default',
'filename': 'log/info.log',
'when': 'D',
'interval': 1,
'backupCount': 10,
'encoding': 'utf8'
},
'debug_file_handler': {
'class': 'logging.handlers.TimedRotatingFileHandler',
'level': 'DEBUG',
'formatter': 'default',
'filename': 'log/debug.log',
'when': 'D',
'interval': 1,
'backupCount': 10,
'encoding': 'utf8'
},
'error_file_handler': {
'class': 'logging.handlers.TimedRotatingFileHandler',
'level': 'ERROR',
'formatter': 'default',
'filename': 'log/error.log',
'when': 'D',
'interval': 1,
'backupCount': 10,
'encoding': 'utf8'
}
},
'loggers': {
'proxy': {
'handlers': ['console'],
'level': 'DEBUG'
},
'crawl': {
'handlers': ['debug_file_handler', 'error_file_handler'],
'level': 'DEBUG'
}
},
'root': {
'level': 'INFO',
'handlers': ['console', 'info_file_handler']
}
}
"""
12306
"""
class Config:
def __init__(self):
self.pwd = os.path.split(os.path.realpath(__file__))[0]
self.config_path = os.path.join(self.pwd, 'dev.cfg')
self.config_file = ConfigParser()
self.config_file.read(self.config_path)
def proxy_getter_funs(self):
return self.config_file.options('ProxyGetter')
if __name__ == "__main__":
config = Config()
print(config.pwd)