From 35661b98da9db700bd52532d536645e0d5698600 Mon Sep 17 00:00:00 2001 From: Timerix22 Date: Sat, 2 Sep 2023 20:57:51 +0600 Subject: [PATCH] PrintSchedule --- Platonus.API/DataModels/Schedule.cs | 2 +- Platonus.API/PlatonusLanguage.cs | 13 +++++- PlatonusSchedule.CLI/Program.cs | 68 ++++++++++++++++++++++++++--- 3 files changed, 75 insertions(+), 8 deletions(-) diff --git a/Platonus.API/DataModels/Schedule.cs b/Platonus.API/DataModels/Schedule.cs index d718593..aa53238 100644 --- a/Platonus.API/DataModels/Schedule.cs +++ b/Platonus.API/DataModels/Schedule.cs @@ -76,7 +76,7 @@ public class Schedule public class Day { public (TimeRange Time, Lesson? Lesson)[] LessonHours { get; } - internal DayOfWeek DayOfWeek { get; } + public DayOfWeek DayOfWeek { get; } internal Day(int dayIndex, int dayLessonsCount) { LessonHours = new (TimeRange, Lesson?)[dayLessonsCount]; diff --git a/Platonus.API/PlatonusLanguage.cs b/Platonus.API/PlatonusLanguage.cs index 957cf8b..3918667 100644 --- a/Platonus.API/PlatonusLanguage.cs +++ b/Platonus.API/PlatonusLanguage.cs @@ -1,4 +1,6 @@ -namespace Platonus.API; +using System; + +namespace Platonus.API; public class PlatonusLanguage { @@ -14,4 +16,13 @@ public class PlatonusLanguage public static PlatonusLanguage English = new(0, "en"); public static PlatonusLanguage Russian = new(1, "ru"); public static PlatonusLanguage Kazakh = new(2, "kz"); + + public static PlatonusLanguage Parse(string literalCode) => + literalCode.ToLower() switch + { + "en" => English, + "ru" => Russian, + "kz" => Kazakh, + _ => throw new Exception($"unknown language code: {literalCode}") + }; } \ No newline at end of file diff --git a/PlatonusSchedule.CLI/Program.cs b/PlatonusSchedule.CLI/Program.cs index 3ea323e..7192de4 100644 --- a/PlatonusSchedule.CLI/Program.cs +++ b/PlatonusSchedule.CLI/Program.cs @@ -1,20 +1,76 @@ using System; +using System.Linq; +using System.Text; using Platonus.API; +using Platonus.API.DataModels; +Console.InputEncoding = Encoding.UTF8; +Console.OutputEncoding = Encoding.UTF8; var p = new PlatonusClient(); var loginCredentials = new LoginCredentials( - ReadString("login"), - ReadString("password"), - PlatonusLanguage.English); + ReadString("student id") + "@iitu.edu.kz", + ReadString("password", true), + PlatonusLanguage.Parse(ReadString("language (en/ru/kz)")) +); await p.LoginAsync(loginCredentials); var schedule = await p.GetScheduleAsync(); -return; +while (true) +{ + PrintSchedule(schedule); + Console.ReadKey(); +} -string ReadString(string question) + +string ReadString(string question, bool hideInput = false) { Console.Write($"{question}: "); string? answ = Console.ReadLine(); if (string.IsNullOrEmpty(answ)) throw new NullReferenceException(); + if (hideInput) + { + Console.CursorTop--; + Console.CursorLeft = question.Length + 2; + for (int i = 0; i < answ.Length; i++) + Console.Write('*'); + Console.WriteLine(); + } return answ; -} \ No newline at end of file +} + +void PrintHeader(char sep, string title) +{ + int sepCount = Console.BufferWidth - 4 - title.Length; + for (int i = 0; i < sepCount / 2; i++) + Console.Write(sep); + Console.Write('['); + Console.Write(title); + Console.Write(']'); + for (int i = 0; i < sepCount / 2 + sepCount % 2; i++) + Console.Write(sep); + Console.WriteLine(); +} + +void PrintSchedule(Schedule s) +{ + PrintHeader('=', "SCHEDULE"); + Console.WriteLine($"selected year: {s.SelectedYear}"); + Console.WriteLine($"selected term: {s.SelectedTermNumber}"); + Console.WriteLine($"selected week: {s.SelectedWeekNumber} of {s.TermWeekNumbers.Last()}"); + Console.WriteLine($"current week: {s.CurrentWeekNumber} of {s.TermWeekNumbers.Last()}"); + + foreach (var day in s.Days) + { + PrintHeader('-', $"{day.DayOfWeek:G}"); + foreach (var lessonHour in day.LessonHours) + { + if (lessonHour.Lesson is not null) + { + Console.Write($"{lessonHour.Time.Start:hh\\:mm}-{lessonHour.Time.Finish:hh\\:mm}"); + Schedule.Day.Lesson l = lessonHour.Lesson; + Console.WriteLine($" | {l.SubjectName} ({l.LessonTypeName}) at {l.Auditory}"); + Console.WriteLine($" | tutor: {l.TutorName}"); + } + } + } +}