Skip to content

Instantly share code, notes, and snippets.

@net21
Last active December 13, 2016 04:55
Show Gist options
  • Save net21/8279367 to your computer and use it in GitHub Desktop.
Save net21/8279367 to your computer and use it in GitHub Desktop.

Revisions

  1. net21 revised this gist Jan 9, 2014. 1 changed file with 1 addition and 6 deletions.
    7 changes: 1 addition & 6 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -12,12 +12,7 @@ def getTicketCount(yp_info):
    YW 硬卧
    RW 软卧
    """
    ticketCountDesc = "";
    # 本次列车您选择的席别尚有余票94张
    seatTicket = 0; # 所选席别余票多少张
    # 无座179张
    withoutSeatTicket = 0; # 无座票多少张


    seat = {"WZ":0, "YZ":0, "YW":0, "RW":0, "ZY":0, "ZE":0}

    i = 0;
  2. net21 created this gist Jan 6, 2014.
    54 changes: 54 additions & 0 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    def getTicketCount(yp_info):
    """
    从余票字符串中获得余票数据。
    余票信息字符串如下:
    1018053038405095000010180500003032150000
    O055300502M0933000989174800019
    返回的是一个余票字典,并不是很全面,只取了我需要的类型,如下
    ZY 一等座
    ZE 二等座
    WZ 无座
    YZ 硬座
    YW 硬卧
    RW 软卧
    """
    ticketCountDesc = "";
    # 本次列车您选择的席别尚有余票94张
    seatTicket = 0; # 所选席别余票多少张
    # 无座179张
    withoutSeatTicket = 0; # 无座票多少张

    seat = {"WZ":0, "YZ":0, "YW":0, "RW":0, "ZY":0, "ZE":0}

    i = 0;
    while i in range(len(yp_info)):
    # 1*****3179
    group = yp_info[i:i+10];

    # 1(席别)
    seatType = group[:1];
    # 硬座: 1, 硬卧: 3, 软卧: 4, 二等座:O, 一等座:M
    # 3179
    count = group[6:10];
    while len(count) > 1 and count[0:1] == "0": # count为0000的情况, count最终等于0
    count = count[1:1+len(count)];
    # 3179
    count = int(count);
    if seatType == "1":
    if count < 3000:
    seat['YZ'] = count
    else:
    seat['WZ'] = count - 3000
    elif seatType == "3":
    seat['YW'] = count
    elif seatType == "4":
    seat['RW'] = count
    elif seatType == "M":
    seat['ZY'] = count
    elif seatType == "O":
    if count < 3000:
    seat['ZE'] = count
    else:
    seat['WZ'] = count - 3000
    i = i + 10
    return seat