Skip to content

Commit

Permalink
Refactor notification about teachers timetable changed
Browse files Browse the repository at this point in the history
  • Loading branch information
wh0o7 committed Sep 9, 2023
1 parent 0169bb5 commit 2cb9b26
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
1 change: 0 additions & 1 deletion TeachersTimetable/Models/TeacherInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public class TeacherInfo
public string Date { get; set; }
public List<Lesson> Lessons = new();


public override bool Equals(object? obj)
{
if (obj == null || this.GetType() != obj.GetType())
Expand Down
17 changes: 9 additions & 8 deletions TeachersTimetable/Services/ParseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ParseService : IParseService
{
private readonly IMongoService _mongoService;
private readonly IBotService _botService;
private readonly IFirefoxService _chromeService;
private readonly IFirefoxService _firefoxService;
private readonly IDistributionService _distributionService;

private const string WeekUrl =
Expand Down Expand Up @@ -141,12 +141,12 @@ public class ParseService : IParseService
private static string LastDayHtmlContent { get; set; }
private static string LastWeekHtmlContent { get; set; }

public ParseService(IMongoService mongoService, IBotService botService, IFirefoxService chromeService,
public ParseService(IMongoService mongoService, IBotService botService, IFirefoxService firefoxService,
IDistributionService distributionService)
{
this._mongoService = mongoService;
this._botService = botService;
this._chromeService = chromeService;
this._firefoxService = firefoxService;
this._distributionService = distributionService;

if (!Directory.Exists("./cachedImages")) Directory.CreateDirectory("./cachedImages");
Expand Down Expand Up @@ -174,7 +174,7 @@ public async Task ParseDay()
Console.WriteLine("Start day parse");

var teacherInfos = new List<TeacherInfo>();
var (service, options, delay) = this._chromeService.Create();
var (service, options, delay) = this._firefoxService.Create();
var day = string.Empty;
using (FirefoxDriver driver = new FirefoxDriver(service, options, delay))
{
Expand Down Expand Up @@ -245,7 +245,7 @@ public async Task ParseDay()
}

var notificationUsersList = new List<User>();

var teacherUpdatedList = new List<string>();
foreach (var teacherInfo in teacherInfos)
{
var count = 0;
Expand Down Expand Up @@ -276,7 +276,7 @@ public async Task ParseDay()
Timetable.LastOrDefault()?.TeacherInfos.FirstOrDefault(t => t.Name == teacherInfo.Name);

if (teacherInfoFromTimetable is null || teacherInfoFromTimetable.Equals(teacherInfo)) continue;

teacherUpdatedList.Add(teacherInfo.Name);
try
{
_ = this._botService.SendAdminMessageAsync(
Expand All @@ -293,6 +293,7 @@ public async Task ParseDay()
}
}

_ = this._botService.SendAdminMessageAsync(new SendMessageArgs(0, $"There's been a schedule change with the teachers: {string.Join(',', teacherUpdatedList)}"));
Timetable.Clear();
Timetable.Add(new()
{
Expand Down Expand Up @@ -325,7 +326,7 @@ public async Task ParseWeek()
{
Console.WriteLine("Start week parse");

var (service, options, delay) = this._chromeService.Create();
var (service, options, delay) = this._firefoxService.Create();
using (FirefoxDriver driver = new FirefoxDriver(service, options, delay))
{
driver.Manage().Timeouts().PageLoad.Add(TimeSpan.FromMinutes(2));
Expand Down Expand Up @@ -392,7 +393,7 @@ public async Task UpdateTimetableTick()
{
Console.WriteLine("Start update tick");
bool parseDay = false, parseWeek = false;
var (service, options, delay) = this._chromeService.Create();
var (service, options, delay) = this._firefoxService.Create();
using (FirefoxDriver driver = new FirefoxDriver(service, options, delay))
{
//Day
Expand Down

0 comments on commit 2cb9b26

Please sign in to comment.