Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
coeusite committed Apr 20, 2018
1 parent af86817 commit a54c60c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ Copyright (C) 2017
- 默认用法: ```python bjguahao.py```
- 指定配置: ```python bjguahao.py -c your-conf.yaml```

**Android QPython3 使用方法**
1. 安装 [QPython3](https://play.google.com/store/apps/details?id=org.qpython.qpy3)[QPython](https://play.google.com/store/apps/details?id=org.qpython.qpy)
2. 安装 [QPy3.6](https://play.google.com/store/apps/details?id=org.qpython.qpy36) 并运行(会安装 Python 3.6)
3. 在 QPython3 中将版本切为 Python 3.6(默认为 Python 3.2)
4. 修改配置文件(```config.yaml```或自定义)
5. 由于 QPython3 不支持传参,如需指定配置文件,需手动修改```qpython3_run.py```中的```config_name```配置文件名
6. 将整个项目复制到你的 Android
7. 在 QPython3 中运行```qpython3_run.py```

若配置文件不在项目目录,也可修改```qpython3_run.py```中的```config_path```为配置文件的**绝对**地址,如
```
config_path = "/storage/emulated/0/qpython/projects3/bjguahao/custom.yaml"
```

## 配置文件

默认配置文件 `config.yaml`
Expand Down Expand Up @@ -77,7 +91,7 @@ DebugLevel: "info"
#使用ios短信和mac电脑接收验证码
useIMessage: "false"

# 是否使用 QPython3 运行本脚本
# 是否使用 QPython3.6 运行本脚本
useQPython3: "false"
```
Expand Down
18 changes: 11 additions & 7 deletions bjguahao.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def __init__(self, config_path):
try:
with open(config_path, "r", encoding="utf-8") as yaml_file:
data = yaml.load(yaml_file)

debug_level = data["DebugLevel"]
if debug_level == "debug":
self.debug_level = logging.DEBUG
Expand Down Expand Up @@ -72,7 +71,7 @@ def __init__(self, config_path):
self.useQPython3 = data["useQPython3"]
except KeyError:
self.useQPython3 = "false"

#
logging.info("配置加载完成")
logging.debug("手机号:" + str(self.mobile_no))
logging.debug("挂号日期:" + str(self.date))
Expand Down Expand Up @@ -119,9 +118,12 @@ def __init__(self, config_path="config.yaml"):
self.imessage = None

if self.config.useQPython3 == 'true':
# 按需导入 qpython3.py
import qpython3
self.qpython3 = qpython3.QPython3()
try: # Android QPython3 验证
# 按需导入 qpython3.py
import qpython3
self.qpython3 = qpython3.QPython3()
except ModuleNotFoundError:
self.qpython3 = None
else:
self.qpython3 = None

Expand Down Expand Up @@ -159,7 +161,8 @@ def auth_login(self):
登陆
"""
try:
cookies_file = os.path.join("." + self.config.mobile_no + ".cookies")
# patch for qpython3
cookies_file = os.path.join(os.path.dirname(sys.argv[0]), "." + self.config.mobile_no + ".cookies")
self.browser.load_cookies(cookies_file)
if self.is_login():
logging.info("cookies登录成功")
Expand All @@ -182,7 +185,8 @@ def auth_login(self):
try:
data = json.loads(response.text)
if data["msg"] == "OK" and not data["hasError"] and data["code"] == 200:
cookies_file = os.path.join("." + self.config.mobile_no + ".cookies")
# patch for qpython3
cookies_file = os.path.join(os.path.dirname(sys.argv[0]), "." + self.config.mobile_no + ".cookies")
self.browser.save_cookies(cookies_file)
logging.info("登陆成功")
return True
Expand Down
4 changes: 2 additions & 2 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ DebugLevel: "info"
#使用ios短信和mac电脑接收验证码
useIMessage: "false"

# 是否使用 QPython3 运行本脚本
useQPython3: "false"
# 是否使用 QPython3.6 运行本脚本
useQPython3: "true"
26 changes: 26 additions & 0 deletions qpython3_run.py
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()

0 comments on commit a54c60c

Please sign in to comment.