Example #1
0
    def get_electricity_info(self, apart_id, meter_room):
        """get electricity info

            :param apart_id: 栋数
            :param meter_room: 宿舍号
        """
        apart_id = str(apart_id)
        meter_room = str(meter_room)
        try:
            content = LifeService._get_electricity_info_html(apart_id, meter_room)
        except KeyError as e:
            _.d(e.message)
            result = {
                'response': None
            }
            return _.to_json_string(result)
        soup = BeautifulSoup(content)
        tags = soup.find_all(name='span', class_='STYLE7')
        result = {
            'response': {
                'apart': _.trim(tags[0].string),
                'apart_id': _.trim(tags[1].string),
                'used': _.trim(tags[2].string),
                'left': _.trim(tags[3].string),
                'update_time': _.trim(tags[4].string)
            }
        }
        return _.to_json_string(result)
Example #2
0
    def get_score(self):
        """
        获得成绩列表
        :return: json array
        """
        html = self.__get_score_html()
        soup = BeautifulSoup(html)
        div = soup.find_all('div', class_='Section1')[0]
        tag_ps = div.find_all('p')
        del tag_ps[0]
        result = []
        '''
        #one object
        {
           'year':'第一学期',
           'score_list':[
                {
                    'id':'0800040',
                    'name':'C++'
                    'type':'必修',
                    'xuefen':'1',
                    'score':'95',
                    'remark':'重修'
                }
           ]
        }
        '''
        # 最后一个为第二课堂学分,删除之
        tables = soup.find_all('table', attrs={'class': 'MsoTableGrid', 'border': '1'})
        del tables[len(tables) - 1]
        # 第x个学期
        year_num = 1
        for table in tables:
            try:
                trs = table.find_all('tr')

                tern_info = {
                    'year': year_num,
                    'score_list': []
                }
                # 遍历每一列
                for tr in trs:
                    tds = tr.find_all(self.__get_td)
                    if len(tds) == 0:
                        continue
                    lesson_info = {
                        'id': _.trim(tds[0].get_text()),
                        'name': _.trim(tds[1].get_text()),
                        'type': _.trim(tds[2].get_text()),
                        'xuefen': _.trim(tds[3].get_text()),
                        'score': _.trim(tds[4].get_text()),
                        'remark': _.trim(tds[5].get_text())
                    }

                    tern_info['score_list'].append(lesson_info)
                year_num += 1
                result.append(tern_info)
            except Exception as e:
                _.d(e.message)
        return result
Example #3
0
    def get_score(self):
        """
        获得成绩列表
        :return: json array
        """
        html = self.__get_score_html()
        soup = BeautifulSoup(html)
        div = soup.find_all('div', class_='Section1')[0]
        tag_ps = div.find_all('p')
        del tag_ps[0]
        result = []
        '''
        #one object
        {
           'year':'第一学期',
           'score_list':[
                {
                    'id':'0800040',
                    'name':'C++'
                    'type':'必修',
                    'xuefen':'1',
                    'score':'95',
                    'remark':'重修'
                }
           ]
        }
        '''
        # 最后一个为第二课堂学分,删除之
        tables = soup.find_all('table',
                               attrs={
                                   'class': 'MsoTableGrid',
                                   'border': '1'
                               })
        del tables[len(tables) - 1]
        # 第x个学期
        year_num = 1
        for table in tables:
            try:
                trs = table.find_all('tr')

                tern_info = {'year': year_num, 'score_list': []}
                # 遍历每一列
                for tr in trs:
                    tds = tr.find_all(self.__get_td)
                    if len(tds) == 0:
                        continue
                    lesson_info = {
                        'id': _.trim(tds[0].get_text()),
                        'name': _.trim(tds[1].get_text()),
                        'type': _.trim(tds[2].get_text()),
                        'xuefen': _.trim(tds[3].get_text()),
                        'score': _.trim(tds[4].get_text()),
                        'remark': _.trim(tds[5].get_text())
                    }

                    tern_info['score_list'].append(lesson_info)
                year_num += 1
                result.append(tern_info)
            except Exception as e:
                _.d(e.message)
        return result