Skip to content

Commit

Permalink
Only use DriverManager on Chrome compatible systems
Browse files Browse the repository at this point in the history
  • Loading branch information
KarmaKamikaze committed Sep 25, 2024
1 parent 82ea36f commit 02fed0c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions MoxfieldPriceScraper/MoxfieldScraper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Drawing;
using System.Globalization;
using System.Runtime.InteropServices;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using Serilog;
Expand Down Expand Up @@ -60,13 +61,17 @@ public async Task ScrapeAsync(CancellationToken cancellationToken)
if (!string.IsNullOrEmpty(_settings.SenderEmailAddress) &&
!string.IsNullOrEmpty(_settings.SenderEmailPassword) &&
!string.IsNullOrEmpty(_settings.ReceiverEmailAddress))
{
await EmailService.SendEmailWithEmbeddedImageAsync(_settings.SenderEmailAddress,
_settings.SenderEmailPassword,
_settings.ReceiverEmailAddress, $"Moxfield Scraper Success on {_deckTitle}!",
$"Optimal price found for {_deckTitle}: €{finalPrice}! See attachment proof...",
Path.Combine(dataDirectory, $"{_deckTitle}_proof.png"));
}
else
{
Log.Warning("Email notification settings are not fully configured");
}
}
}

Expand Down Expand Up @@ -103,7 +108,6 @@ protected virtual void Dispose(bool disposing)
private void InitializeWebDriver()
{
Log.Debug("Initializing WebDriver");
new DriverManager().SetUpDriver(new ChromeConfig());
var chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--no-sandbox"); // Bypass OS security model
chromeOptions.AddArgument("--headless=new"); // Run in headless mode, without a GUI
Expand All @@ -117,6 +121,12 @@ private void InitializeWebDriver()
};
chromeOptions.AddUserProfilePreference("prefs", preferences);

if (RuntimeInformation.OSArchitecture == Architecture.Arm ||
RuntimeInformation.OSArchitecture == Architecture.Arm64)
{
new DriverManager().SetUpDriver(new ChromeConfig());
}

_driver = new ChromeDriver(chromeOptions);
_driver.Manage().Timeouts().ImplicitWait = _elementSeekTimeout;
Log.Debug("WebDriver initialized with ImplicitWait set to {Timeout}", _elementSeekTimeout);
Expand Down Expand Up @@ -290,7 +300,10 @@ private async Task<decimal> GetPrice(decimal targetPrice, int updateFrequency, C
Log.Information("{Time}\tPrice Before: [€{BeforePrice}]\tNow: [€{NewPrice}]",
DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), price, newPrice);
price = newPrice;
if (price > targetPrice) Thread.Sleep(TimeSpan.FromSeconds(updateFrequency));
if (price > targetPrice)
{
Thread.Sleep(TimeSpan.FromSeconds(updateFrequency));
}
}

Log.Information("Optimal price found: €{Price}!", price);
Expand Down

0 comments on commit 02fed0c

Please sign in to comment.