#!/usr/bin/python2  
#encoding:UTF-8

from urllib import urlencode
from urllib2 import urlopen
import urllib2
import os
import sys

if __name__ == "__main__":
	
    if not os.access('user.dat', os.F_OK):
	print "用户帐号信息文件丢失"
        sys.exit()
    else:
        f=open('user.dat')  
	message=f.readlines(2)

    login_name=message[0].strip()
    login_pass=message[1].strip()

    opener=urllib2.build_opener(urllib2.HTTPRedirectHandler(), urllib2.HTTPHandler(debuglevel=0))
    opener.addheaders=[('User-agent', "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)")]
    url='http://gate.lnu.edu.cn/'
    
    try:

        response=opener.open(url, urlencode({"DDDDD":login_name, "upass":login_pass, "0MKKey":None}))
        gj_print = response.read().decode("gb2312")

        if gj_print.find(u'您已经成功登录') != -1:
	    print '\n\n\n' 
	    print '##################################'
	    print '用户： %s 您好'%login_name
       	    print '您已经成功登录'
	    print '##################################'
	    print '\n\n\n' 
        else:
            print '\n\n\n' 
	    print '##################################'
	    print '抱歉，您登录失败'
            print '##################################'
            print '\n\n\n' 
    except:
	print '\n\n\n' 
	print '##################################'
        print "网络联通有误， 请检测网络是否可达"
        print '##################################'
        print '\n\n\n' 
