-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathjob_wxbot.py
677 lines (584 loc) · 28.5 KB
/
job_wxbot.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
#!/usr/bin/env python
# coding: utf-8
import ConfigParser
import logging
import os
import sys
import config
import redis
import threading
import platform
import utils
from sqlhelper import SqlHelper
from spider.boss import Boss
from spider.lagou import Lagou
from spider.liepin import Liepin
from wxbot import *
class MyWXBot(WXBot):
# '''
# def schedule(self):
# self.send_msg(u'张三', u'测试')
# time.sleep(1)
# '''
# 运行微信网页版
def run_wx(self):
self.DEBUG = True
if 'Linux' in platform.platform():
self.conf['qr'] = 'tty'
else:
self.conf['qr'] = 'png'
self.is_big_contact = False #如果确定通讯录过大,无法获取,可以直接配置,跳过检查。假如不是过大的话,这个方法可能无法获取所有的联系人
self.is_login_success = False
self.run()
# 用户按照关键字查询工作
def user_query_job(self):
while True:
if self.is_login_success == False:
time.sleep(3)
continue
job = red.lpop('job')
if job == None:
time.sleep(1)
continue
utils.log('pop job:%s' % job)
try:
param = json.loads(job)
platform = param.get('platform', '')
platform_name = param.get('platform_name')
if platform == 'boss':
msg = self.get_boss_local_job(param)
elif platform == 'lagou':
msg = self.get_lagou_local_job(param)
elif platform == 'liepin':
msg = self.get_liepin_local_job(param)
else:
msg = ''
if msg != '' and msg != None:
self.send_msg_by_uid('@%s %s \n%s' % (param.get('user_name'), platform_name, msg),
param.get('user_id'))
command = (
"INSERT IGNORE INTO {} (id, user_name, user_id, city, query, page, platform, result, "
"save_time) "
"VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s)".format(config.user_query_table))
data = (
None, param.get('user_name'), param.get('user_id'), param.get('city_name', ''),
param.get('query', ''), 1, platform_name, msg, None)
sql.insert_data(command, data)
time.sleep(2)
except Exception, e:
self.send_msg_by_uid('用户查询信息失败 job:%s msg:%s' % (job, e))
continue
# 抓取招聘网站更新的消息,并发到微信群里面
# def update_job(self):
# while True:
# if self.is_login_success == False:
# time.sleep(5)
# continue
#
# try:
# self.update_boss_job()
# time.sleep(10)
# self.update_lagou_job()
# time.sleep(10)
# self.update_liepin_job()
# time.sleep(10)
# except Exception, e:
# utils.log('update job exception msg:%s' % e)
# self.send_msg_by_uid('')
def crawl_boss_job(self):
while True:
if self.is_login_success == False:
time.sleep(5)
continue
try:
self.update_boss_job()
except Exception, e:
utils.log('update boss job exception msg:%s' % e)
self.send_msg_by_uid('在抓取 Boss 直聘时出现中断异常 msg:%s' % e)
time.sleep(60)
def crawl_lagou_job(self):
while True:
if self.is_login_success == False:
time.sleep(5)
continue
try:
self.update_lagou_job()
except Exception, e:
utils.log('update lagou job exception msg:%s' % e)
self.send_msg_by_uid('在抓取拉勾网时出现中断异常 msg:%s' % e)
time.sleep(60)
def crawl_liepin_job(self):
while True:
if self.is_login_success == False:
time.sleep(5)
continue
try:
self.update_liepin_job()
except Exception, e:
utils.log('update liepin job exception msg:%s' % e)
self.send_msg_by_uid('在抓取猎聘时出现中断异常 msg:%s' % e)
time.sleep(60)
def handle_msg_all(self, msg):
utils.log('msg:%s' % msg)
if msg['msg_type_id'] == 4 and msg['content']['type'] == 0:
# self.send_msg_by_uid(u'hi', msg['user']['id'])
pass
elif (msg['msg_type_id'] == 3 or msg['msg_type_id'] == 1) and msg['content']['type'] == 0:
data = msg['content']['data']
if u'@job' in data:
param = self.get_param(msg)
if param != None:
self.get_all_job(param, msg)
def get_all_job(self, param, msg):
utils.log('param:%s' % param)
param['platform'] = 'boss'
param['platform_name'] = 'boss 直聘'
red.rpush('job', json.dumps(param))
param['platform'] = 'lagou'
param['platform_name'] = '拉勾网'
red.rpush('job', json.dumps(param))
param['platform'] = 'liepin'
param['platform_name'] = '猎聘网'
red.rpush('job', json.dumps(param))
command = (
"INSERT IGNORE INTO {} (id, user_name, user_id, city, query, page, platform, result, "
"save_time) "
"VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s)".format(config.user_query_table))
data = (
None, param.get('user_name'), param.get('user_id'), param.get('city_name', ''),
param.get('query', ''), 1, '', '', None)
sql.insert_data(command, data)
utils.log('redis length:%s' % red.llen('job'))
def get_param(self, msg):
desc = msg['content']['desc']
# 这里解决在 pc 上发送 @ 消息,desc 没有和 data 一样保护 @ 信息的问题
if u'@' in desc:
desc = desc.replace(u'@job ', '')
infos = desc.split(' ')
if len(infos) >= 2:
page = 1
if len(infos) >= 3:
try:
page = int(infos[2])
except:
pass
param = {
'user_name': msg['content']['user']['name'],
'user_id': msg['user']['id'],
'platform': '',
'city_name': infos[0],
'query': infos[1],
'page': page,
'is_use_proxy': False,
}
return param
else:
utils.log('user:%s 格式不正确' % msg['user'])
self.send_msg_by_uid('@%s 查询格式不正确' % (msg['content']['user']['name']), msg['user']['id'])
return None
def get_boss_local_job(self, param):
table_name = '%s_job' % param.get('platform')
command = "SELECT * FROM {0} WHERE job_name LIKE \'%{1}%\' AND city_name LIKE \'%{2}%\' ORDER BY save_time " \
"DESC limit 5".format(table_name, param.get('query'), param.get('city_name'))
msg = ''
result = sql.query(command)
if result != None and len(result) > 0:
for item in result:
info = '{company_name} {company_info} 招聘 {job_name} {salary} {job_info} ' \
'{release_time} 详情:{url}\n\n'. \
format(company_name = item[7], company_info = item[8], job_name = item[3],
salary = item[6], job_info = item[4], release_time = item[5], url = item[10])
msg = msg + info
else:
msg = '没有查询到数据, 查询城市:%s 查询关键词:%s' % (param.get('city_name'), param.get('query'))
return msg
def get_lagou_local_job(self, param):
table_name = '%s_job' % param.get('platform')
command = "SELECT * FROM {0} WHERE job_name LIKE \'%{1}%\' AND city_name LIKE \'%{2}%\' ORDER BY save_time " \
"DESC limit 5".format(table_name, param.get('query'), param.get('city_name'))
msg = ''
result = sql.query(command)
if result != None and len(result) > 0:
for item in result:
info = '{company_name} {finance_stage} 招聘 {job_name} {salary} {education}{work_year} {release_time} ' \
'详情:{url}\n\n'. \
format(company_name = item[9], finance_stage = item[11], job_name = item[3],
salary = item[8], education = item[5], work_year = item[4],
release_time = item[7], url = item[16])
msg = msg + info
else:
msg = '没有查询到数据, 查询城市:%s 查询关键词:%s' % (param.get('city_name'), param.get('query'))
return msg
def get_liepin_local_job(self, param):
table_name = '%s_job' % param.get('platform')
command = "SELECT * FROM {0} WHERE job_name LIKE \'%{1}%\' AND city_name LIKE \'%{2}%\' ORDER BY save_time " \
"DESC limit 5".format(table_name, param.get('query'), param.get('city_name'))
msg = ''
result = sql.query(command)
if result != None and len(result) > 0:
for item in result:
info = '{company_name} {company_info} 招聘 {job_name} {job_condition} {release_time} ' \
'详情:{url}\n\n'. \
format(company_name = item[5], company_info = item[6], job_name = item[3], job_condition = item[4],
release_time = item[8], url = item[9])
msg = msg + info
else:
msg = '没有查询到数据, 查询城市:%s 查询关键词:%s' % (param.get('city_name'), param.get('query'))
return msg
def get_boss_job(self, param):
msg = ''
command = "SELECT * FROM {0} WHERE name LIKE \'{1}\'".format(
config.boss_city_id_table, param.get('city_name'))
res = sql.query_one(command)
if res == None:
msg = '没有找到对应城市 id, 城市名称:%s' % (param.get('city_name'))
else:
id = res[0]
param['city_id'] = id
boss = Boss()
job_list = boss.start_request(param)
if job_list == None:
msg = '没有查询到相关工作,查询城市:%s 查询关键词:%s' % (param.get('city_name'), param.get('query'))
elif len(job_list) == 0:
msg = '没有查询到相关工作,查询城市:%s 查询关键词:%s' % (param.get('city_name'), param.get('query'))
else:
for job in job_list:
job_name = job.get('job_name')
job_info = job.get('job_info')
salary = job.get('salary')
company_name = job.get('company_name')
company_info = job.get('company_info')
url = job.get('url')
release_time = job.get('release_time')
info = '{company_name} {company_info} 招聘 {job_name} {salary} {job_info} ' \
'{release_time} 详情:{url}\n\n'. \
format(company_name = company_name, company_info = company_info, job_name = job_name,
salary = salary, job_info = job_info, release_time = release_time, url = url)
msg = msg + info
return msg
def get_lagou_job(self, param):
msg = ''
lagou = Lagou()
job_list = lagou.start_request(param)
if job_list == None:
msg = '没有查询到相关工作,查询城市:%s 查询关键词:%s' % (param.get('city_name'), param.get('query'))
elif len(job_list) == 0:
msg = '没有查询到相关工作,查询城市:%s 查询关键词:%s' % (param.get('city_name'), param.get('query'))
else:
for job in job_list:
job_name = job.get('job_name')
company_name = job.get('company_name')
finance_stage = job.get('finance_stage')
education = job.get('education')
work_year = job.get('work_year')
salary = job.get('salary')
url = job.get('url')
release_time = job.get('release_time')
info = '{company_name} {finance_stage} 招聘 {job_name} {salary} {education}{work_year} {release_time} ' \
'详情:{url}\n\n'. \
format(company_name = company_name, finance_stage = finance_stage, job_name = job_name,
salary = salary, education = education, work_year = work_year,
release_time = release_time, url = url)
msg = msg + info
return msg
def get_liepin_job(self, param):
msg = ''
command = "SELECT * FROM {0} WHERE name LIKE \'{1}\'".format(
config.liepin_city_id_table, param.get('city_name'))
res = sql.query_one(command)
if res == None:
msg = '没有找到对应城市 id, 城市名称:%s' % (param.get('user_name'), param.get('city_name'))
else:
id = res[0]
param['city_id'] = id
liepin = Liepin()
job_list = liepin.start_request(param)
if job_list == None:
msg = '没有查询到相关工作,查询城市:%s 查询关键词:%s' % (param.get('city_name'), param.get('query'))
elif len(job_list) == 0:
msg = '没有查询到相关工作,查询城市:%s 查询关键词:%s' % (param.get('city_name'), param.get('query'))
else:
for job in job_list:
job_name = job.get('job_name')
job_condition = job.get('job_condition')
company_name = job.get('company_name')
company_info = job.get('company_info')
url = job.get('url')
info = '{company_name} {company_info} 招聘 {job_name} {job_condition} {release_time} ' \
'详情:{url}\n\n'.format(company_name = company_name, company_info = company_info,
job_name = job_name, job_condition = job_condition,
release_time = job.get('release_time'),
url = url)
msg = msg + info
return msg
def update_boss_job(self):
cf = ConfigParser.ConfigParser()
cf.read('job_conf.ini')
citys = cf.get('boss', 'citys')
querys = cf.get('boss', 'querys')
for city in citys.split(','):
command = "SELECT * FROM {0} WHERE name LIKE \'{1}\'".format(config.boss_city_id_table, city)
res = sql.query_one(command)
if res == None:
continue
city_id = res[0]
for query in querys.split(','):
param = {
'city_id': city_id,
'city_name': city,
'query': query,
'page': 1,
}
boss = Boss()
job_list = boss.start_request(param)
if job_list == None:
self.send_msg_by_uid('Boss 直聘,抓取数据异常 city:%s query:%s' % (city, query))
elif len(job_list) == 0:
self.send_msg_by_uid('Boss 直聘,解析数据异常 city:%s query:%s' % (city, query))
else:
for job in job_list:
id = job.get('id')
command = "SELECT id FROM {0} WHERE id = \'{1}'".format(config.boss_job_table, id)
res = sql.query_one(command)
# 这是一个新发布的招聘数据
if res == None:
query = job.get('query', '')
job_name = job.get('job_name', '')
job_info = job.get('job_info', '')
salary = job.get('salary', '')
company_name = job.get('company_name', '')
company_info = job.get('company_info', '')
release_time = job.get('release_time', '')
url = job.get('url')
job_label = job.get('job_label', '')
info = 'Boss 直聘 {city_name} {query}\n{company_name} {company_info} 招聘 {job_name}' \
'{salary} {job_info} {release_time} 详情:{url}\n\n'. \
format(city_name = city, query = query,
company_name = company_name, company_info = company_info, job_name = job_name,
salary = salary, job_info = job_info, release_time = release_time, url = url)
self.send_msg('西瓜群', info)
command = (
"INSERT IGNORE INTO {} (id, city_name, query, job_name, job_info, "
"release_time, salary, company_name, company_info, job_label, url, job_jd, save_time) "
"VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)".
format(config.boss_job_table))
msg = (
id, city, query, job_name, job_info, release_time, salary, company_name,
company_info, job_label, url, '', None)
sql.insert_data(command, msg)
time.sleep(40)
def update_lagou_job(self):
cf = ConfigParser.ConfigParser()
cf.read('job_conf.ini')
citys = cf.get('lagou', 'citys')
querys = cf.get('lagou', 'querys')
for city in citys.split(','):
for query in querys.split(','):
param = {
'city_name': city,
'query': query,
'page': 1,
}
lagou = Lagou()
job_list = lagou.start_request(param)
if job_list == None:
self.send_msg_by_uid('Lagou 抓取数据失败 city:%s query:%s' % (city, query))
elif len(job_list) == 0:
self.send_msg_by_uid('Lagou 没有解析到数据 city:%s query:%s' % (city, query))
else:
for job in job_list:
id = job.get('id')
command = "SELECT id FROM {0} WHERE id = \'{1}'".format(config.lagou_job_table, id)
res = sql.query_one(command)
# 这是一个新发布的招聘数据
if res == None:
city_name = job.get('city_name', '')
query = job.get('query', '')
job_name = job.get('job_name', '')
work_year = job.get('work_year', '')
education = job.get('education', '')
job_nature = job.get('job_nature', '')
create_time = job.get('create_time', '')
salary = job.get('salary', '')
company_name = job.get('company_name', '')
industry_field = job.get('industry_field', '')
finance_stage = job.get('finance_stage', '')
company_label = job.get('company_label', '')
company_size = job.get('company_size', '')
job_label = job.get('job_label', '')
url = job.get('url')
info = '拉勾网 {city_name} {query}\n{company_name} {finance_stage} 招聘 {job_name} {salary} ' \
'{education}{work_year} {release_time} 详情:{url}\n\n'. \
format(city_name = city, query = query, company_name = company_name,
finance_stage = finance_stage, job_name = job_name,
salary = salary, education = education, work_year = work_year,
release_time = create_time, url = url)
self.send_msg('西瓜群', info)
command = (
"INSERT IGNORE INTO {} (id, city_name, query, job_name, work_year, education, "
"job_nature, create_time, salary, company_name, industry_field, finance_stage, "
"company_label, company_size, job_label, url, job_jd, save_time) "
"VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)".
format(config.lagou_job_table))
msg = (
id, city_name, query, job_name, work_year, education, job_nature, create_time, salary,
company_name, industry_field, finance_stage, company_label, company_size, job_label,
url, '', None)
sql.insert_data(command, msg)
time.sleep(40)
def update_liepin_job(self):
cf = ConfigParser.ConfigParser()
cf.read('job_conf.ini')
citys = cf.get('liepin', 'citys')
querys = cf.get('liepin', 'querys')
for city in citys.split(','):
command = "SELECT * FROM {0} WHERE name LIKE \'{1}\'".format(config.liepin_city_id_table, city)
res = sql.query_one(command)
if res == None:
continue
city_id = res[0]
for query in querys.split(','):
param = {
'city_id': city_id,
'city_name': city,
'query': query,
'page': 1,
}
liepin = Liepin()
job_list = liepin.start_request(param)
if job_list == None:
self.send_msg_by_uid('liepin 抓取数据失败 city:%s query:%s' % (city, query))
elif len(job_list) == 0:
self.send_msg_by_uid('liepin 没有解析到数据 city:%s query:%s' % (city, query))
else:
for job in job_list:
id = job.get('id')
command = "SELECT id FROM {0} WHERE id = \'{1}'".format(config.liepin_job_table, id)
res = sql.query_one(command)
# 这是一个新发布的招聘数据
if res == None:
job_name = job.get('job_name')
job_condition = job.get('job_condition')
company_name = job.get('company_name')
company_info = job.get('company_info')
url = job.get('url')
info = '猎聘网 {city_name} {query}\n{company_name} {company_info} 招聘 {job_name} ' \
'{job_condition} {release_time} 详情:{url}\n\n'.format(
city_name = job.get('city_name'), query = job.get('query'),
company_name = company_name, company_info = company_info, job_name = job_name,
job_condition = job_condition, release_time = job.get('release_time'),
url = url)
self.send_msg('西瓜群', info)
command = (
"INSERT IGNORE INTO {} (id, city_name, query, job_name, job_condition, "
"company_name, "
"company_info, full_msg, release_time, url, save_time) "
"VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)".format(
config.liepin_job_table))
msg = (
id, job.get('city_name'), job.get('query'), job_name, job_condition, company_name,
company_info, info, job.get('release_time'), url, None)
sql.insert_data(command, msg)
time.sleep(40)
def init():
# 创建用户查询记录表
command = (
"CREATE TABLE IF NOT EXISTS {} ("
"`id` INT(12) NOT NULL AUTO_INCREMENT UNIQUE,"
"`user_name` CHAR(20) NOT NULL,"
"`user_id` CHAR(200) DEFAULT NULL,"
"`city` CHAR(10) DEFAULT NULL,"
"`query` CHAR(20) DEFAULT NULL,"
"`page` INT(3) DEFAULT NULL,"
"`platform` CHAR(30) DEFAULT NULL,"
"`result` TEXT DEFAULT NULL,"
"`save_time` TIMESTAMP NOT NULL,"
"PRIMARY KEY(id)"
") ENGINE=InnoDB".format(config.user_query_table))
sql.create_table(command)
# 创建 boss 直聘平台工作信息表
command = (
"CREATE TABLE IF NOT EXISTS {} ("
"`id` INT(10) NOT NULL UNIQUE,"
"`city_name` CHAR(20) DEFAULT NULL,"
"`query` CHAR(20) DEFAULT NULL,"
"`job_name` CHAR(20) DEFAULT NULL,"
"`job_info` CHAR(50) DEFAULT NULL,"
"`release_time` CHAR(30) DEFAULT NULL,"
"`salary` CHAR(20) DEFAULT NULL,"
"`company_name` CHAR(100) DEFAULT NULL,"
"`company_info` CHAR(200) DEFAULT NULL,"
"`job_label` CHAR(100) DEFAULT NULL,"
"`url` CHAR(100) DEFAULT NULL,"
"`job_jd` TEXT DEFAULT NULL,"
"`save_time` TIMESTAMP NOT NULL,"
"PRIMARY KEY(id)"
") ENGINE=InnoDB".format(config.boss_job_table))
sql.create_table(command)
# 创建拉钩网平台工作信息表
command = (
"CREATE TABLE IF NOT EXISTS {} ("
"`id` INT(10) NOT NULL UNIQUE,"
"`city_name` CHAR(20) DEFAULT NULL,"
"`query` CHAR(20) DEFAULT NULL,"
"`job_name` CHAR(20) DEFAULT NULL,"
"`work_year` CHAR(20) DEFAULT NULL,"
"`education` CHAR(20) DEFAULT NULL,"
"`job_nature` CHAR(20) DEFAULT NULL,"
"`create_time` CHAR(30) DEFAULT NULL,"
"`salary` CHAR(20) DEFAULT NULL,"
"`company_name` CHAR(100) DEFAULT NULL,"
"`industry_field` CHAR(100) DEFAULT NULL,"
"`finance_stage` CHAR(100) DEFAULT NULL,"
"`company_label` CHAR(100) DEFAULT NULL,"
"`company_size` CHAR(100) DEFAULT NULL,"
"`job_label` CHAR(100) DEFAULT NULL,"
"`url` CHAR(100) DEFAULT NULL,"
"`job_jd` TEXT DEFAULT NULL,"
"`save_time` TIMESTAMP NOT NULL,"
"PRIMARY KEY(id)"
") ENGINE=InnoDB".format(config.lagou_job_table))
sql.create_table(command)
# 创建猎聘网平台工作信息表
command = (
"CREATE TABLE IF NOT EXISTS {} ("
"`id` INT(10) NOT NULL UNIQUE,"
"`city_name` CHAR(20) NOT NULL,"
"`query` CHAR(20) NOT NULL,"
"`job_name` CHAR(200) NOT NULL,"
"`job_condition` CHAR(200) NOT NULL,"
"`company_name` CHAR(100) NOT NULL,"
"`company_info` CHAR(200) NOT NULL,"
"`full_msg` TEXT NOT NULL,"
"`release_time` CHAR(30) NOT NULL,"
"`url` CHAR(100) NOT NULL,"
"`save_time` TIMESTAMP NOT NULL,"
"PRIMARY KEY(id)"
") ENGINE=InnoDB".format(config.liepin_job_table))
sql.create_table(command)
if __name__ == '__main__':
if not os.path.exists('log'):
os.makedirs('log')
if not os.path.exists('temp'):
os.makedirs('temp')
reload(sys)
sys.setdefaultencoding('utf-8')
logging.basicConfig(
filename = 'log/job.log',
format = '%(levelname)s %(asctime)s: %(message)s',
level = logging.DEBUG
)
sql = SqlHelper()
red = redis.StrictRedis(host = 'localhost', port = 6379, db = 10)
init()
wx = MyWXBot()
t1 = threading.Thread(target = wx.run_wx)
t2 = threading.Thread(target = wx.user_query_job)
t3 = threading.Thread(target = wx.crawl_boss_job)
t4 = threading.Thread(target = wx.crawl_lagou_job)
t5 = threading.Thread(target = wx.crawl_liepin_job)
t1.start()
t2.start()
t3.start()
t4.start()
t5.start()