Skip to content

Commit

Permalink
Red de Medios channels
Browse files Browse the repository at this point in the history
Removed parser infinitive loop
  • Loading branch information
extrem7 committed Jul 24, 2020
1 parent 9de6fb8 commit 555bb91
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 105 deletions.
13 changes: 12 additions & 1 deletion Modules/Frontend/Http/Controllers/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Modules\Frontend\Http\Controllers;

use App\Models\Page;
use App\Models\Rss\Country;
use App\Repositories\Interfaces\ArticleRepositoryInterface;
use App\Repositories\Interfaces\ChannelRepositoryInterface;
use App\Repositories\Interfaces\CountryRepositoryInterface;
Expand Down Expand Up @@ -63,6 +64,16 @@ public function allRss(Page $page)
return view('frontend::rss.index', compact('page'), ['orderName' => 'all-rss']);
}

public function redDeMedios(Page $page)
{
$international = $this->channelRepository->getInternational();
$chile = $this->channelRepository->getByCountry(
Country::whereSlug('chile')->orWhereIn('id', [11])->first()
);

return view("frontend::pages.red-de-medios", compact('page', 'international', 'chile'));
}

public function show(Page $pageModel)
{
$page = $pageModel;
Expand All @@ -79,7 +90,7 @@ public function show(Page $pageModel)
} elseif ($page->id === 3 || $page->slug === 'contacto') {
$view = 'contacto';
} elseif ($page->id === 4 || $page->slug === 'red-de-medios') {
$view = 'red-de-medios';
return $this->redDeMedios($page);
} elseif ($page->slug == 'all-rss') {
return $this->allRss($page);
}
Expand Down
6 changes: 6 additions & 0 deletions Modules/Frontend/Providers/FrontendServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ protected function viewComposer()
'sidebarChannel' => $channelRepository->getSidebar()
]);
});
View::composer('frontend::pages.red-de-medios', function ($view) {
$channelRepository = app(ChannelRepositoryInterface::class);
share([
'sidebarChannels' => $channelRepository->getSidebar(2)
]);
});
}

protected function getCountries()
Expand Down
1 change: 1 addition & 0 deletions Modules/Frontend/Resources/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const app = new Vue({
},
],
sidebarChannel: this.shared('sidebarChannel') || null,
sidebarChannels: this.shared('sidebarChannels') || [],
}
},
components,
Expand Down
76 changes: 20 additions & 56 deletions Modules/Frontend/Resources/views/pages/red-de-medios.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
@php /* @var $page \App\Models\Page */ @endphp
@php
/* @var $page \App\Models\Page
* @var $channel \App\Models\Rss\Channel
*/
@endphp
@extends('frontend::layouts.master')

