-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from coeusite/patch-4
- 主脚本兼容 Android QPython3 + QPy3.6 - 增加了 QPython3 启动脚本 - 增加了 QPython3 短信监视脚本 - 增加了 config 文件的容错功能,useIMessage 和 useQPython3 默认为 false - 在非 Android 平台运行时,增加 useQPython3 = true 的容错功能 - imessage.py 仅在 useIMessage = true 时载入 - update .gitignore to exclude all yaml except config.yaml - cookies 文件将强制储存在项目目录下 已测试: - PC 仍可正常运行 - Android 端放号后成功挂号 未测试: - macOS 情况未知 - Android 端放号前监测挂号
- Loading branch information
Showing
6 changed files
with
169 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
*.json | ||
!_config.json | ||
|
||
*.cookies | ||
*.pyc | ||
.idea/ | ||
.config.yaml | ||
*.yaml | ||
|
||
!config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import re | ||
import datetime | ||
import logging | ||
import time | ||
|
||
from androidhelper import Android | ||
|
||
# 主 Class | ||
class QPython3(object): | ||
# 初始化 | ||
def __init__(self): | ||
self.regex = re.compile('证码为.*【(\d+)】') # regex | ||
self.start_time = datetime.datetime.now() | ||
# Android QPython3 | ||
self.droid = Android() | ||
logging.debug("QPython3 实例初始化完成") | ||
# 读取验证码短信 | ||
def _get_sms_verify_code(self): | ||
# init | ||
self.start_time = datetime.datetime.now() | ||
code = '000000' | ||
retry = 600 | ||
# loop | ||
logging.debug("监控短信中……") | ||
while retry > 0: | ||
retry -= 1 | ||
# 检查 SMS | ||
code = self._check_sms_verify_code() | ||
# 有效验证码? | ||
if code != '000000': | ||
logging.debug("取得有效验证码……"+code) | ||
break | ||
else: | ||
logging.debug("未找到有效验证码……重试中, retry = {}".format(retry)) | ||
time.sleep(0.05) | ||
else: | ||
logging.debug("未找到有效验证码……"+code) | ||
return code | ||
# 读取验证码短信 | ||
def _check_sms_verify_code(self): | ||
# init | ||
code = '000000' | ||
# 获取当前的全部未读短信 | ||
smsMessageIds = self.droid.smsGetMessageIds(True) | ||
# 无短信退出 | ||
if len(smsMessageIds.result) == 0: | ||
logging.debug("无短信退出……") | ||
return code | ||
# loop | ||
for smsId in smsMessageIds.result: | ||
# get message | ||
smsMessage = self.droid.smsGetMessageById(smsId) | ||
# 时间筛选 | ||
smsTimestamp = datetime.datetime.fromtimestamp(int(smsMessage.result['date'])/1e3) | ||
# 跳过开始时间点前 SMS | ||
if smsTimestamp < self.start_time: | ||
# print("时间跳过:", smsMessage) | ||
continue | ||
# 文字匹配 | ||
smsContent = smsMessage.result['body'] | ||
res = self.regex.search(smsContent) | ||
if res is None: | ||
# print("匹配跳过:", smsMessage) | ||
continue | ||
else: | ||
# print("发现短信:", smsMessage) | ||
code = res.group(1).strip() | ||
break | ||
return code | ||
# 获取验证码的外部调用 | ||
def get_verify_code(self): | ||
logging.debug("获取验证码中……") | ||
# 读取验证码短信 | ||
return self._get_sms_verify_code() | ||
|
||
|
||
|
||
## 测试使用 | ||
def main(): | ||
logging.basicConfig(level=logging.DEBUG, | ||
format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', | ||
datefmt='%a, %d %b %Y %H:%M:%S') | ||
droid = QPython3() | ||
code = droid.get_verify_code() | ||
print(code) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 - | ||
|
||
# 这里需修改 config_name 为你的配置文件名称,如 | ||
config_name = "config.yaml" | ||
|
||
# 以脚本地址作为配置文件地址 | ||
import sys, os | ||
config_path = os.path.join(os.path.dirname(sys.argv[0]), config_name) | ||
|
||
try: | ||
import requests | ||
except: | ||
import pip | ||
pip.main(['install', 'requests']) | ||
|
||
try: | ||
import yaml | ||
except: | ||
import pip | ||
pip.main(['install', 'PyYAML']) | ||
|
||
if __name__ == "__main__": | ||
from bjguahao import Guahao | ||
guahao = Guahao(config_path) | ||
guahao.run() |