try to finish the job

This commit is contained in:
2025-03-01 13:32:07 +01:00
parent 1bebf03a70
commit fcb3f8d7d8
2 changed files with 53 additions and 13 deletions

View File

@ -156,6 +156,7 @@ abstract class BrowserJob implements ShouldQueue
'--whitelisted-ips=""', '--whitelisted-ips=""',
'--disable-dev-shm-usage', '--disable-dev-shm-usage',
'--user-data-dir=/home/seluser/profile/', '--user-data-dir=/home/seluser/profile/',
'--auto-open-devtools-for-tabs',
])->all()); ])->all());
return RemoteWebDriver::create( return RemoteWebDriver::create(

View File

@ -4,15 +4,9 @@ namespace App\Browser\Jobs\EpicGames;
use App\Browser\BrowserJob; use App\Browser\BrowserJob;
use App\Browser\Components\Hellcase\EpicGamesLogin; use App\Browser\Components\Hellcase\EpicGamesLogin;
use App\Browser\Components\Hellcase\MainNav;
use App\Browser\Jobs\Hellcase\HellcaseLoginQrCode;
use App\Models\JobArtifact;
use App\Models\JobInfo; use App\Models\JobInfo;
use App\Models\JobRun; use App\Models\JobRun;
use App\Notification\NotificationBody\Hellcase\HellcaseNotificationDailyFreeBody; use App\Notification\Notifications\SimpleNotification;
use App\Notification\NotificationBody\Hellcase\HellcaseNotificationLoginBody;
use App\Notification\Notifications\Hellcase\HellcaseNotificationDailyFree;
use App\Notification\Notifications\Hellcase\HellcaseNotificationLogin;
use App\Notification\Providers\AllNotification; use App\Notification\Providers\AllNotification;
use Exception; use Exception;
use Facebook\WebDriver\WebDriverBy; use Facebook\WebDriver\WebDriverBy;
@ -36,7 +30,8 @@ class EpicGamesJob extends BrowserJob implements ShouldBeUniqueUntilProcessing
public function run(Browser $browser): ?JobRun public function run(Browser $browser): ?JobRun
{ {
sleep(40); $browser->visit("https://bscscan.com/contractsVerified");
sleep(3);
Log::info("Running " . self::class); Log::info("Running " . self::class);
$this->jobRun = new JobRun([ $this->jobRun = new JobRun([
"job_id" => $this->jobId, "job_id" => $this->jobId,
@ -44,8 +39,8 @@ class EpicGamesJob extends BrowserJob implements ShouldBeUniqueUntilProcessing
]); ]);
$this->jobRun->save(); $this->jobRun->save();
$this->goToEpicGamesWebsite($browser); // $this->goToEpicGamesWebsite($browser);
$this->removePopups($browser); // $this->removePopups($browser);
sleep(5); sleep(5);
$this->signin($browser); $this->signin($browser);
$this->getFreeGames($browser); $this->getFreeGames($browser);
@ -53,7 +48,7 @@ class EpicGamesJob extends BrowserJob implements ShouldBeUniqueUntilProcessing
$this->jobRun->success = true; $this->jobRun->success = true;
$this->jobRun->save(); $this->jobRun->save();
Log::info( self::class . " run ended"); Log::info(self::class . " run ended");
return $this->jobRun; return $this->jobRun;
} }
@ -101,8 +96,8 @@ class EpicGamesJob extends BrowserJob implements ShouldBeUniqueUntilProcessing
sleep(3); sleep(3);
$jobInfos = JobInfo::where("job_id", $this->jobId)->get(); $jobInfos = JobInfo::where("job_id", $this->jobId)->get();
$email = $jobInfos->where("key", "email")->first()->value; $email = $jobInfos->where("key", "epicgames_account_email")->first()->value;
$password = $jobInfos->where("key", "password")->first()->value; $password = $jobInfos->where("key", "epicgames_account_password")->first()->value;
$browser->within(new EpicGamesLogin, function (Browser $browser) use ($email, $password) { $browser->within(new EpicGamesLogin, function (Browser $browser) use ($email, $password) {
$browser->fillForm($email, $password); $browser->fillForm($email, $password);
}); });
@ -113,6 +108,50 @@ class EpicGamesJob extends BrowserJob implements ShouldBeUniqueUntilProcessing
private function getFreeGames(Browser $browser) private function getFreeGames(Browser $browser)
{ {
$browser->visit('https://www.epicgames.com/store/en-US/free-games'); $browser->visit('https://www.epicgames.com/store/en-US/free-games');
$browser->waitForText("Free Games", 30, true);
$freeGamesLinkElements = $browser->driver->findElements(WebDriverBy::xpath('//a[contains(@aria-label, "Free Now")]'));
$freeGamesLinks = [];
foreach ($freeGamesLinkElements as $element) {
$freeGamesLinks[] = $element->getAttribute("href");
}
foreach ($freeGamesLinks as $link) {
$browser->visit($link);
$this->claimCurrentGame($browser);
}
}
private function claimCurrentGame(Browser $browser)
{
sleep(5);
$this->assertNotDetected($browser);
if ($this->unratedContent($browser)) {
throw new Exception("Le jeu demande un âge et datboi a la flemme de le mettre");
}
$this->waitForAndClickElementContainingText($browser, '//button', "Get", 30, true);
sleep(5);
$this->assertNotDetected($browser);
$browser->waitForText("Place Order", 30, true);
$browser->click("Place Order");
sleep(5);
$this->assertNotDetected($browser);
$browser->waitForText("Order Confirmation", 30, true);
$browser->click("Close");
sleep(5);
AllNotification::send(
new SimpleNotification($this->jobId, "Un jeu a été ajouté à votre bibliothèque", "Un jeu a été ajouté à votre bibliothèque EpicGames")
);
}
private function unratedContent(Browser $browser)
{
try {
$browser->waitForText("please provide your date of birth", 5, true);
return true;
} catch (Exception $_) {
return false;
}
} }
private function removePopups(Browser $browser) private function removePopups(Browser $browser)