Add adhadhu support

This commit is contained in:
Mohamed jinas
2024-01-07 16:58:18 +05:00
parent 1cc86fbbde
commit 46ead16ef8
11 changed files with 497 additions and 6 deletions

View File

@@ -2,11 +2,10 @@
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/app" isTestSource="false" packagePrefix="App\" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" packagePrefix="Tests\" />
<sourceFolder url="file://$MODULE_DIR$/tests/Unit" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/tests/Feature" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/database/factories" isTestSource="false" packagePrefix="Database\Factories\" />
<sourceFolder url="file://$MODULE_DIR$/database/seeders" isTestSource="false" packagePrefix="Database\Seeders\" />
<excludeFolder url="file://$MODULE_DIR$/vendor/asm89/stack-cors" />
<excludeFolder url="file://$MODULE_DIR$/vendor/brick/math" />
<excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
@@ -116,6 +115,49 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/vlucas/phpdotenv" />
<excludeFolder url="file://$MODULE_DIR$/vendor/voku/portable-ascii" />
<excludeFolder url="file://$MODULE_DIR$/vendor/webmozart/assert" />
<excludeFolder url="file://$MODULE_DIR$/storage/app" />
<excludeFolder url="file://$MODULE_DIR$/storage/debugbar" />
<excludeFolder url="file://$MODULE_DIR$/storage/framework" />
<excludeFolder url="file://$MODULE_DIR$/vendor/bacon/bacon-qr-code" />
<excludeFolder url="file://$MODULE_DIR$/vendor/barryvdh/laravel-debugbar" />
<excludeFolder url="file://$MODULE_DIR$/vendor/dasprid/enum" />
<excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/cache" />
<excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/dbal" />
<excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/deprecations" />
<excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/event-manager" />
<excludeFolder url="file://$MODULE_DIR$/vendor/firebase/php-jwt" />
<excludeFolder url="file://$MODULE_DIR$/vendor/google/apiclient" />
<excludeFolder url="file://$MODULE_DIR$/vendor/google/apiclient-services" />
<excludeFolder url="file://$MODULE_DIR$/vendor/google/auth" />
<excludeFolder url="file://$MODULE_DIR$/vendor/graham-campbell/result-type" />
<excludeFolder url="file://$MODULE_DIR$/vendor/jaybizzle/crawler-detect" />
<excludeFolder url="file://$MODULE_DIR$/vendor/jenssegers/agent" />
<excludeFolder url="file://$MODULE_DIR$/vendor/jinas/moosun" />
<excludeFolder url="file://$MODULE_DIR$/vendor/laravel/fortify" />
<excludeFolder url="file://$MODULE_DIR$/vendor/laravel/jetstream" />
<excludeFolder url="file://$MODULE_DIR$/vendor/laravel/sail" />
<excludeFolder url="file://$MODULE_DIR$/vendor/laravel/sanctum" />
<excludeFolder url="file://$MODULE_DIR$/vendor/league/mime-type-detection" />
<excludeFolder url="file://$MODULE_DIR$/vendor/livewire/livewire" />
<excludeFolder url="file://$MODULE_DIR$/vendor/maximebf/debugbar" />
<excludeFolder url="file://$MODULE_DIR$/vendor/mobiledetect/mobiledetectlib" />
<excludeFolder url="file://$MODULE_DIR$/vendor/paragonie/constant_time_encoding" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpseclib/phpseclib" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-invoker" />
<excludeFolder url="file://$MODULE_DIR$/vendor/pragmarx/google2fa" />
<excludeFolder url="file://$MODULE_DIR$/vendor/predis/predis" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/cache" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/http-client" />
<excludeFolder url="file://$MODULE_DIR$/vendor/realrashid/sweet-alert" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/cli-parser" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/code-unit" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/complexity" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/lines-of-code" />
<excludeFolder url="file://$MODULE_DIR$/vendor/spatie/laravel-analytics" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/cache" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/cache-contracts" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/debug" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/var-exporter" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />

