1
0
mirror of https://github.com/XFox111/GUTSchedule.git synced 2026-04-22 06:58:01 +03:00

Cabinet functionality updated (#25)

Cabinet authorization has been turned on
Occupation check in functionality
This commit is contained in:
Michael Gordeev
2020-11-12 15:21:55 +03:00
committed by GitHub
parent 018981002b
commit 6c475dd621
16 changed files with 1457 additions and 1173 deletions
+29 -1
View File
@@ -8,13 +8,14 @@ using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace GUTSchedule
{
public static class Parser
{
private static async Task<HttpClient> VaildateAuthorization(string email, string password)
public static async Task<HttpClient> VaildateAuthorization(string email, string password)
{
if (string.IsNullOrWhiteSpace(email))
throw new ArgumentNullException(nameof(email));
@@ -46,6 +47,8 @@ namespace GUTSchedule
throw new System.Security.VerificationException(responseQuery["error"].Replace("|", "; "));
}
await client.GetAsync("https://lk.sut.ru/cabinet/?login=yes");
return client;
}
@@ -440,5 +443,30 @@ namespace GUTSchedule
return schedule;
}
public static async Task<List<(string, string)>> CheckAvailableOccupations(string email, string password)
{
HttpClient client = await VaildateAuthorization(email, password);
HttpResponseMessage response = await client.GetAsync("https://lk.sut.ru/cabinet//project/cabinet/forms/raspisanie_bak.php");
string responseContent = await response.GetString();
if (!response.IsSuccessStatusCode)
throw new HttpRequestException(responseContent);
IHtmlDocument doc = new HtmlParser().ParseDocument(responseContent);
List<(string, string)> occupations = doc.QuerySelectorAll(".simple-little-table td[align=left] > span[id] > a").Select(i =>
{
string[] parameters = new Regex(@"(?<=\()[0-9,]*(?=\))").Match(i.Attributes["onclick"].Value).Value.Split(',');
return (parameters[0], parameters[1]);
}).ToList();
return occupations;
}
public static async Task ApplyForOccupations(string email, string password, List<(string, string)> occupations)
{
HttpClient client = await VaildateAuthorization(email, password);
foreach (var i in occupations)
await client.GetAsync($"https://lk.sut.ru/cabinet/project/cabinet/forms/raspisanie_bak.php?open=1&rasp={i.Item1}&week={i.Item2}");
}
}
}