Skip to content

Commit

Permalink
新增配置
Browse files Browse the repository at this point in the history
  • Loading branch information
xiehe committed Jul 30, 2017
1 parent fa241fd commit 33be63b
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 47 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
temp/*
dist
build
setup
*.pyc
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# gjjx-zhushou
公交驾校预约助手
# 公交驾校预约助手

## 如何使用
1. 解压`公交驾校预约助手*.zip`
2. 编辑`conf.ini`
3. 双击`run.exe`运行程序
11 changes: 11 additions & 0 deletions conf.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[assistant]
# 用户名
user_name = 用户名
# 密码
password = 密码

# 刷新间隔(秒)
sleep = 2

# 预约时间 0:上午 1:下午 2:晚上
date_line = 2017-06-25,0|2017-06-25,1
21 changes: 20 additions & 1 deletion login.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env python
# coding: utf-8

import os
import sys
import webbrowser
import random
import re
from PIL import Image
Expand All @@ -17,7 +20,7 @@ def __init__(self, session):
self.captcha_path = 'temp/captcha.png'

# 获取验证码
def getCaptcha(self):
def get_captcha(self):
"""
@return Bool, 文件流
"""
Expand All @@ -30,6 +33,22 @@ def getCaptcha(self):
else:
return False, r.content

# 显示验证码
def show_image(self, file_path):
"""
:param file_path: 图片文件路径
"""
if sys.version_info >= (3, 3):
from shlex import quote
else:
from pipes import quote

if sys.platform == "darwin":
command = "open -a /Applications/Preview.app %s&" % quote(file_path)
os.system(command)
else:
webbrowser.open(os.path.join(os.getcwd(), file_path))

# 登录
def login(self, payload):
url = 'http://www.gjjx.com.cn/member/login?hash=' + str(random.random())
Expand Down
29 changes: 29 additions & 0 deletions parseconf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python
# coding: utf-8

import ConfigParser
import sys
reload(sys)
sys.setdefaultencoding('utf8')

class ParseConf:
def __init__(self):
try:
cf = ConfigParser.ConfigParser()
cf.read('conf.ini')

# 用户名
self.user_name = cf.get('assistant', 'user_name')
# 密码
self.password = cf.get('assistant', 'password')

# 刷新间隔(秒)
self.sleep = int(cf.get('assistant', 'sleep'))

# 预约时间
date_line = cf.get('assistant', 'date_line')
self.date_line = map(lambda x: x.split(','), date_line.split('|'))

except Exception, e:
print '[ERROR] Parse conf.ini failed.'
raise e
95 changes: 51 additions & 44 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@
from session import Session
from login import Login
from appointment import Appointment
from parseconf import ParseConf
import webbrowser
import sys
reload(sys)
sys.setdefaultencoding('gbk')

DATELINE_CN = ['上午', '中午', '晚上']
CONFIG = ParseConf()


# 预约日期
def apdate(appointment, datepoint):
"""
预约日期
:param appointment: 预约session
:param datepoint 需要预约的时间点 [(2017-05-27, 0)]
"""
(postdata, schedule) = appointment.timetable()
# test
# print postdata
# print schedule
print u'获取预约日期表...'

for k,(d,i) in enumerate(datepoint):
Expand All @@ -33,46 +38,48 @@ def apdate(appointment, datepoint):
else:
return False, None

session = Session().session
if __name__ == '__main__':
session = Session().session

login = Login(session)
login.getCaptcha()
captcha = raw_input(u'输入验证码: ')
payload = {
'username': '用户名',
'password': '密码',
'captcha': captcha
}
(loginStat, loginMsg) = login.login(payload)
login = Login(session)
login.get_captcha()
login.show_image(login.captcha_path)
captcha = raw_input(u'输入验证码:')
payload = {
'username': CONFIG.user_name,
'password': CONFIG.password,
'captcha': captcha
}
(loginStat, loginMsg) = login.login(payload)

if loginStat == True:
print u'登录成功'
appointment = Appointment(session)
appointment.login()
nowtime = time.time()

count = 1
aplogin = False
# 已经登录
# 590-600登录 已经登录 (r)
while True:
time.sleep(2)
print count
count = count + 1
try:
ok, ret = apdate(appointment, [('2017-06-25', 0)])
except Exception as e:
print e
continue
if ok == True:
print ret[0] + DATELINE_CN[ret[1]] + u'预约成功'
break
if loginStat == True:
print u'登录成功'
appointment = Appointment(session)
appointment.login()
nowtime = time.time()
count = 1
aplogin = False
# 已经登录
# 590-600登录 已经登录 (r)
while True:
time.sleep(CONFIG.sleep)
print count
count = count + 1
try:
ok, ret = apdate(appointment, CONFIG.date_line)
except Exception as e:
print e
continue
if ok == True:
print ret[0] + DATELINE_CN[ret[1]] + u'预约成功'
break

left = (time.time() - nowtime) % 600
if left <= 590:
aplogin = False
elif aplogin == False and left > 590:
appointment.login()
aplogin = True
else:
print u'登录失败'
left = (time.time() - nowtime) % 600
if left <= 590:
aplogin = False
elif aplogin == False and left > 590:
appointment.login()
aplogin = True
else:
print u'登录失败'

0 comments on commit 33be63b

Please sign in to comment.