121
.idea/blade.xml generated Normal file
View File

@@ -0,0 +1,121 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="BladeInjectionConfiguration" default="false">
<directives>
<data directive="@append" />
<data directive="@auth" injection="true" prefix="&lt;?php&#10;if(auth()-&gt;guard(" suffix=")-&gt;check()): ?&gt;" />
<data directive="@aware" injection="true" prefix="&lt;?php&#10;$__aware_exp = " suffix="?&gt;" />
<data directive="@break" injection="true" prefix="&lt;?php&#10;if(" suffix=") break; ?&gt;" />
<data directive="@can" injection="true" prefix="&lt;?php&#10;if (app(\Illuminate\Contracts\Auth\Access\Gate::class)-&gt;check(" suffix=")): ?&gt;" />
<data directive="@canany" injection="true" prefix="&lt;?php&#10;if (app(\Illuminate\Contracts\Auth\Access\Gate::class)-&gt;any(" suffix=")): ?&gt;" />
<data directive="@cannot" injection="true" prefix="&lt;?php&#10;if (app(\Illuminate\Contracts\Auth\Access\Gate::class)-&gt;denies(" suffix=")): ?&gt;" />
<data directive="@case" injection="true" prefix="&lt;?php&#10;case (" suffix="): ?&gt;" />
<data directive="@checked" injection="true" prefix="&lt;?php&#10;if(" suffix="): echo 'checked'; endif; ?&gt;" />
<data directive="@choice" injection="true" prefix="&lt;?php&#10;echo app('translator')-&gt;choice(" suffix="); ?&gt;" />
<data directive="@class" injection="true" prefix="class=&quot;&lt;?php&#10;echo \Illuminate\Support\Arr::toCssClasses(" suffix=") ?&gt;&quot;" />
<data directive="@component" injection="true" prefix="&lt;?php&#10;$__env-&gt;startComponent(" suffix="); ?&gt;" />
<data directive="@componentfirst" injection="true" prefix="&lt;?php&#10;$__env-&gt;startComponentFirst(" suffix="); ?&gt;" />
<data directive="@continue" injection="true" prefix="&lt;?php&#10;if(" suffix=") continue; ?&gt;" />
<data directive="@csrf" />
<data directive="@dd" injection="true" prefix="&lt;?php&#10;dd(" suffix="); ?&gt;" />
<data directive="@default" />
<data directive="@disabled" injection="true" prefix="&lt;?php&#10;if(" suffix="): echo 'disabled'; endif; ?&gt;" />
<data directive="@dump" injection="true" prefix="&lt;?php&#10;dump(" suffix="); ?&gt;" />
<data directive="@each" injection="true" prefix="&lt;?php&#10;echo $__env-&gt;renderEach(" suffix="); ?&gt;" />
<data directive="@else" />
<data directive="@elseauth" injection="true" prefix="&lt;?php&#10;elseif(auth()-&gt;guard(" suffix=")-&gt;check()): ?&gt;" />
<data directive="@elsecan" injection="true" prefix="&lt;?php&#10;elseif (app(\Illuminate\Contracts\Auth\Access\Gate::class)-&gt;check(" suffix=")): ?&gt;" />
<data directive="@elsecanany" injection="true" prefix="&lt;?php&#10;elseif (app(\Illuminate\Contracts\Auth\Access\Gate::class)-&gt;any(" suffix=")): ?&gt;" />
<data directive="@elsecannot" injection="true" prefix="&lt;?php&#10;elseif (app(\Illuminate\Contracts\Auth\Access\Gate::class)-&gt;denies(" suffix=")): ?&gt;" />
<data directive="@elseguest" injection="true" prefix="&lt;?php&#10;elseif(auth()-&gt;guard(" suffix=")-&gt;guest()): ?&gt;" />
<data directive="@elseif" injection="true" prefix="&lt;?php&#10;elseif(" suffix="): ?&gt;" />
<data directive="@empty" injection="true" prefix="&lt;?php&#10;if(empty(" suffix=")): ?&gt;" />
<data directive="@endauth" />
<data directive="@endcan" />
<data directive="@endcanany" />
<data directive="@endcannot" />
<data directive="@endcomponent" />
<data directive="@endcomponentClass" />
<data directive="@endcomponentfirst" />
<data directive="@endempty" />
<data directive="@endenv" />
<data directive="@enderror" />
<data directive="@endfor" />
<data directive="@endforeach" />
<data directive="@endforelse" />
<data directive="@endfragment" />
<data directive="@endguest" />
<data directive="@endif" />
<data directive="@endisset" />
<data directive="@endlang" />
<data directive="@endonce" />
<data directive="@endphp" />
<data directive="@endprepend" />
<data directive="@endprependonce" />
<data directive="@endproduction" />
<data directive="@endpush" />
<data directive="@endpushif" />
<data directive="@endpushonce" />
<data directive="@endsection" />
<data directive="@endslot" />
<data directive="@endswitch" />
<data directive="@endunless" />
<data directive="@endverbatim" />
<data directive="@endwhile" />
<data directive="@entangle" injection="true" prefix="&lt;?php \print_r(" suffix="); ?&gt;" />
<data directive="@env" injection="true" prefix="&lt;?php&#10;if(app()-&gt;environment(" suffix=")): ?&gt;" />
<data directive="@error" injection="true" prefix="&lt;?php&#10;$__errorArgs = [" suffix="];&#10;$__bag = $errors-&gt;getBag($__errorArgs[1] ?? 'default');&#10;if ($__bag-&gt;has($__errorArgs[0])) :&#10;if (isset($message)) { $__messageOriginal = $message; }&#10;$message = $__bag-&gt;first($__errorArgs[0]); ?&gt;" />
<data directive="@extends" injection="true" prefix="&lt;?php&#10;echo $__env-&gt;make(" suffix=", \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))-&gt;render(); ?&gt;" />
<data directive="@extendsfirst" injection="true" prefix="&lt;?php&#10;echo $__env-&gt;first(" suffix=", \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))-&gt;render(); ?&gt;" />
<data directive="@for" injection="true" prefix="&lt;?php&#10;for(" suffix="): ?&gt;" />
<data directive="@foreach" injection="true" prefix="&lt;?php&#10;foreach(" suffix="): ?&gt;" />
<data directive="@forelse" injection="true" prefix="&lt;?php&#10;foreach(" suffix="): ?&gt;" />
<data directive="@fragment" injection="true" prefix="&lt;?php&#10;$__env-&gt;startFragment(" suffix="); ?&gt;" />
<data directive="@guest" injection="true" prefix="&lt;?php&#10;if(auth()-&gt;guard(" suffix=")-&gt;guest()): ?&gt;" />
<data directive="@hasSection" injection="true" prefix="&lt;?php&#10;if (! empty(trim($__env-&gt;yieldContent(" suffix=")))): ?&gt;" />
<data directive="@if" injection="true" prefix="&lt;?php&#10;if(" suffix="): ?&gt;" />
<data directive="@include" injection="true" prefix="&lt;?php&#10;echo $__env-&gt;make(" suffix=", \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))-&gt;render(); ?&gt;" />
<data directive="@includeFirst" injection="true" prefix="&lt;?php&#10;echo $__env-&gt;first(" suffix=", \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))-&gt;render(); ?&gt;" />
<data directive="@includeUnless" injection="true" prefix="&lt;?php&#10;echo $__env-&gt;renderUnless(" suffix=", \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path'])); ?&gt;" />
<data directive="@includeWhen" injection="true" prefix="&lt;?php&#10;echo $__env-&gt;renderWhen(" suffix=", \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path'])); ?&gt;" />
<data directive="@isset" injection="true" prefix="&lt;?php&#10;if(isset(" suffix=")): ?&gt;" />
<data directive="@js" injection="true" prefix="&lt;?php&#10;echo \Illuminate\Support\Js::from(" suffix=")-&gt;toHtml() ?&gt;" />
<data directive="@json" injection="true" prefix="&lt;?php&#10;echo json_encode(" suffix=") ?&gt;" />
<data directive="@lang" injection="true" prefix="&lt;?php&#10;echo app('translator')-&gt;get(" suffix="); ?&gt;" />
<data directive="@livewire" injection="true" prefix="&lt;?php \Livewire\Livewire::mount(" suffix="); ?&gt;" />
<data directive="@livewireScripts" />
<data directive="@livewireStyles" />
<data directive="@method" injection="true" prefix="&lt;?php&#10;echo method_field(" suffix="); ?&gt;" />
<data directive="@once" />
<data directive="@overwrite" />
<data directive="@parent" />
<data directive="@php" injection="true" prefix="&lt;?php&#10;(" suffix="); ?&gt;" />
<data directive="@prepend" injection="true" prefix="&lt;?php&#10;$__env-&gt;startPrepend(" suffix="); ?&gt;" />
<data directive="@prependonce" injection="true" prefix="&lt;?php&#10;$___phpstorm_prepend_once_params = [" suffix="]; if (! $__env-&gt;hasRenderedOnce($___phpstorm_prepend_once_params[1])): $__env-&gt;markAsRenderedOnce($___phpstorm_prepend_once_params); $__env-&gt;startPrepend($___phpstorm_prepend_once_params[0]); ?&gt;" />
<data directive="@production" />
<data directive="@props" injection="true" prefix="&lt;?php $attributes = $attributes-&gt;exceptProps(" suffix="); ?&gt;" />
<data directive="@push" injection="true" prefix="&lt;?php&#10;$__env-&gt;startPush(" suffix="); ?&gt;" />
<data directive="@pushif" injection="true" prefix="&lt;?php&#10;$__pushif_args = explode(','," suffix=", 2); if({$__pushif_args[0]}): $__env-&gt;startPush({$__pushif_args[1]}); ?&gt;" />
<data directive="@pushonce" injection="true" prefix="&lt;?php&#10;$__php_storm_push_once_params = [" suffix="]; if (!$__env-&gt;hasRenderedOnce($__php_storm_push_once_params[1])): $__env-&gt;markAsRenderedOnce($__php_storm_push_once_params[1]); $__env-&gt;startPush($__php_storm_push_once_params[0]); ?&gt;" />
<data directive="@readonly" injection="true" prefix="&lt;?php&#10;if(" suffix="): echo 'readonly'; endif; ?&gt;" />
<data directive="@required" injection="true" prefix="&lt;?php&#10;if(" suffix="): echo 'required'; endif; ?&gt;" />
<data directive="@section" injection="true" prefix="&lt;?php&#10;$__env-&gt;startSection(" suffix="); ?&gt;" />
<data directive="@sectionMissing" injection="true" prefix="&lt;?php&#10;if (empty(trim($__env-&gt;yieldContent(" suffix=")))): ?&gt;" />
<data directive="@selected" injection="true" prefix="&lt;?php&#10;if(" suffix="): echo 'selected'; endif; ?&gt;" />
<data directive="@show" />
<data directive="@slot" injection="true" prefix="&lt;?php&#10;$__env-&gt;slot(" suffix="); ?&gt;" />
<data directive="@stack" injection="true" prefix="&lt;?php&#10;echo $__env-&gt;yieldPushContent(" suffix="); ?&gt;" />
<data directive="@stop" />
<data directive="@style" injection="true" prefix="style=&quot;&lt;?php&#10;echo \Illuminate\Support\Arr::toCssStyles(" suffix=") ?&gt;&quot;" />
<data directive="@switch" injection="true" prefix="&lt;?php&#10;switch(" suffix="): ?&gt;" />
<data directive="@this" />
<data directive="@unless" injection="true" prefix="&lt;?php&#10;if (! (" suffix=")): ?&gt;" />
<data directive="@unset" injection="true" prefix="&lt;?php&#10;unset(" suffix="); ?&gt;" />
<data directive="@verbatim" />
<data directive="@vite" injection="true" prefix="&lt;?php&#10;$__vite_arguments = " suffix=" ?? '()'; echo app(Illuminate\Foundation\Vite::class){$__vite_arguments}; ?&gt;" />
<data directive="@vitereactrefresh" />
<data directive="@while" injection="true" prefix="&lt;?php&#10;while(" suffix="): ?&gt;" />
<data directive="@yield" injection="true" prefix="&lt;?php&#10;echo $__env-&gt;yieldContent(" suffix="); ?&gt;" />
</directives>
</component>
</project>

