Archived
Private
Public Access
1
0

Improved substitution page

This commit is contained in:
2023-04-24 18:50:10 +02:00
parent 45a7457ef3
commit 5f3016eccb
12 changed files with 186 additions and 53 deletions

View File

@@ -1,4 +1,5 @@
using BetterIServ.Backend.Entities;
using HtmlAgilityPack;
using Microsoft.AspNetCore.Mvc;
using PuppeteerSharp;
using Credentials = BetterIServ.Backend.Entities.Credentials;
@@ -6,7 +7,7 @@ using Credentials = BetterIServ.Backend.Entities.Credentials;
namespace BetterIServ.Backend.Controllers;
[ApiController]
[Route("auth")]
[Route("iserv")]
public class AuthController : ControllerBase {
[HttpPost("login")]
@@ -47,4 +48,28 @@ public class AuthController : ControllerBase {
return authKeys;
}
[HttpPost("groups")]
public async Task<ActionResult<SingleResult<string[]>>> GetCourses([FromBody] AuthKeys keys, [FromQuery] string domain) {
var client = new HttpClient();
var request = new HttpRequestMessage {
Method = HttpMethod.Get,
RequestUri = new Uri($"https://{domain}/iserv/profile"),
Headers = {
{ "cookie", keys.ToCookieString() }
}
};
var raw = await (await client.SendAsync(request)).Content.ReadAsStringAsync();
var html = new HtmlDocument();
html.LoadHtml(raw);
var list = html.DocumentNode.SelectSingleNode("//body/div/div[2]/div[3]/div/div/div[2]/div/div/div/div/ul[1]");
var courses = new List<string>();
foreach (var child in list.ChildNodes) {
if (child.ChildNodes.Count < 1) continue;
courses.Add(child.ChildNodes[0].InnerText);
}
return new SingleResult<string[]> { Value = courses.ToArray() };
}
}

View File

@@ -42,16 +42,32 @@ public class UnitsController : ControllerBase {
if (node.ChildNodes.Count < 9) continue;
var substitution = new Substitution {
Class = node.ChildNodes[0].InnerText,
Times = node.ChildNodes[1].InnerText.Split(" - ").Select(int.Parse).ToArray(),
Type = node.ChildNodes[2].InnerText,
Representative = node.ChildNodes[3].InnerText,
Lesson = node.ChildNodes[4].InnerText,
NewLesson = node.ChildNodes[4].InnerText,
Lesson = node.ChildNodes[5].InnerText,
Room = node.ChildNodes[6].InnerText,
Teacher = node.ChildNodes[7].InnerText,
Description = node.ChildNodes[9].InnerText
};
var classes = node.ChildNodes[0].InnerText;
if (!classes.StartsWith("Q")) {
string grade = new string(classes.ToCharArray().Where(char.IsNumber).ToArray());
var subClasses = classes.Replace(grade, "").ToCharArray();
var result = new string[subClasses.Length];
for (int j = 0; j < subClasses.Length; j++) {
result[j] = grade + subClasses[j];
}
substitution.Classes = result;
}
else {
substitution.Classes = new[] { classes };
}
data.Substitutions.Add(substitution);
}

View File

@@ -6,4 +6,8 @@ public struct AuthKeys {
public string AuthSid { get; set; }
public string SatId { get; set; }
public string AuthSession { get; set; }
public string ToCookieString() {
return $"IServSession={Session}; IServSAT={Sat}; IServAuthSID={AuthSid}; IServSATId={SatId}; IServAuthSession={AuthSession}";
}
}

View File

@@ -1,11 +1,12 @@
namespace BetterIServ.Backend.Entities;
public struct Substitution {
public string Class { get; set; }
public string[] Classes { get; set; }
public int[] Times { get; set; }
public string Type { get; set; }
public string Representative { get; set; }
public string Lesson { get; set; }
public string NewLesson { get; set; }
public string Room { get; set; }
public string Teacher { get; set; }
public string Description { get; set; }