-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path自动检查文章投稿状态并发送邮件.py
executable file
·115 lines (87 loc) · 3.48 KB
/
自动检查文章投稿状态并发送邮件.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
import re
import os
import smtplib
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
class Journal(object):
def __init__(self, account, password, journal_name):
self.account = account
self.password = password
self.journal_name = journal_name
def write_log(self, info):
with open(self.journal_name, "a") as f:
f.write("%s\n" % info)
@property
def read_last_log(self):
if os.path.exists(self.journal_name):
with open(self.journal_name, 'r') as f:
lines = f.readlines()
last_line = lines[-1]
return last_line
else:
return "newfile"
def send_info(self, info):
if self.read_last_log == "%s\n" % info:
pass
else:
days = info.split(',')[0]
status = info.split(',')[1].lstrip().rstrip()
context = "This is the %s days since I have submited my manuscript. The status is %s." % (days, status)
msg = MIMEMultipart()
msg.attach(MIMEText(context))
msg['from'] = 'your mail here'
msg['subject'] = 'My manuscript status'
msgto = 'your target mail address here'
try:
server = smtplib.SMTP()
server.connect('smtp.163.com')
server.login('your mail here','your password here')
server.sendmail(msg['from'], msgto, msg.as_string())
server.quit()
except Exception as e:
print(e)
class JGR(Journal):
def __init__(self, account, password):
# if this script is run on a server, then phantomjs is suggested than chrome
self.driver = webdriver.Chrome()
self.journal_name = "JGR"
super(JGR, self).__init__(account=account, password=password, journal_name="JGR")
@property
def home_url(self):
return "https://jgr-atmospheres-submit.agu.org/cgi-bin/main.plex"
def login(self):
try:
self.driver.get(self.home_url)
if "Journal of Geophysical Research" not in self.driver.title:
raise Exception('The URL of JGR is not correct!')
# fill the account
elem = self.driver.find_element_by_name("login")
elem.clear()
elem.send_keys(self.account)
# fill the password
elem = self.driver.find_element_by_name("password")
elem.clear()
elem.send_keys(self.password)
elem.send_keys(Keys.RETURN)
except Exception as e:
print("JGR login failed: \n")
print(e)
def check(self):
elem = self.driver.find_element_by_partial_link_text('Live Manuscripts')
elem.click()
# find how many days past since my submission
elem = self.driver.find_element_by_partial_link_text('Check Status')
days = re.findall(re.compile(r'Check Status # .* [0-9]* days',re.M), self.driver.page_source)[0].split()[4]
elem.click()
status = re.findall(re.compile(r'Current Stage.*',re.M), self.driver.page_source)[0][26:-10]
self.driver.close()
info = "%s, %s" % (days, status)
self.write_log(info)
self.send_info(info)
if __name__ == "__main__":
MS = JGR("your_mail_here", "your_password_here")
MS.login()
MS.check()