/** * Execute the console command. * * @return mixed */ public function handle() { $eventsIn3Days = $this->event->getEventsWithin3Days(); foreach ($eventsIn3Days as $event) { $time = $this->getEventTime($event->time); $this->info('Event: ' . $event['name'] . ' at ' . $time->format('jS \\o\\f M \\a\\t h:ia')); $content = $event['name'] . ' at ' . $time->format('jS \\o\\f M \\a\\t h:ia') . ' #memtech ' . $event['event_url']; $tweet = $this->reformatStatus($content, $event, $time->format('jS \\o\\f M \\a\\t h:ia')); $tweet_at = $time->subDays(3)->subHours(10)->setTimezone('America/Chicago'); // check if we already have a pending tweet $existing = Tweet::where('event_id', $event['event_id'])->where('days_before', 3)->first(); if (is_null($existing)) { $this->tweet->create(['content' => $tweet, 'tweet_at' => $tweet_at, 'sent' => false, 'event_id' => $event['event_id'], 'days_before' => 3]); } } $eventsIn24hours = $this->event->getEventsWithin24Hours(); foreach ($eventsIn24hours as $event) { $time = $this->getEventTime($event->time); $this->info('Event: ' . $event['name'] . ' at ' . $time->format('jS \\o\\f M \\a\\t h:ia')); $content = $event['name'] . ' at ' . $time->format('jS \\o\\f M \\a\\t h:ia') . ' #memtech ' . $event['event_url']; $tweet = $this->reformatStatus($content, $event, $time->format('jS \\o\\f M \\a\\t h:ia')); $tweet_at = $time->subHours(10)->setTimezone('America/Chicago'); // check if we already have a pending tweet $existing = Tweet::where('event_id', $event['event_id'])->where('days_before', 0)->first(); if (is_null($existing)) { $this->tweet->create(['content' => $tweet, 'tweet_at' => $tweet_at, 'sent' => false, 'event_id' => $event['event_id'], 'days_before' => 0]); } } }
/** * Execute the console command. * * @return mixed */ public function handle() { $tweets = Tweet::where('tweet_at', '<', Carbon::now()->toDateTimeString())->where('sent', false)->get(); if (count($tweets) > 0) { foreach ($tweets as $tweet) { try { $event = Event::where('event_id', $tweet->event_id)->firstOrFail(); } catch (ModelNotFoundException $e) { $this->info('Event with event_id ' . $tweet->event_id . ' not found'); } if (!$event->isCancelled($tweet->event_id)) { $this->postTweet($tweet->content); $this->setTweetAsSent($tweet->id); } } } }