Skip to content

Commit

Permalink
Merge pull request #30 from richard-muvirimi/development
Browse files Browse the repository at this point in the history
Change status message character case
  • Loading branch information
richard-muvirimi committed Nov 3, 2023
2 parents ec5498b + b69eb05 commit 81f7c02
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions app/Traits/ScrapesRates.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function scrape(): void
return;
}

$site = '<html lang="en-US"><body>'.$site.'</body></html>';
$site = '<html lang="en-US"><body>' . $site . '</body></html>';

Cache::set($this->source_url, $site, CarbonInterval::minutes(30));
}
Expand All @@ -49,7 +49,7 @@ private function getHtmlContent(): string
{

$headers = [
'Authorization' => 'Bearer '.env('SCRAPPY_TOKEN'),
'Authorization' => 'Bearer ' . env('SCRAPPY_TOKEN'),
];

$body = [
Expand All @@ -67,7 +67,7 @@ private function getHtmlContent(): string

$client = new Client($options);

$response = $client->post(env('SCRAPPY_SERVER').'/scrape', [
$response = $client->post(env('SCRAPPY_SERVER') . '/scrape', [
'headers' => $headers,
'form_params' => $body,
]);
Expand All @@ -91,7 +91,7 @@ private function getUserAgent(): string
{
$agent = Cache::get('user-agent');

if (! $agent) {
if (!$agent) {
$agent = env('USER_AGENT');

$agent = preg_replace('/headless/i', '', $agent);
Expand All @@ -116,7 +116,7 @@ private function parseHtml(string $html): void
$converter = new CssSelectorConverter();

$selector = $this->rate_selector;
if (! $this->isXpath($selector)) {
if (!$this->isXpath($selector)) {
$selector = $converter->toXPath($selector);
}

Expand All @@ -133,22 +133,22 @@ private function parseHtml(string $html): void
}

$selector = $this->rate_updated_at_selector;
if (! $this->isXpath($selector)) {
if (!$this->isXpath($selector)) {
$selector = $converter->toXPath($selector);
}

//date
$this->rate_updated_at = $this->cleanDate($crawler->filterXPath($selector)->text(), $this->source_timezone);
$this->status = true;
$this->statusMessage = '';
$this->status_message = '';

} else {
$this->status = false;
$this->statusMessage = 'Rate is an empty string.';
$this->status_message = 'Rate is an empty string.';
}
} catch (Exception $e) {
$this->status = false;
$this->statusMessage = $e->getMessage();
$this->status_message = $e->getMessage();
} finally {
$this->save();
}
Expand Down Expand Up @@ -179,7 +179,7 @@ private function cleanRate(string $value, string $locale): float
*/
$amount = preg_replace('/(\d)\s+(\d)/', '$1$2', $amount);

if (! is_numeric($amount)) {
if (!is_numeric($amount)) {
// separate alpha characters from numeric
$amount = preg_replace('/([^0-9,.]*)([0-9,.]+)([^0-9,.]*)/i', '$1 $2 $3', $amount);

Expand Down Expand Up @@ -308,7 +308,7 @@ private function cleanDate(string $value, string $timezone): Carbon
$months[] = strtolower(DateTime::createFromFormat('n', $i)->format('F'));
}

$regex = "/\b(?!(".implode('|', $months).'|(\w[0-9][a-z])))(\w*[a-z]+[^\s]*|(\w[^\D\d\w]))/i';
$regex = "/\b(?!(" . implode('|', $months) . '|(\w[0-9][a-z])))(\w*[a-z]+[^\s]*|(\w[^\D\d\w]))/i';

$rawDate = preg_replace($regex, '', $rawDate);

Expand Down

0 comments on commit 81f7c02

Please sign in to comment.