19
.idea/laravel-idea.xml generated Normal file
View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="LaravelIdeaMainSettings">
<option name="codeGeneration">
<LaravelCodeGeneration>
<option name="generationStringSettings">
<map>
<entry key="createEloquentScope:inModuleNamespace" value="Models\Scopes" />
<entry key="createEloquentScope:namespace" value="Models\Scopes" />
<entry key="createModel:inModuleNamespace" value="Models" />
<entry key="createModel:namespace" value="Models" />
</map>
</option>
</LaravelCodeGeneration>
</option>
<option name="frameworkFound" value="true" />
<option name="userClassName" value="\AppModels\User" />
</component>
</project>

58
.idea/php.xml generated
View File

@@ -1,5 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MessDetectorOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PHPCSFixerOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PHPCodeSnifferOptionsConfiguration">
<option name="highlightLevel" value="WARNING" />
<option name="transferred" value="true" />
</component>
<component name="PhpIncludePathManager">
<include_path>
<path value="$PROJECT_DIR$/vendor/symfony/mime" />
@@ -111,12 +121,58 @@
<path value="$PROJECT_DIR$/vendor/symfony/console" />
<path value="$PROJECT_DIR$/vendor/nikic/php-parser" />
<path value="$PROJECT_DIR$/vendor/symfony/routing" />
<path value="$PROJECT_DIR$/vendor/maximebf/debugbar" />
<path value="$PROJECT_DIR$/vendor/pragmarx/google2fa" />
<path value="$PROJECT_DIR$/vendor/jaybizzle/crawler-detect" />
<path value="$PROJECT_DIR$/vendor/paragonie/constant_time_encoding" />
<path value="$PROJECT_DIR$/vendor/doctrine/dbal" />
<path value="$PROJECT_DIR$/vendor/doctrine/cache" />
<path value="$PROJECT_DIR$/vendor/firebase/php-jwt" />
<path value="$PROJECT_DIR$/vendor/livewire/livewire" />
<path value="$PROJECT_DIR$/vendor/doctrine/deprecations" />
<path value="$PROJECT_DIR$/vendor/doctrine/event-manager" />
<path value="$PROJECT_DIR$/vendor/barryvdh/laravel-debugbar" />
<path value="$PROJECT_DIR$/vendor/symfony/cache-contracts" />
<path value="$PROJECT_DIR$/vendor/symfony/cache" />
<path value="$PROJECT_DIR$/vendor/symfony/var-exporter" />
<path value="$PROJECT_DIR$/vendor/symfony/debug" />
<path value="$PROJECT_DIR$/vendor/laravel/fortify" />
<path value="$PROJECT_DIR$/vendor/laravel/sanctum" />
<path value="$PROJECT_DIR$/vendor/laravel/jetstream" />
<path value="$PROJECT_DIR$/vendor/phpunit/php-invoker" />
<path value="$PROJECT_DIR$/vendor/predis/predis" />
<path value="$PROJECT_DIR$/vendor/spatie/laravel-analytics" />
<path value="$PROJECT_DIR$/vendor/dasprid/enum" />
<path value="$PROJECT_DIR$/vendor/laravel/sail" />
<path value="$PROJECT_DIR$/vendor/google/apiclient-services" />
<path value="$PROJECT_DIR$/vendor/google/auth" />
<path value="$PROJECT_DIR$/vendor/google/apiclient" />
<path value="$PROJECT_DIR$/vendor/league/mime-type-detection" />
<path value="$PROJECT_DIR$/vendor/psr/http-client" />
<path value="$PROJECT_DIR$/vendor/psr/cache" />
<path value="$PROJECT_DIR$/vendor/bacon/bacon-qr-code" />
<path value="$PROJECT_DIR$/vendor/jinas/moosun" />
<path value="$PROJECT_DIR$/vendor/graham-campbell/result-type" />
<path value="$PROJECT_DIR$/vendor/sebastian/complexity" />
<path value="$PROJECT_DIR$/vendor/jenssegers/agent" />
<path value="$PROJECT_DIR$/vendor/realrashid/sweet-alert" />
<path value="$PROJECT_DIR$/vendor/mobiledetect/mobiledetectlib" />
<path value="$PROJECT_DIR$/vendor/phpseclib/phpseclib" />
<path value="$PROJECT_DIR$/vendor/sebastian/lines-of-code" />
<path value="$PROJECT_DIR$/vendor/sebastian/code-unit" />
<path value="$PROJECT_DIR$/vendor/sebastian/cli-parser" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="7.2" />
<component name="PhpProjectSharedConfiguration" php_language_level="7.4" />
<component name="PhpStanOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PhpUnit">
<phpunit_settings>
<PhpUnitSettings configuration_file_path="$PROJECT_DIR$/phpunit.xml" custom_loader_path="$PROJECT_DIR$/vendor/autoload.php" use_configuration_file="true" />
</phpunit_settings>
</component>
<component name="PsalmOptionsConfiguration">
<option name="transferred" value="true" />
</component>
</project>