@section('content')
Expand All @@ -21,27 +25,12 @@
<div class="title title-cyan medium-size">RED DE MEDIOS-INTERNACIONAL</div>
</div>
<div class="rss-body">
<a href="" class="rss-link title"><img
src="https://redmedial.com/wp-content/uploads/2019/06/Captura-de-pantalla-2019-06-25-a-las-10.51.27.png"
alt="">Telesur</a>
<a href="" class="rss-link title"><img
src="https://redmedial.com/wp-content/uploads/2019/06/Captura-de-pantalla-2019-06-25-a-las-10.51.27.png"
alt="">Telesur</a>
<a href="" class="rss-link title"><img
src="https://redmedial.com/wp-content/uploads/2019/06/Captura-de-pantalla-2019-06-25-a-las-10.51.27.png"
alt="">Telesur</a>
<a href="" class="rss-link title"><img
src="https://redmedial.com/wp-content/uploads/2019/06/Captura-de-pantalla-2019-06-25-a-las-10.51.27.png"
alt="">Telesur</a>
<a href="" class="rss-link title"><img
src="https://redmedial.com/wp-content/uploads/2019/06/Captura-de-pantalla-2019-06-25-a-las-10.51.27.png"
alt="">Telesur</a>
<a href="" class="rss-link title"><img
src="https://redmedial.com/wp-content/uploads/2019/06/Captura-de-pantalla-2019-06-25-a-las-10.51.27.png"
alt="">Telesur</a>
<a href="" class="rss-link title"><img
src="https://redmedial.com/wp-content/uploads/2019/06/Captura-de-pantalla-2019-06-25-a-las-10.51.27.png"
alt="">Telesur</a>
@foreach($international as $channel)
<a href="{{$channel->link}}" class="rss-link title">
<img src="{{$channel->logo}}" alt="">
{{$channel->name}}
</a>
@endforeach
</div>
</div>
</div>
Expand All @@ -52,27 +41,12 @@
</div>
<div class="rss-body">
<div class="rss-body">
<a href="" class="rss-link title"><img
src="https://redmedial.com/wp-content/uploads/2019/06/Captura-de-pantalla-2019-06-25-a-las-10.51.27.png"
alt="">Telesur</a>
<a href="" class="rss-link title"><img
src="https://redmedial.com/wp-content/uploads/2019/06/Captura-de-pantalla-2019-06-25-a-las-10.51.27.png"
alt="">Telesur</a>
<a href="" class="rss-link title"><img
src="https://redmedial.com/wp-content/uploads/2019/06/Captura-de-pantalla-2019-06-25-a-las-10.51.27.png"
alt="">Telesur</a>
<a href="" class="rss-link title"><img
src="https://redmedial.com/wp-content/uploads/2019/06/Captura-de-pantalla-2019-06-25-a-las-10.51.27.png"
alt="">Telesur</a>
<a href="" class="rss-link title"><img
src="https://redmedial.com/wp-content/uploads/2019/06/Captura-de-pantalla-2019-06-25-a-las-10.51.27.png"
alt="">Telesur</a>
<a href="" class="rss-link title"><img
src="https://redmedial.com/wp-content/uploads/2019/06/Captura-de-pantalla-2019-06-25-a-las-10.51.27.png"
alt="">Telesur</a>
<a href="" class="rss-link title"><img
src="https://redmedial.com/wp-content/uploads/2019/06/Captura-de-pantalla-2019-06-25-a-las-10.51.27.png"
alt="">Telesur</a>
@foreach($chile as $channel)
<a href="{{$channel->link}}" class="rss-link title">
<img src="{{$channel->logo}}" alt="">
{{$channel->name}}
</a>
@endforeach
</div>
</div>
</div>
Expand All @@ -81,21 +55,11 @@
</div>
<div class="col-xl-3 col-lg-4 indent-sm">
<social></social>
<rss-item v-bind="singleRss" class="mt-4"></rss-item>
<rss-item v-bind="sidebarChannels[0]" class="mt-4"></rss-item>
<div class="ads-single mt-4">
<div id="div-gpt-ad-RM2020-01" data-google-query-id="CP7R7sX6jeoCFQIZewodFYkH4Q">
<div id="google_ads_iframe_/30128925/RM2020_SINGLE/RM2020_single_01_0__container__"
style="border: 0pt none;">
<iframe id="google_ads_iframe_/30128925/RM2020_SINGLE/RM2020_single_01_0"
title="3rd party ad content"
name="google_ads_iframe_/30128925/RM2020_SINGLE/RM2020_single_01_0" width="300"
height="250" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"
srcdoc="" style="border: 0px; vertical-align: bottom;" data-google-container-id="1"
data-gtm-yt-inspected-1_27="true" data-load-complete="true"></iframe>
</div>
</div>
@include('frontend::articles.includes.banner-bottom')
</div>
<rss-item v-bind="singleRss" class="mt-4"></rss-item>
<rss-item v-bind="sidebarChannels[1]" class="mt-4"></rss-item>
</div>
</div>
Expand Down
94 changes: 49 additions & 45 deletions Modules/Parser/Services/ParserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,62 +52,60 @@ public function __construct(Command $command)
public function start(): void
{
$this->categories = Category::all('id', 'keywords');
while ($this->run) {
$channels = $this->getChannels();
if (empty($channels)) {
$this->error('No active channels');
return;
}
$channels = $this->getChannels();
if (empty($channels)) {
$this->error('No active channels');
return;
}

foreach ($channels as $channel) {
$timeStart = microtime(true);
foreach ($channels as $channel) {
$timeStart = microtime(true);

$channel->refresh();
if ($channel->status === Channel::WORKING) {
if ($channel->last_run === null || $channel->last_run->diffInMinutes() < 2) continue;
}
//$channel->refresh();
if ($channel->status === Channel::WORKING) {
if ($channel->last_run === null || $channel->last_run->diffInMinutes() < 2) continue;
}

$this->info("Start working on channel #$channel->id $channel->slug");
$this->updateLastRun($channel);
$channel->update(['status' => Channel::WORKING]);
/* @var $feed SimplePie */
$feed = Feeds::make($channel->feed, null, true);
if ($feed->error() === null) {
$this->info('Feed has been fetched');
$this->info("Start working on channel #$channel->id $channel->slug");
$this->updateLastRun($channel);
$channel->update(['status' => Channel::WORKING]);
/* @var $feed SimplePie */
$feed = Feeds::make($channel->feed, null, true);
if ($feed->error() === null) {
$this->info('Feed has been fetched');

$items = $this->filterNewItems($feed, $channel);
$items = $this->filterNewItems($feed, $channel);

$count = 0;
$count = 0;

DB::transaction(function () use ($items, $channel, &$count) {
foreach ($items as $item) {
$this->html = null;
DB::transaction(function () use ($items, $channel, &$count) {
foreach ($items as $item) {
$this->html = null;

if ($post = $this->createItem($item, $channel)) {
$count++;
$this->attachImage($item, $post, $channel->use_og);
$this->attachToCategories($item, $post);
}
if ($post = $this->createItem($item, $channel)) {
$count++;
$this->attachImage($item, $post, $channel->use_og);
$this->attachToCategories($item, $post);
}
});
}
});

$this->info("Created $count items");
$this->info("Created $count items");

if (in_array($channel->id, setting('international_medias'))) {
Cacher::channelsInternational();
}
if ($country = $channel->country) {
if ($count > 0) Cacher::countyByCode($country->code);
}
} else {
$this->error('SimplePie returned error: ' . $feed->error());
if (in_array($channel->id, setting('international_medias'))) {
Cacher::channelsInternational();
}

$timeEnd = microtime(true);
$executionTime = round($timeEnd - $timeStart, 1);
$this->info("End working on channel #$channel->id $channel->slug. Total Execution Time: {$executionTime}s");
$channel->update(['status' => Channel::IDLE]);
if ($country = $channel->country) {
if ($count > 0) Cacher::countyByCode($country->code);
}
} else {
$this->error('SimplePie returned error: ' . $feed->error());
}

$timeEnd = microtime(true);
$executionTime = round($timeEnd - $timeStart, 1);
$this->info("End working on channel #$channel->id $channel->slug. Total Execution Time: {$executionTime}s");
$channel->update(['status' => Channel::IDLE]);
}
}

Expand Down Expand Up @@ -138,7 +136,13 @@ protected function createItem(SimplePie_Item $item, Channel $channel): ?Post
$date = Carbon::create($item->get_date());

if ($channel->use_og | $channel->use_fulltext) {
$this->html = Http::get($item->get_link());
try {
$this->html = Http::get($item->get_link());
} catch (Exception $e) {
$this->error("Error while trying to get post origin:\n"
. $e->getFile() . ' line: ' . $e->getLine() . "\n"
. $e->getMessage());
}
if ($channel->use_fulltext) {
try {
$content = $this->parseFullContent($item) ?? $content;
Expand Down
5 changes: 3 additions & 2 deletions app/Repositories/ChannelRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ public function getByCountry(Country $country): Collection
);
}

public function getSidebar(): Channel
/* @return Channel[] */
public function getSidebar(int $number = 1): iterable
{
$international = $this->getInternational();
return $international->random();
return $international->random($number);
}

public function transformChannels(Collection $channels)
Expand Down
3 changes: 2 additions & 1 deletion app/Repositories/Interfaces/ChannelRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ public function getInternational(): Collection;

public function getByCountry(Country $country);

public function getSidebar(): Channel;
/* @return Channel[] */
public function getSidebar(int $number = 1): iterable;
}

0 comments on commit 555bb91

Please sign in to comment.