Skip to content

Commit

Permalink
Merge pull request #37 from richard-muvirimi/development
Browse files Browse the repository at this point in the history
Revert use of laravel squish
  • Loading branch information
richard-muvirimi committed Apr 7, 2024
2 parents d5ff52f + d13d0a0 commit ca38670
Show file tree
Hide file tree
Showing 7 changed files with 520 additions and 473 deletions.
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
APP_AUTHOR=
APP_AUTHOR="Richard Muvirimi"

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
Expand Down Expand Up @@ -67,3 +67,6 @@ USER_AGENT="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Geck
SCRAPPY_TOKEN=
SCRAPPY_SERVER="https://scrappy.tyganeutronics.com"
SCRAPPY_TIMEOUT=110

WWWGROUP=1000
WWWUSER=1000
File renamed without changes.
18 changes: 9 additions & 9 deletions app/Traits/ScrapesRates.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use App\Models\Rate;
use Carbon\CarbonInterval;
use Carbon\CarbonTimeZone;
use DateTime;
use Error;
use Exception;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
Expand Down Expand Up @@ -175,7 +177,7 @@ private function isXpath(string $selector): bool
/**
* Convert number to an int
*
* @throws Exception
* @throws Exception
*/
private function cleanRate(string $value, string $locale): float
{
Expand Down Expand Up @@ -203,7 +205,7 @@ private function cleanRate(string $value, string $locale): float
$numbers = implode(' ', $numbered);

$fmt = new NumberFormatter($locale, NumberFormatter::DECIMAL);
$numbers = $fmt->parse($numbers);
$numbers = $fmt->parse($numbers) ?: 0;

//split by non-numeric
$figures = preg_split('/[^0-9,.]/', $numbers, -1, PREG_SPLIT_NO_EMPTY);
Expand Down Expand Up @@ -261,17 +263,15 @@ private function clean(string $value): string
/**
* Remove all non-alphanumeric characters except spaces
*/
$value = implode(' ', array_map(function (string $word): string {
return implode(' ', array_map(function (string $word): string {
return trim($word, '-,:;\'"()[]{}<>!?*');
}, explode(' ', $value)));

return Str::squish($value);
}

/**
* Parse a date from raw text
*
* @throws Exception
* @throws Exception
*/
private function cleanDate(string $value, string $timezone): Carbon
{
Expand All @@ -286,9 +286,9 @@ private function cleanDate(string $value, string $timezone): Carbon
$parsed = $parser->parse($rawDate, true);

if ($parsed !== false) {
return Carbon::parse($parsed)->shiftTimezone($timezone);
return Carbon::parse($parsed, CarbonTimeZone::create($timezone))->shiftTimezone('UTC');
}
} catch (Exception) {
} catch (Exception|Error) {
//do nothing
}

Expand Down Expand Up @@ -327,6 +327,6 @@ private function cleanDate(string $value, string $timezone): Carbon
/**
* Parse the date
*/
return Carbon::parse($rawDate)->shiftTimezone($timezone);
return Carbon::parse($rawDate, CarbonTimeZone::create($timezone))->shiftTimezone('UTC');
}
}
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@
"require-dev": {
"fakerphp/faker": "^1.23",
"laravel/pint": "^1.13",
"laravel/sail": "^1.26",
"laravel/sail": "^1.27",
"mikey179/vfsstream": "^1.6",
"mockery/mockery": "^1.6",
"nunomaduro/collision": "^7.10",
"phpunit/phpunit": "^10.4",
"spatie/laravel-ignition": "^2.3"
"phpunit/phpunit": "^10.5",
"spatie/laravel-ignition": "^2.4"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit ca38670

Please sign in to comment.