Chinaunix首页 | 论坛 | 博客
  • 博客访问: 512274
  • 博文数量: 119
  • 博客积分: 5054
  • 博客等级: 大校
  • 技术积分: 1305
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-03 13:13
文章分类

全部博文(119)

文章存档

2011年(4)

2010年(115)

我的朋友

分类: Python/Ruby

2010-01-03 14:12:37

程序运行效果:
程序源代码:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys, urllib2

def CetQuery(band, exam_id):
    """CETQuery version 0.2 2009.2.28

    An Exercise Program by PT, GZ University
    Author Blog: http://apt-blog.co.cc , Welcome to Drop by.
    "
""

    #查询连接
    cet = "" + band + "&id=" + exam_id

    print "Connecting..."

    #构造HTTP头
    header = {'Referer':''}

    #第二个参数出现则使用post方式提交
    req = urllib2.Request(cet, '', header)

    try:
        data = urllib2.urlopen(req).read()
    except BaseException, e:
        print "Error retrieving data:", e
        return -1

    if not len(result):
        print "Error Occured. Maybe record not existed."
        return -1

    #解码字符串
    result = data.decode("gb2312").encode("utf8")

    res_tu = tuple(result.split(','))
    score_tu = ("听力", "阅读", "综合", "写作", "总分", "学校", "姓名")

    print "n***** CET %s 成绩清单 *****" % (band)
    print "-准考证号: %s" % (exam_id)
    for i in range(7):
        print "-%s: %s" % (score_tu[i], res_tu[i])
    print "**************************n"
    print "准考证号前一位同学: %sn后两位同学分别是: %s、%s" % (res_tu[-3], res_tu[-2], res_tu[-1])

    return 0

if __name__ == "__main__":
    if (len(sys.argv) != 3) or
        (sys.argv[1] != '4' and sys.argv[1] != '6') or
        (len(sys.argv[2]) != 15):
        print "Error: 程序参数错误,考试类型(4、6),准考证号长度(15位)"
        print "nExample:nnCETQuery.py 4 123456789012345nn"
        print CetQuery.__doc__
        sys.exit(1)

    statue = CetQuery(sys.argv[1], sys.argv[2])
    sys.exit(statue)


阅读(715) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~