Beispiel #1
0
    def _parse_result(self, response):
        data = StringIO(BeautifulSoup(response.text).find('pre').text.strip())
        # `header` is e.g.:
        # "u'-LAMBDA-VAC-ANG-|-SPECTRUM--|TT|--------TERM---------|---J-J---|----LEVEL-ENERGY--CM-1----'"
        # `colnames` is then
        # [u'LAMBDA VAC ANG', u'SPECTRUM', u'TT', u'TERM', u'J J',
        #  u'LEVEL ENERGY  CM 1']

        header = data.readline().strip().strip('|')

        colnames = [colname.strip('-').replace('-', ' ')
                    for colname in header.split('|') if colname.strip()]
        indices = [i for i, c in enumerate(header) if c == '|']
        input = []
        for line in data:
            row = []
            for start, end in zip([0] + indices, indices + [None]):
                # `value` will hold all cell values in the line, so
                # `u'1.010799'`, `u'Zn XXX'` etc.
                value = line[start:end].strip()
                if value:
                    row.append(value)
                else:
                    # maintain table dimensions when data missing
                    row.append('None')
            if row:
                input.append('\t'.join(row))
        if input:
            return ascii.read(input, data_start=0, delimiter='\t',
                              names=colnames)
        else:
            # return an empty table if the query yielded no results
            return Table()
Beispiel #2
0
 def _parse_result(self, response):
     data = StringIO(BeautifulSoup(response.text).find('pre').text.strip())
     # `header` is e.g. "u'-LAMBDA-VAC-ANG-|-SPECTRUM--|TT|--------TERM---------|---J-J---|----LEVEL ENERGY--CM-1----'"
     header = data.readline().strip().strip('|')
     # `colnames` is then "[u'LAMBDA VAC ANG', u'SPECTRUM', u'TT', u'TERM', u'J J', u'LEVEL ENERGY  CM 1']"
     colnames = [
         colname.strip('-').replace('-', ' ')
         for colname in header.split('|') if colname.strip()
     ]
     indices = [i for i, c in enumerate(header) if c == '|']
     input = []
     for line in data:
         # example for `line`:
         # u'      1.010799    Zn XXX     E1          1-10          1/2-*            0.00 - 98933890.00\n'
         row = []
         for start, end in zip([0] + indices, indices + [None]):
             # `value` will hold all cell values in the line, so
             # `u'1.010799'`, `u'Zn XXX'` etc.
             value = line[start:end].strip()
             if value:
                 row.append(value)
         if row:
             input.append('\t'.join(row))
     if input:
         return ascii.read(input,
                           data_start=0,
                           delimiter='\t',
                           names=colnames)
     else:
         # return an empty table if the query yielded no results
         return Table()