mirror of
https://github.com/XFox111/bonch-calendar.git
synced 2026-06-30 10:52:41 +03:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ea6dbf2d8f | |||
| c6d91d7020 |
+30
-22
@@ -97,30 +97,38 @@ app.MapGet("/timetable/{facultyId}/{groupId}", async (
|
||||
}
|
||||
}
|
||||
|
||||
DateTime semesterStartDate = await apiService.GetSemesterStartDateAsync(groupId);
|
||||
string groupName = (await apiService.GetGroupsListAsync(facultyId, 0))[groupId];
|
||||
|
||||
string classesRaw = await apiService.GetScheduleDocumentAsync(groupId, TimetableType.Classes);
|
||||
List<CalendarEvent> timetable = [.. parsingService.ParseGeneralTimetable(classesRaw, semesterStartDate, groupName)];
|
||||
|
||||
TimetableType[] types = [TimetableType.Attestations, TimetableType.Exams, TimetableType.ExamsForExtramural];
|
||||
foreach (TimetableType type in types)
|
||||
try
|
||||
{
|
||||
classesRaw = await apiService.GetScheduleDocumentAsync(groupId, type);
|
||||
timetable.AddRange(parsingService.ParseExamTimetable(classesRaw, groupName));
|
||||
DateTime semesterStartDate = await apiService.GetSemesterStartDateAsync(groupId);
|
||||
string groupName = (await apiService.GetGroupsListAsync(facultyId, 0))[groupId];
|
||||
|
||||
string classesRaw = await apiService.GetScheduleDocumentAsync(groupId, TimetableType.Classes);
|
||||
List<CalendarEvent> timetable = [.. parsingService.ParseGeneralTimetable(classesRaw, semesterStartDate, groupName)];
|
||||
|
||||
TimetableType[] types = [TimetableType.Attestations, TimetableType.Exams, TimetableType.ExamsForExtramural];
|
||||
foreach (TimetableType type in types)
|
||||
{
|
||||
classesRaw = await apiService.GetScheduleDocumentAsync(groupId, type);
|
||||
timetable.AddRange(parsingService.ParseExamTimetable(classesRaw, groupName));
|
||||
}
|
||||
|
||||
Calendar calendar = new();
|
||||
calendar.Properties.Add(new CalendarProperty("X-WR-CALNAME", groupName));
|
||||
calendar.Properties.Add(new CalendarProperty("X-WR-TIMEZONE", "Europe/Moscow"));
|
||||
calendar.Properties.Add(new CalendarProperty("REFRESH-INTERVAL;VALUE=DURATION", "PT6H"));
|
||||
calendar.Events.AddRange(timetable);
|
||||
calendar.AddTimeZone(new VTimeZone("Europe/Moscow"));
|
||||
string serialized = new CalendarSerializer().SerializeToString(calendar)!;
|
||||
|
||||
await File.WriteAllTextAsync(cacheFile, serialized);
|
||||
logger.LogInformation("Cached timetable for group {GroupId} to {CacheFile}.", groupId, cacheFile);
|
||||
return Results.Text(serialized, contentType: "text/calendar");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to generate timetable for group {GroupId} of faculty {FacultyId}.", groupId, facultyId);
|
||||
throw;
|
||||
}
|
||||
|
||||
Calendar calendar = new();
|
||||
calendar.Properties.Add(new CalendarProperty("X-WR-CALNAME", groupName));
|
||||
calendar.Properties.Add(new CalendarProperty("X-WR-TIMEZONE", "Europe/Moscow"));
|
||||
calendar.Properties.Add(new CalendarProperty("REFRESH-INTERVAL;VALUE=DURATION", "PT6H"));
|
||||
calendar.Events.AddRange(timetable);
|
||||
calendar.AddTimeZone(new VTimeZone("Europe/Moscow"));
|
||||
string serialized = new CalendarSerializer().SerializeToString(calendar)!;
|
||||
|
||||
await File.WriteAllTextAsync(cacheFile, serialized);
|
||||
logger.LogInformation("Cached timetable for group {GroupId} to {CacheFile}.", groupId, cacheFile);
|
||||
return Results.Text(serialized, contentType: "text/calendar");
|
||||
})
|
||||
.WithName("GetTimetable")
|
||||
.WithDescription("Gets the iCal timetable for the specified group.")
|
||||
|
||||
@@ -123,15 +123,15 @@ public partial class ParsingService
|
||||
|
||||
private static (string className, string classType, string[] professors, string auditorium) ParseBaseInfo(IElement classElement)
|
||||
{
|
||||
string className = classElement.QuerySelector(".subect")!.TextContent;
|
||||
string classType = classElement.QuerySelector(".type")!.TextContent
|
||||
.Replace("(", string.Empty).Replace(")", string.Empty).Trim();
|
||||
string className = classElement.QuerySelector(".subect")?.TextContent ?? string.Empty;
|
||||
string classType = classElement.QuerySelector(".type")?.TextContent
|
||||
.Replace("(", string.Empty).Replace(")", string.Empty).Trim() ?? string.Empty;
|
||||
|
||||
string[] professors = classElement.QuerySelector(".teacher[title]")!.GetAttribute("title")
|
||||
!.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
string[] professors = classElement.QuerySelector(".teacher[title]")?.GetAttribute("title")
|
||||
?.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) ?? [];
|
||||
|
||||
string auditorium = classElement.QuerySelector(".aud")!.TextContent
|
||||
.Replace("ауд.:", string.Empty).Replace(';', ',').Trim();
|
||||
string auditorium = classElement.QuerySelector(".aud")?.TextContent
|
||||
.Replace("ауд.:", string.Empty).Replace(';', ',').Trim() ?? string.Empty;
|
||||
|
||||
return (className, classType, professors, auditorium);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user