-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.py
More file actions
83 lines (68 loc) · 2.81 KB
/
main.py
File metadata and controls
83 lines (68 loc) · 2.81 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import smtplib
import sys
import time
import urllib2
from email.mime.text import MIMEText
class Mail:
@staticmethod
def send(title, content):
mail_user = "m18024160675@163.com" # 邮箱账号
mail_pwd = "baidu233" # 邮箱密码(SMTP)
mail_to = "" # 目标的通知邮箱,可以跟自身相同
msg = MIMEText(content, 'plain', 'utf-8')
msg["Subject"] = title
msg["From"] = mail_user
msg["To"] = mail_to
s = smtplib.SMTP("smtp.163.com", timeout=30)
s.login(mail_user, mail_pwd)
s.sendmail(mail_user, mail_to, msg.as_string())
s.close()
class BaiduTalent:
def __init__(self):
# Console里的 document.cookie() 整一条
self.cookie = ""
self.res_url = "http://talent.baidu.com/baidu/web/httpservice/getApplyRecordList?recruitType=1&_="
self.opener = urllib2.build_opener()
def check(self):
now_time = (str(int(time.time() * 1000)))
print time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
new_cookie = self.cookie
# new_cookie = self.cookie.replace(self.cookie.split('Hm_lpvt_50e85ccdd6c1e538eb1290bc92327926=')[1], now_time) # 确保一直最新
self.opener.addheaders = [
('Accept', 'application/json, text/javascript, */*; q=0.01'),
('X-Requested-With', 'XMLHttpRequest'),
("Accept-Encoding", "gzip, deflate, sdch"),
("Accept-Language", "zh-CN,zh;q=0.8,en;q=0.6"),
('Referer', 'http://talent.baidu.com/external/baidu/index.html'),
("User-Agent",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36"),
("Cookie", new_cookie)
]
url = self.res_url + now_time
result = self.opener.open(url)
# print result.read()
try:
json_str = json.loads(result.read())
result = json_str['applyRecordList'][0]['applyStatus']
result = result.encode('utf-8')
# 常见的状态:面试安排中、面试通过、已变更职位
if "面试通过" in result:
Mail.send(result, result)
sys.exit(0)
else:
# 首次测试成功后可以注释掉这行就不会邮件骚扰了,只在状态变为通过时通知
Mail.send("百度面试结果查询", result)
except ValueError:
Mail.send("百度面试结果查询-Cookie过期", 'Cookie过期')
sys.exit(0)
def run(self):
while True:
self.check()
# 一小时查询一次,一般改为6小时也行
time.sleep(60 * 60)
if __name__ == "__main__":
baidu = BaiduTalent()
baidu.run()