def parse_station_record(self, line):
fieldnames = ['StationCode', 'StationName', 'DateStart', 'DateEnd', 'AntennaHeight', 'HeightCode', 'AntennaNorth', 'AntennaEast',
'ReceiverCode', 'ReceiverVers', 'ReceiverFirmware', 'ReceiverSerial', 'AntennaCode', 'RadomeCode', 'AntennaSerial']
fieldwidths = (
1, 6, 18, 19, 19, 9, 7, 9, 9, 22, 22, 7, 22, 17, 7, 20) # negative widths represent ignored padding fields
fmtstring = ' '.join('{}{}'.format(abs(fw), 'x' if fw < 0 else 's') for fw in fieldwidths)
fieldstruct = struct.Struct(fmtstring)
parse = fieldstruct.unpack_from
if line[0] == ' ' and len(line) >= 77:
record = dict(zip(fieldnames, map(str.strip, parse(line.ljust(fieldstruct.size))[1:])))
else:
return None
# convert to datetime object
DateStart, DateEnd = self.stninfodate2datetime(record['DateStart'], record['DateEnd'])
record['DateStart'] = DateStart
record['DateEnd'] = DateEnd
record['StationCode'] = record['StationCode'].lower()
return record
评论列表
文章目录