for a in dat0: schoolid = a['school_id'] print(schoolid) schoolname = a['name'] url1 = 'https://static-data.gaokao.cn/www/2.0/school/' + schoolid + '/info.json' #print("正在下载" + schoolname) html1 = requests.get(url1).text dict1 = json.loads(html1) # 将string转化为dict #print(dict1) if len(dict1) != 0: dat1 = dict1["data"] name = dat1["name"] content = dat1["content"] f985 = dat1["f985"] if f985 == "1": f985 = "是" else: f985 = "否" f211 = dat1["f211"] if f211 == "1": f211 = "是" else: f211 = "否" ruanke_rank = dat1["ruanke_rank"] if ruanke_rank == '0': ruanke_rank = '' type_name = dat1["type_name"] school_nature_name = dat1["school_nature_name"] province_name = dat1["province_name"] city_name = dat1["city_name"] address = dat1["address"] special = [] for j in dat1["special"]: special.append(j["special_name"]) pro_type_min = dat1["pro_type_min"] fen2022 = '' fen2021 = '' fen2020 = '' for k in pro_type_min.keys(): print(k) print(x["name"]) if int(k) == x["name"]: print(pro_type_min[k]) for m in pro_type_min[k]:
时间: 2024-02-14 07:32:46 浏览: 49
这是一段 Python 代码,但是您并没有提出问题。请问您需要我帮您分析这段代码的作用吗?这段代码的主要作用是爬取高校信息,包括高校名称、内容、是否为 985/211 高校、软科排名、类型、学校性质、省份名称、城市名称、地址、专业等级分数线。其中,通过循环遍历获取专业等级的分数线,并根据指定的条件进行筛选。
相关问题
ProgramModelEntities = _migrateRepository.GetAllWithNoTrackingAsync<ProgramModelEntity>().ToList(); Programmes = ProgramModelEntities.Select(program => { CProgramme p = new CProgramme() { Id = new Guid(program.Id), Name = program.Name, SchoolId = SQIConstants.SYS_School_ID, Description = program.Description, CreatedById = String.IsNullOrEmpty(program.CreatedBy) ? new Guid("e306ca07-a21b-40fd-935a-343cfe369001") : new Guid(program.CreatedBy), CreatedTime = program.CreatedOn == null ? new DateTime().Ticks : program.CreatedOn.Value.Ticks, ModifiedById = String.IsNullOrEmpty(program.ModifiedBy) ? new Guid("e306ca07-a21b-40fd-935a-343cfe369001") : new Guid(program.ModifiedBy), ModifiedTime = program.ModifiedOn == null ? new DateTime().Ticks : program.ModifiedOn.Value.Ticks, Duration = 1 }; if (!String.IsNullOrEmpty(program.ProgramAdmins)) { var admins = program.ProgramAdmins.Split(";"); ResourceAccesses.Add(admins.Select(admin => new CResourceAccess() { Id = Guid.NewGuid(), UserId = new Guid(admin), RoleType = RoleType.ProgrammeAdmin, ResourceId = new Guid(program.Id), ResourceLevel = ResourceLevel.Programme } ).ToList()); } ResourcesList.Add(new CResources { Id = new Guid(program.Id), ResourceLevel = ResourceLevel.Programme, SchoolId = SQIConstants.SYS_School_ID, ProgrammeId = new Guid(program.Id), }); return p; } ).ToList(); 优化下这段代码
以下是对这段代码的一些优化建议:
1. 使用异步方法来获取数据,可以提高性能。例如,可以使用 `ToListAsync()` 替代 `ToList()`。
2. 使用 LINQ 的 Select 方法来进行对象的转换,可以让代码更简洁易读。例如,可以使用如下的代码替代 `ProgramModelEntities.Select()`:
```
Programmes = await _migrateRepository.GetAllWithNoTrackingAsync<ProgramModelEntity>()
.Select(program => new CProgramme
{
Id = new Guid(program.Id),
Name = program.Name,
SchoolId = SQIConstants.SYS_School_ID,
Description = program.Description,
CreatedById = String.IsNullOrEmpty(program.CreatedBy)
? new Guid("e306ca07-a21b-40fd-935a-343cfe369001")
: new Guid(program.CreatedBy),
CreatedTime = program.CreatedOn?.Ticks ?? new DateTime().Ticks,
ModifiedById = String.IsNullOrEmpty(program.ModifiedBy)
? new Guid("e306ca07-a21b-40fd-935a-343cfe369001")
: new Guid(program.ModifiedBy),
ModifiedTime = program.ModifiedOn?.Ticks ?? new DateTime().Ticks,
Duration = 1
})
.ToListAsync();
```
3. 对于资源列表和资源访问列表的操作,可以使用 LINQ 的 SelectMany 方法和 Where 方法来替代 foreach 循环。例如,可以使用如下的代码替代 `if (!String.IsNullOrEmpty(program.ProgramAdmins))` 和 `ResourcesList.Add()`:
```
var programmeAdmins = program.ProgramAdmins?.Split(';');
if (programmeAdmins?.Any() == true)
{
ResourceAccesses.AddRange(programmeAdmins
.Select(admin => new CResourceAccess
{
Id = Guid.NewGuid(),
UserId = new Guid(admin),
RoleType = RoleType.ProgrammeAdmin,
ResourceId = new Guid(program.Id),
ResourceLevel = ResourceLevel.Programme
}));
}
ResourcesList.AddRange(programmeAdmins?.Select(admin => new CResources
{
Id = new Guid(program.Id),
ResourceLevel = ResourceLevel.Programme,
SchoolId = SQIConstants.SYS_School_ID,
ProgrammeId = new Guid(program.Id),
}) ?? Enumerable.Empty<CResources>());
```
综上所述,以下是经过优化后的代码:
```
Programmes = await _migrateRepository.GetAllWithNoTrackingAsync<ProgramModelEntity>()
.Select(program => new CProgramme
{
Id = new Guid(program.Id),
Name = program.Name,
SchoolId = SQIConstants.SYS_School_ID,
Description = program.Description,
CreatedById = String.IsNullOrEmpty(program.CreatedBy)
? new Guid("e306ca07-a21b-40fd-935a-343cfe369001")
: new Guid(program.CreatedBy),
CreatedTime = program.CreatedOn?.Ticks ?? new DateTime().Ticks,
ModifiedById = String.IsNullOrEmpty(program.ModifiedBy)
? new Guid("e306ca07-a21b-40fd-935a-343cfe369001")
: new Guid(program.ModifiedBy),
ModifiedTime = program.ModifiedOn?.Ticks ?? new DateTime().Ticks,
Duration = 1
})
.ToListAsync();
var programmeResources = Programmes.SelectMany(programme => new[]
{
new CResources
{
Id = programme.Id,
ResourceLevel = ResourceLevel.Programme,
SchoolId = SQIConstants.SYS_School_ID,
ProgrammeId = programme.Id
}
});
var programmeAdminResources = Programmes.SelectMany(programme =>
{
var programmeAdmins = programme.ProgramAdmins?.Split(';');
return programmeAdmins?.Select(admin => new CResourceAccess
{
Id = Guid.NewGuid(),
UserId = new Guid(admin),
RoleType = RoleType.ProgrammeAdmin,
ResourceId = programme.Id,
ResourceLevel = ResourceLevel.Programme
}) ?? Enumerable.Empty<CResourceAccess>();
});
ResourcesList.AddRange(programmeResources);
ResourceAccesses.AddRange(programmeAdminResources);
```
前端传来的搜索条件 1. pageNum: 1 2. pageSize: 20 3. schoolId: 12 4. clockTime_begin: 2023-08-02 5. clockTime_end: 2023-08-03 ``` <select id="selectAttStudentRecordList" parameterType="AttStudentRecord" resultMap="AttStudentRecordResult"> <include refid="selectAttStudentRecordVo"/> <where> <if test="schoolId != null "> and school_id = #{schoolId}</if> <if test="parentId != null "> and parent_id = #{parentId}</if> <if test="studentId != null "> and student_id = #{studentId}</if> <if test="stuName != null and stuName != ''"> and stu_name like concat('%', #{stuName}, '%')</if> <if test="stuNo != null and stuNo != ''"> and stu_no = #{stuNo}</if> <if test="cardNo != null and cardNo != ''"> and card_no = #{cardNo}</if> <if test="clockType != null "> and clock_type = #{clockType}</if> <if test="imgUrl != null and imgUrl != ''"> and img_url = #{imgUrl}</if> <if test="clock_time != null" > and clock_time =#{clockTime}</if> <if test="channelName != null and channelName != ''"> and channel_name like concat('%', #{channelName}, '%')</if> <if test="deviceId != null "> and device_id = #{deviceId}</if> <if test="tenantId != null "> and tenant_id = #{tenantId}</if> and del_flag = 0 </where> </select> 我在xml文件中的where要怎么写
你可以根据前端传来的搜索条件,在XML文件的`<where>`标签中编写相应的条件语句。以下是根据你提供的搜索条件示例的XML代码示例:
```xml
<select id="selectAttStudentRecordList" parameterType="AttStudentRecord" resultMap="AttStudentRecordResult">
<include refid="selectAttStudentRecordVo" />
<where>
<if test="schoolId != null ">and school_id = #{schoolId}</if>
<if test="clockTime_begin != null ">and clock_time >= #{clockTime_begin}</if>
<if test="clockTime_end != null ">and clock_time <= #{clockTime_end}</if>
and del_flag = 0
</where>
</select>
```
以上示例中,根据前端传来的搜索条件,我仅添加了`schoolId`和`clockTime`的判断条件。你可以根据需要添加其他条件,如`pageNum`、`pageSize`等。
请注意,示例中使用了`>=`和`<=`来表示大于等于和小于等于的比较操作符,这是因为XML文件中需要使用实体编码来表示特殊字符。
希望这能帮到你!如果有任何进一步的问题,请随时问我。
阅读全文