PrintSchedule
This commit is contained in:
parent
8ad3a57b72
commit
35661b98da
@ -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];
|
||||
|
||||
@ -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}")
|
||||
};
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
||||
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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user