(?P[^<]+)<\/td>| [^<]+<\/td> | [^<]+(?P\d+)[' \
+ '^&]+&domain=(?P\d+)"'
+ LOGIN_STATUS_REGEX = ''
+
+ def __init__(self):
+ self.headers = {
+ 'Content-Type': 'application/x-www-form-urlencoded',
+ }
+ self.session = requests.session()
+ self.token_pattern = re.compile(self.TOKEN_REGEX)
+ self.domain_info_pattern = re.compile(self.DOMAIN_INFO_REGEX)
+ self.login_pattern = re.compile(self.LOGIN_STATUS_REGEX)
+
+ def run(self) -> list:
+ self.login()
+ html = self.get_domains()
+ token_match = self.token_pattern.findall(html)
+ domain_info_match = self.domain_info_pattern.findall(html)
+ login_match = self.login_pattern.findall(html)
+
+ if not login_match:
+ print("FreeNom login parse failed")
+ raise CustomException("登录检查失败")
+
+ if not token_match:
+ print("FreeNom token parse failed")
+ raise CustomException("页面token检查失败")
+
+ if not domain_info_match:
+ print("FreeNom domain info parse failed")
+ raise CustomException("页面没有获取到域名信息")
+
+ token = token_match[0]
+ print(f"waiting for renew domain info is {domain_info_match}")
+
+ result = []
+
+ for info in domain_info_match:
+ time.sleep(1)
+ domain, days, domain_id = info
+ msg = "失败"
+
+ if int(days) > 14:
+ print(f"FreeNom domain {domain} can not renew, days until expiry is {days}")
+
+ else:
+ response = self.renew_domain(token, domain_id)
+
+ if response.find("Order Confirmation") != -1:
+ msg = "成功"
+ print(f"FreeNom renew domain {domain} is success")
+
+ result.append((domain, days, domain_id, msg))
+ return result
+
+ def login(self) -> bool:
+ data = {
+ 'username': settings.FN_ID,
+ 'password': settings.FN_PW
+ }
+ headers = {
+ **self.headers,
+ 'Referer': 'https://my.freenom.com/clientarea.php'
+ }
+ response = self.session.post(self.LOGIN_URL, data=data, headers=headers)
+
+ if response.status_code == 200:
+ return True
+ else:
+ print("FreeNom login failed")
+ raise CustomException("调用登录接口失败")
+
+ def get_domains(self) -> str:
+ headers = {
+ 'Referer': 'https://my.freenom.com/clientarea.php'
+ }
+ response = self.session.get(self.DOMAIN_STATUS_URL, headers=headers)
+
+ if response.status_code == 200:
+ return response.text
+ else:
+ print("FreeNom check domain status failed")
+ raise CustomException("调用获取域名信息接口失败")
+
+ def renew_domain(self, token, renewalid) -> str:
+ headers = {
+ **self.headers,
+ "Referer": "https://my.freenom.com/domains.php?a=renewdomain&domain=" + "renewalid"
+ }
+ data = {
+ "token": token,
+ "renewalid": renewalid,
+ f"renewalperiod[{renewalid}]": "12M",
+ 'paymentmethod': 'credit'
+ }
+
+ response = self.session.post(self.RENEW_DOMAIN_URL, data=data, headers=headers)
+ if response.status_code == 200:
+ return response.text
+ else:
+ print("FreeNom renew domain failed")
+ raise CustomException("调用续期接口失败接口失败")
+
+ def __del__(self):
+ self.session.close()
diff --git a/Scripts/py/FreeNom/utils/mail.py b/Scripts/py/FreeNom/utils/mail.py
new file mode 100644
index 0000000..a323cb6
--- /dev/null
+++ b/Scripts/py/FreeNom/utils/mail.py
@@ -0,0 +1,52 @@
+import smtplib
+import traceback
+from email.mime.multipart import MIMEMultipart
+from email.mime.text import MIMEText
+from jinja2 import FileSystemLoader, Environment, Template
+
+from . import settings
+
+
+class EmailPoster(object):
+ """
+ 邮件发送基础类
+
+ """
+
+ @staticmethod
+ def get_template():
+ loader = FileSystemLoader('templates')
+ env = Environment(loader=loader)
+ template = env.get_template("default.html")
+ return template
+
+ def send(self, data: dict):
+ payload = data.get("payload", {})
+ if payload:
+ template = self.get_template()
+ content = template.render(payload=payload)
+ else:
+ content = data.get('body', '')
+ subject = data.get('subject', '')
+ mail_to = data.get('to', [])
+ mail_from = data.get('from', settings.MAIL_ADDRESS)
+ self._send(content, subject, mail_from, mail_to)
+
+ @staticmethod
+ def _send(content: str, subject: str, mail_from: str, mail_to: list):
+ msg_root = MIMEMultipart('related')
+ msg_text = MIMEText(content, 'html', 'utf-8')
+ msg_root.attach(msg_text)
+ msg_root['Subject'] = subject
+ msg_root['From'] = mail_from
+ msg_root['To'] = ";".join(mail_to)
+
+ try:
+ smtp = smtplib.SMTP_SSL(settings.MAIL_HOST, settings.MAIL_PORT)
+ # smtp.set_debuglevel(1)
+ smtp.ehlo()
+ smtp.login(settings.MAIL_USER, settings.MAIL_PW)
+ smtp.sendmail(settings.MAIL_ADDRESS, mail_to, msg_root.as_string())
+ smtp.quit()
+ except Exception as e:
+ print(traceback.format_exc(e))
diff --git a/Scripts/py/FreeNom/utils/settings.py b/Scripts/py/FreeNom/utils/settings.py
new file mode 100644
index 0000000..2b12f08
--- /dev/null
+++ b/Scripts/py/FreeNom/utils/settings.py
@@ -0,0 +1,15 @@
+import os
+
+# qq mail
+MAIL_ADDRESS = os.getenv("MAIL_ADDRESS", "")
+MAIL_HOST = os.getenv("SMTP_HOST", "smtp.qq.com")
+MAIL_PW= os.getenv("MAIL_PW", "")
+MAIL_PORT = int(os.getenv("SMTP_PORT", 465))
+MAIL_TO = os.getenv("MAIL_TO", "")
+MAIL_USER = os.getenv("MAIL_USER", "")
+
+
+# free nom
+FN_ID = os.getenv("FN_ID", "")
+FN_PW = os.getenv("FN_PW", "")
+
diff --git a/Scripts/py/mimotion.py b/Scripts/py/mimotion.py
index a092007..698bc11 100644
--- a/Scripts/py/mimotion.py
+++ b/Scripts/py/mimotion.py
@@ -11,7 +11,7 @@ Date: Tue Aug 10 08:24:30 UTC 2021
MI_USER: 账号 仅支持手机号,多账号用 # 分隔
MI_PWD: 密码 多账号用 # 分隔,且与账号一一对应
STEP: 步数 空或不填则为 18000-25000 之间随机,自定义示例: 18763 或 19000-24000
-PMODE: 推送模式 || PKEY: 具体推送格式填写(不带 [ ],请用具体的值代替)
+PMODE: 推送模式 || PKEY: 具体推送格式填写(不带 [TG: ],请用具体的值代替)
wx [Server 酱: skey]
nwx [新 Server 酱: skey]
tg [TG: tg_bot_token@user_id]
| |