3
.idea/phpunit.xml generated
View File

@@ -3,8 +3,7 @@
<component name="PHPUnit">
<option name="directories">
<list>
<option value="$PROJECT_DIR$/tests/Unit" />
<option value="$PROJECT_DIR$/tests/Feature" />
<option value="$PROJECT_DIR$/tests" />
</list>
</option>
</component>

View File

@@ -0,0 +1,73 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Source;
use App\Services\AdhadhuService;
use App\Topic;
use Illuminate\Support\Carbon;
class ScrapeAdhadhuCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'scrape:adhadhu';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Scrape Adhadhu';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$source = Source::where('slug', 'adhadhu')->first();
$articles = (new AdhadhuService)->scrape();
foreach ($articles as $article) {
$articleModel = $source->articles()->updateOrCreate(
["guid" => $article["guid"]],
[
"title" => $article["title"],
"url" => $article["url"],
"author" => $article["author"],
"featured_image" => $article["image"],
"body" => $article["content"],
"published_date" => $article["date"],
"meta" => [
"title" => $article["og_title"]
]
]
);
collect($article["topics"])->each(function ($topic) use ($articleModel) {
$topicModel = Topic::firstOrCreate(["slug" => $topic["slug"]], ["name" => $topic["name"]]);
$topicModel->articles()->syncWithoutDetaching($articleModel);
});
}
return 0;
}
}

