Add (scraper)

Update (ai): integrate scraper
This commit is contained in:
2023-09-25 19:39:13 +08:00
parent b6f36e3ccd
commit c53918d03b
7 changed files with 262 additions and 45 deletions

View File

@@ -5,10 +5,12 @@
use App\Jobs\GenerateArticleJob;
use App\Jobs\Tasks\GetNewsSerpTask;
use App\Jobs\Tasks\ParseNewsSerpDomainsTask;
use App\Jobs\Tasks\ScrapeUrlBodyTask;
use App\Models\Category;
use App\Models\NewsSerpResult;
use App\Models\Post;
use App\Models\SerpUrl;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Route;
/*
@@ -22,40 +24,82 @@
|
*/
Route::get('/news_serp', function () {
$category = Category::find(2);
Route::get('/step-1', function (Request $request) {
$category = Category::find($request->input('id'));
$news_serp_result = GetNewsSerpTask::handle($category, 'US');
dd($news_serp_result);
dd($news_serp_result->id);
});
Route::get('/news_serp_parse', function () {
$news_serp_result = NewsSerpResult::find(3);
$serp_urls = ParseNewsSerpDomainsTask::handle($news_serp_result);
dd($serp_urls);
Route::get('/step-2', function (Request $request) {
$news_serp_result = NewsSerpResult::find($request->input('id', null));
if (is_null($news_serp_result))
{
abort(404);
}
$task = ParseNewsSerpDomainsTask::handle($news_serp_result);
if ($task)
{
$serp_url = SerpUrl::latest()->first();
dd($serp_url->id);
}
});
Route::get('/write_article', function () {
$serp_url = SerpUrl::find(2);
Route::get('/step-3', function (Request $request) {
$serp_url = SerpUrl::find($request->input('id', null));
if (is_null($serp_url))
{
abort(404);
}
$task = GenerateArticleJob::dispatch($serp_url)->onQueue('default')->onConnection('default');
dd($task);
});
Route::get('/gen_article_image', function () {
Route::get('/step-4', function () {
$post = Post::whereNull('featured_image')->where('status', 'draft')->first();
$task = GenerateArticleFeaturedImageJob::dispatch($post)->onQueue('default')->onConnection('default');
dd($task);
});
Route::get('/suggest_titles', function () {
$results = OpenAI::suggestArticleTitles("It's 2019s Electric: How Fisker Is Reinventing The Automotive Industry And \nExpanding Its Business", "Fisker's approach to building electric vehicles is deeply intertwined with \nits overall business philosophy: use less, use better,...s", 1);
dd($results);
Route::get('/step-5', function (Request $request) {
$post = Post::find($request->input('id'));
if (is_null($post))
{
return abort(404);
}
$post->published_at = now();
dd($post->save());
});
Route::get('/write_article_raw', function () {
$results = OpenAI::writeArticle("Fisker's Vision for the Future of Electric Cars", "Explore Fisker's innovative vision for the future of electric cars and its impact on the automotive industry.", 'Article', 500, 800);
dd($results);
// Route::get('/suggest_titles', function () {
// $results = OpenAI::suggestArticleTitles("It's 2019s Electric: How Fisker Is Reinventing The Automotive Industry And \nExpanding Its Business", "Fisker's approach to building electric vehicles is deeply intertwined with \nits overall business philosophy: use less, use better,...s", 1);
// dd($results);
// });
// Route::get('/write_article_raw', function () {
// $results = OpenAI::writeArticle("Fisker's Vision for the Future of Electric Cars", "Explore Fisker's innovative vision for the future of electric cars and its impact on the automotive industry.", 'Article', 500, 800);
// dd($results);
// });
Route::get('proxy_test', function() {
$url = 'https://www.cnbc.com/2023/09/24/this-southern-city-is-the-no-1-place-to-start-your-own-business.html';
$task = ScrapeUrlBodyTask::handle($url);
dd($task);
});
// Route::get('/image_gen', function() {