Improved substitution page
This commit is contained in:
@@ -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() };
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user