This commit is contained in:
Leon 2021-08-12 22:08:53 +08:00
parent 8755403aa2
commit 8579d5f02d

View File

@ -53,12 +53,13 @@ class FreeNom:
return r.status_code == 200 return r.status_code == 200
def renew(self): def renew(self):
global result global msg
msg = ''
# login # login
ok = self._login() ok = self._login()
if not ok: if not ok:
result = 'login failed' msg = 'login failed'
print(result) print(msg)
return return
# check domain status # check domain status
@ -67,15 +68,15 @@ class FreeNom:
# login status check # login status check
if not re.search(login_status_ptn, r.text): if not re.search(login_status_ptn, r.text):
result = 'get login status failed' msg = 'get login status failed'
print(result) print(msg)
return return
# page token # page token
match = re.search(token_ptn, r.text) match = re.search(token_ptn, r.text)
if not match: if not match:
result = 'get page token failed' msg = 'get page token failed'
print(result) print(msg)
return return
token = match.group(1) token = match.group(1)
@ -98,18 +99,21 @@ class FreeNom:
}) })
result = f'{domain} 续期成功' if r.text.find('Order Confirmation') != -1 else f'{domain} 续期失败' result = f'{domain} 续期成功' if r.text.find('Order Confirmation') != -1 else f'{domain} 续期失败'
print(result) print(result)
msg += result + '\n'
result = f'{domain} 还有 {days} 天续期' result = f'{domain} 还有 {days} 天续期'
print(result) print(result)
msg += result + '\n'
cur_path = os.path.abspath(os.path.dirname(__file__)) cur_path = os.path.abspath(os.path.dirname(__file__))
service = 1
if os.path.exists(cur_path + "/notify.py"): if os.path.exists(cur_path + "/notify.py"):
try: try:
from notify import send from notify import send
except: except:
print("加载通知服务失败~") print("加载通知服务失败~")
else: else:
result = '' service = 0
instance = FreeNom(username, password) instance = FreeNom(username, password)
instance.renew() instance.renew()
if result != '': if service == 1:
send('Freenom 续期', result) send('Freenom 续期', msg)