Script for Automatic Bus Scheduling at bus driving schools

Source: Internet
Author: User
Import urllib, urllib2, cookielibimport reimport datetime class loginjx: # camouflage browser header = {'user-agent': 'mozilla/5.0 (windows; U; Windows NT 6.1; en-us; RV: 1.9.1.6) Gecko/20091201 Firefox/3.5.6 '} username = ''passwd = ''cookie = none # cookie object cookiefile = '. /cookies. dat '# user = ''def _ init _ (self, username, passwd): Self. username = username self. passwd = passwd # cookie setting self. cooki E = cookielib. lwpcookiejar () # use a custom cookie to store opener = urllib2.build _ opener (urllib2.httpcookieprocessor (self. cookie) urllib2.install _ opener (opener) # log on to Def login (Self): # Set the request parameter to postdata = {'username': Self. username, 'Password': Self. passwd, 'cookietime': 2592000, 'dosubmit ': 'login', 'forward': ''} postdata = urllib. urlencode (postdata) # initiate a request Req = urllib2.request (url = 'HTTP: // www.gjjx.com.cn/index.php? M = Member & C = index & A = login ', Data = postdata, # request data headers = self. header # request header) Result = urllib2.urlopen (req ). read () Result = STR (result) self. user = self. username self. cookie. save (self. cookiefile) # Save the cookie If 'login succeeded 'in result: Print ("% s you have logged on successfully. --------- \ N "% (self. user) Flag = true else: Print ("% s shameful failed bird login") Flag = false return flag def get_uid (Self): uid_url = urllib2.request (url = 'HTTP: // www.gjjx.com.cn/index.php? M = Member & C = index & A = appointment ', headers = self. header) auth = urllib2.urlopen (uid_url ). read () Result = STR (auth) uid = Re. findall (''' student ID No. <span> (\ D +) </span> ''', result) return uid [0] def order_class (self, uid = "61394720", yyrq = "25-dec-11", SD = "5", cnbh = "32220", traint = "2"): base_url = "http://www.gjjx.com.cn/index.php? M = Member & C = index & A = BPK & "query_param =" id = % S & yyrq = % S & SD = % S & cnbh = % S & traint = % s "% (UID, yyrq, SD, cnbh, traint) print base_url + query_param uid_url = urllib2.request (url = (base_url + query_param), headers = self. header) auth = urllib2.urlopen (uid_url ). read () Result = STR (auth) If "expired" in result: Return "timeout" Elif "successful" in result: return "OK" Elif "duplicate reservation is not allowed for the same car" in result: Return "OK" else: Return "F Ailed "Print (" requesting ...... ") # username and password login = loginjx ('username', 'Password') # Time Window 5--- 6--- 18: 00sd = "5" # field number cnbh = "32221" # reservation date order_date = '2017-12-25 'yyrq = datetime. datetime. strptime (order_date, '% Y-% m-% D '). strftime ('% d-% B-% y '). upper (); # yyrq = "25-dec-11" #0 course class 2 simulation .... traint = "2" flag = falseorder_ OK = false while flag = false: Flag = login. login () If flag: uid = login. get _ UID () while order_ OK = false: Result = login. order_class (uid = uid, yyrq = yyrq, SD = SD, cnbh = cnbh, traint = traint) If result = "timeout": Print ("timeout! Log on again! ") Flag = false order_ OK = false Elif result =" failed ": Print (" continuously trying ") pass else: order_ OK = true flag = True Print ("It's a great deal !! ")

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.