View File

@@ -101,8 +101,13 @@ class Kernel extends ConsoleKernel
$schedule->command('scrape:dhiyares')->everyFiveMinutes()
->runInBackground()
->pingOnSuccess(config('app.url') . "/api/ping/dhiyares");
$schedule->command('scrape:adhadhu')->everyFiveMinutes()
->runInBackground()
->pingOnSuccess(config('app.url') . "/api/ping/adhadhu");
}
/**
* Register the commands for the application.
*

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Services;
use App\Services\Feeds\AdhadhuFeed;
use App\Services\Scrapers\AdhadhuScraper;
class AdhadhuService extends Client
{
/**
* Scrap all the rss articles from Adhadhu
*
* @return array
*/
public function scrape(): array
{
$articles = (new AdhadhuFeed)->get();
$articleItems = [];
foreach ($articles as $article) {
$scrapedData = (new AdhadhuScraper)->extract($article["link"], $article["date"]);
if ($scrapedData !== null) {
$articleItems[] = $scrapedData;
}
}
return $articleItems;
}
}

View File

@@ -0,0 +1,82 @@
<?php
namespace App\Services\Feeds;
use Goutte\Client;
use Illuminate\Support\Carbon;
class AdhadhuFeed implements Feed
{
protected $client;
public function __construct()
{
$this->client = new Client();
}
/**
* Return the latest articles from Adhadhu
*
* @return array
*/
public function get(): array
{
$crawler = $this->client->request('GET', "https://adhadhu.com/category/News");
$feeds = [];
// Parse the news articles
$crawler->filter('div.category-news div.row div.list a.item, div.category-news div.row div.list a')->each(function ($node) use (&$feeds) {
// Extract the details of each article
$title = $node->filter('h4')->text();
$link = $node->attr('href');
$timeText = $node->filter('p.font-11')->text();
// Extract the time and convert it to a Carbon instance
$date = $this->extractDate($timeText);
$feeds[] = [
"title" => trim($title),
"link" => "https://adhadhu.com" . $link,
"date" => $date
];
});
return $feeds;
}
/**
* Extract and format the date from the text
*
* @param string $timeText
* @return string
*/
protected function extractDate($timeText)
{
// A simple regex to extract numbers and time units (e.g., "minutes", "hours")
if (preg_match('/(\d+)\s*(minute|hour|day|second)s?/', $timeText, $matches)) {
$number = $matches[1];
$unit = $matches[2];
// Use Carbon's sub method to subtract the time
switch ($unit) {
case 'minute':
return Carbon::now()->subMinutes($number)->format('Y-m-d H:i:s');
case 'hour':
return Carbon::now()->subHours($number)->format('Y-m-d H:i:s');
case 'day':
return Carbon::now()->subDays($number)->format('Y-m-d H:i:s');
case 'second':
return Carbon::now()->subSeconds($number)->format('Y-m-d H:i:s');
default:
// Handle unexpected time unit
return Carbon::now()->format('Y-m-d H:i:s');
}
} else {
// Default to current time if parsing fails
return Carbon::now()->format('Y-m-d H:i:s');
}
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace App\Services\Scrapers;
use Goutte\Client;
use Illuminate\Support\Str;
class AdhadhuScraper
{
protected $client;
protected $title;
protected $content;
protected $image;
protected $topics = [];
protected $author;
public function __construct()
{
$this->client = new Client;
}
public function extract($url, $date = null)
{
$crawler = $this->client->request('GET', $url);
// Extract title
$this->title = $crawler->filter('h1.font-52')->first()->text();
// Extract image URL
$this->image = $crawler->filter('img.img-fluid.hero-img')->first()->attr('src');
// Extract author name
$this->author = $crawler->filter('.MuiAvatar-circle img')->first()->attr('alt');
// Extract content
$crawler->filter('.body > p')->each(function ($node) {
$this->content[] = $node->text();
});
// Extract topics (tags)
$crawler->filter('a[href^="/tags/"]')->each(function ($node) {
$href = $node->attr('href');
$slug = basename($href); // Extracts the last segment of the URL
$this->topics[] = [
"name" => trim($node->filter('.tag')->first()->text()),
"slug" => Str::slug($slug)
];
});
return [
'source' => 'Adhadhu',
'title' => $this->title,
'og_title' => $crawler->filter('meta[property*="og:title"]')->first()->attr('content'),
'image' => $this->image,
'content' => $this->content,
'url' => $url,
'date' => $date,
'guid' => str_replace("https://adhadhu.com/news/","",$url),
'author' => $this->author,
'topics' => $this->topics
];
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB