Exemplo n.º 1
0
 def test_cal_term_code(self):
     with pytest.raises(ValueError):
         util.cal_term_code(2001)
     assert util.cal_term_code(2002) == '001'
     assert util.cal_term_code(2002, is_first_term=False) == '002'
Exemplo n.º 2
0
                    logger.warning('{} 的照片已下载过'.format(full_name))
                    exist_sum += 1
                    continue
                try:
                    res = requests.get(img_url)
                    if res.status_code == 200:
                        with open(filename, 'wb') as fp:
                            fp.write(res.content)
                        logger.info('下载 {} 的照片成功'.format(full_name))
                        success_sum += 1
                    elif res.status_code == 404:
                        logger.warning('下载 {} 的照片失败'.format(full_name))
                        fail_sum += 1
                except Exception as e:
                    logger.error('下载 {} 的照片出错\n\t{}'.format(full_name, e))
                    error_sum += 1
        logger.info('{} 学期共有 {} 名学生'.format(term_code, stu_sum))
        logger.info('{} 学期下载完成,成功 {},失败 {},错误 {}, 已存在 {}'.format(
            term_code, success_sum, fail_sum, error_sum, exist_sum))
    else:
        logger.critical('没有获取到第 {} 的教学班级'.format(term_code))
        sys.exit(0)


if __name__ == '__main__':
    setup_dir()
    for year in range(START_YEAR, END_YEAR + 1):
        term_code = cal_term_code(year)
        t = threading.Thread(target=fetch_img, name=year, args=(term_code,))
        t.start()
Exemplo n.º 3
0
                    logger.warning('{} 的照片已下载过'.format(full_name))
                    exist_sum += 1
                    continue
                try:
                    res = requests.get(img_url)
                    if res.status_code == 200:
                        with open(filename, 'wb') as fp:
                            fp.write(res.content)
                        logger.info('下载 {} 的照片成功'.format(full_name))
                        success_sum += 1
                    elif res.status_code == 404:
                        logger.warning('下载 {} 的照片失败'.format(full_name))
                        fail_sum += 1
                except Exception as e:
                    logger.error('下载 {} 的照片出错\n\t{}'.format(full_name, e))
                    error_sum += 1
        logger.info('{} 学期共有 {} 名学生'.format(term_code, stu_sum))
        logger.info('{} 学期下载完成,成功 {},失败 {},错误 {}, 已存在 {}'.format(
            term_code, success_sum, fail_sum, error_sum, exist_sum))
    else:
        logger.critical('没有获取到第 {} 的教学班级'.format(term_code))
        sys.exit(0)


if __name__ == '__main__':
    setup_dir()
    for year in range(START_YEAR, END_YEAR + 1):
        term_code = cal_term_code(year)
        t = threading.Thread(target=fetch_img, name=year, args=(term_code, ))
        t.start()