Skip to content

Commit

Permalink
Move groups to config
Browse files Browse the repository at this point in the history
  • Loading branch information
wh0o7 committed Sep 18, 2023
1 parent 536c9fd commit 432e644
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
3 changes: 3 additions & 0 deletions StudentsTimetable/Config/GroupsConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace StudentsTimetable.Config;

public record GroupsConfig(string[] Groups);
22 changes: 8 additions & 14 deletions StudentsTimetable/Services/ParseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Support.UI;
using StudentsTimetable.Config;
using StudentsTimetable.Models;
using Telegram.BotAPI.AvailableMethods;
using TelegramBot_Timetable_Core.Config;
using TelegramBot_Timetable_Core.Services;
using Size = System.Drawing.Size;
using Timer = System.Timers.Timer;
Expand All @@ -14,7 +16,7 @@ namespace StudentsTimetable.Services;

public interface IParseService
{
List<string> Groups { get; set; }
string[] Groups { get; init; }
static List<Day> Timetable { get; set; }
Task UpdateTimetableTick();
}
Expand All @@ -34,31 +36,25 @@ public class ParseService : IParseService

private const int DriverTimeout = 2000;

public List<string> Groups { get; set; } = new()
{
"8", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59*",
"60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70",
"71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81",
"82", "83", "84", "160*", "162*", "163*", "164*", "165*", "166*"
};
public string[] Groups { get; init; }

public static List<Day> Timetable { get; set; } = new();

public ParseService(IMongoService mongoService, IBotService botService, IFirefoxService firefoxService,
IDistributionService distributionService)
IDistributionService distributionService, IConfig<GroupsConfig> groups)
{
this._mongoService = mongoService;
this._botService = botService;
this._firefoxService = firefoxService;
this._distributionService = distributionService;

this.Groups = groups.Entries.Groups;
if (!Directory.Exists("./cachedImages")) Directory.CreateDirectory("./cachedImages");

var parseTimer = new Timer(1_000_000)
{
AutoReset = true, Enabled = true
};
parseTimer.Elapsed += async (sender, args) =>
parseTimer.Elapsed += async (_, _) =>
{
try
{
Expand Down Expand Up @@ -192,7 +188,6 @@ public async Task ParseDay()
return false;
})
.ToList();

notificationUserList.AddRange(userList);
}
catch (Exception e)
Expand Down Expand Up @@ -223,8 +218,7 @@ public async Task ParseDay()
_ = this._distributionService.SendDayTimetable(user);
}
this._botService.SendAdminMessageAsync(new SendMessageArgs(0,
$"{notificationUserList.Count} notifications sent"));
this._botService.SendAdminMessageAsync(new SendMessageArgs(0,$"{notificationUserList.Count} notifications sent"));
});
}

Expand Down

0 comments on commit 432e644

Please sign in to comment.