/** * Execute the console command. * * @return mixed */ public function handle() { $youtube = new Client(); $searchResponse = json_decode($youtube->get('https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=' . $this->channelID . '&eventType=live&type=video&key=' . Config::get('services.youtube.key'))->getBody()); $isLive = $searchResponse->pageInfo->totalResults != 0; // Determine the total number of viewers if ($isLive) { $videoResponse = json_decode($youtube->get('https://www.googleapis.com/youtube/v3/videos?part=liveStreamingDetails&id=' . $searchResponse->items[0]->id->videoId . '&key=' . Config::get('services.youtube.key'))->getBody()); $viewers = $videoResponse->items[0]->liveStreamingDetails->concurrentViewers; } else { $viewers = 0; } // If the livestream is active now, and wasn't before, or vice versa, send an event if ($isLive && (Redis::hget('webcast', 'isLive') == 'false' || !Redis::hexists('webcast', 'isLive'))) { // Grab all the relevant SpaceX youtube Livestreams, and create an event $videos = $this->getMultipleYoutubeLivestreams($videoId); // $searchResponse->items[0]->id->videoId event(new WebcastStartedEvent($videos)); } elseif (!$isLive && Redis::hget('webcast', 'isLive') == 'true') { // turn off the spacex webcast event(new WebcastEndedEvent("spacex", false)); } // Set the Redis properties Redis::hmset('webcast', 'isLive', $isLive === true ? 'true' : 'false', 'viewers', $viewers); // Add to Database if livestream is active if ($isLive) { WebcastStatus::create(['viewers' => $viewers]); } }
private static function requestAdDatailsCache($dma_code, $ad_id, $job_id) { $sql = "SELECT a.id, a.dma_code, a.copy, aj.job_id\n \t\t\t FROM ad_jobs aj, ads a\n \t\t\t WHERE aj.ad_id = a.id\n \t\t\t\tAND a.is_active = 1\n \t\t\t\tAND aj.job_id = {$job_id}\n \t\t\t\tAND a.dma_code = {$dma_code}\n \t\t\t\tAND a.id = {$ad_id}"; $ads = DB::select($sql); foreach ($ads as $ad) { $cache_data['copy'] = $ad->copy; $cache_data['url'] = getShortenUrl('http://diversityonecareers.com/job/' . $ad->job_id . '?' . buildAdTrackingQuery($ad->copy)); $cache_key = self::getAdDetailsCacheKey($dma_code, $ad_id, $job_id); Redis::hmset($cache_key, $cache_data); } }
/** * Create a SpaceXStats Live event. Set all the necessary Redis parameters, render a Reddit Thread template, * publish it, then broadcast a LiveStartedEvent to notify websocket listeners. * * @return mixed */ public function create() { // Turn on SpaceXStats Live Redis::set('live:active', true); // Set the streams available Redis::hmset('live:streams', ['spacex' => json_encode(Input::get('streams.spacex')), 'spacexClean' => json_encode(Input::get('streams.spacexClean')), 'nasa' => json_encode(Input::get('streams.nasa'))]); // Set the countdown Redis::hmset('live:countdown', ['to' => Input::get('countdown.to'), 'isPaused' => false]); // Set the details Redis::set('live:title', Input::get('title')); Redis::hmset('live:description', ['raw' => Input::get('description.raw'), 'markdown' => Parsedown::instance()->parse(Input::get('description.raw'))]); Redis::set('live:isForLaunch', Input::get('isForLaunch')); Redis::set('live:resources', json_encode(Input::get('resources'))); Redis::set('live:sections', json_encode(Input::get('sections'))); Redis::set('live:status', 'Upcoming'); // Set the Reddit parameters Redis::hmset('live:reddit', ['title' => Input::get('reddit.title')]); // Create the canned responses Redis::hmset('live:cannedResponses', ['holdAbort' => 'HOLD HOLD HOLD. The countdown has been aborted.', 'terminalCount' => 'Terminal count has now begun. From this point forward, any scrubs will result in a recycle to T-10 minutes.', 'inProgress' => 'Liftoff of ' . Mission::future()->first()->name . '!', 'maxQ' => 'MaxQ, at this point in flight, the vehicle is flying through maximum aerodynamic pressure.', 'MECO' => "MECO! The vehicle's first stage engines have shutdown in preparation for stage separation.", 'stageSep' => 'Stage separation confirmed.', 'mVacIgnition' => "Falcon's upper stage Merlin Vacuum engine has ignited for the ride to orbit.", 'SECO' => 'SECO! Falcon is now in orbit!', 'missionSuccess' => 'Success! SpaceX has completed another successful mission!', 'missionFailure' => 'We appear to have had a failure. We will bring more information to you as it is made available.']); // Render the Reddit thread template $templatedOutput = view('templates.livethreadcontents')->with(array())->render(); // Create the Reddit thread (create a service for this) $reddit = new Reddit(Config::get('services.reddit.username'), Config::get('services.reddit.password'), Config::get('services.reddit.id'), Config::get('services.reddit.secret')); $reddit->setUserAgent('/u/ElongatedMuskrat by /u/EchoLogic. Runs various /r/SpaceX-related tasks.'); // Create a post $subreddit = App::environment('production') ? 'spacex' : 'echocss'; $response = $reddit->subreddit($subreddit)->submit(['kind' => 'self', 'sendreplies' => true, 'text' => $templatedOutput, 'title' => Input::get('reddit.title')]); Redis::hmset('live:reddit', ['thing' => $response->data->name]); // Broadcast event to turn on spacexstats live event(new LiveStartedEvent(['active' => true, 'streams' => ['spacex' => Input::get('streams.spacex'), 'spacexClean' => Input::get('streams.spacexClean'), 'nasa' => Input::get('streams.nasa')], 'countdown' => ['to' => Input::get('countdown.to'), 'isPaused' => false], 'title' => Input::get('title'), 'reddit' => ['title' => Input::get('reddit.title'), 'thing' => $response->data->name], 'description' => Redis::hgetall('live:description'), 'isForLaunch' => Input::get('isForLaunch'), 'resources' => Input::get('resources'), 'sections' => Input::get('sections'), 'status' => 'Upcoming', 'cannedResponses' => Redis::hgetall('live:cannedResponses')])); // Respond return response()->json(null, 204); }
private static function requestCache($str_id) { $companyObj = self::where(['str_id' => $str_id])->first(); if (!empty($companyObj)) { if ($companyObj->is_promoted == 1) { $cache_data = ['CompanyId' => $companyObj->id, 'CompanyStrId' => $companyObj->str_id, 'CompanyName' => $companyObj->name, 'CompanyIndustry' => $companyObj->industry, 'CompanyImg' => $companyObj->img_url, 'CompanyBkgrImg' => $companyObj->background_url, 'CompanyRss' => $companyObj->rss_feed, 'CompanyFacebook' => $companyObj->facebook, 'CompanyTwitter' => $companyObj->twitter, 'CompanyDemographics' => $companyObj->demographics, 'CompanyDescription' => $companyObj->description, 'CompanyIsPromoted' => $companyObj->is_promoted, 'CompanyKeywords' => '']; } else { $cache_data = ['CompanyId' => $companyObj->id, 'CompanyStrId' => $companyObj->str_id, 'CompanyName' => $companyObj->name, 'CompanyIndustry' => $companyObj->industry, 'CompanyImg' => $companyObj->img_url, 'CompanyBkgrImg' => '', 'CompanyRss' => '', 'CompanyFacebook' => '', 'CompanyTwitter' => '', 'CompanyDemographics' => '', 'CompanyDescription' => $companyObj->description, 'CompanyIsPromoted' => $companyObj->is_promoted, 'CompanyKeywords' => '']; } if (!$companyObj->keywords->isEmpty()) { $kw_list = []; foreach ($companyObj->keywords as $k) { $kw_list[] = $k->keyword; } $cache_data['CompanyKeywords'] = implode(',', $kw_list); } $cache_key = self::getCacheKey($str_id); Redis::hmset($cache_key, $cache_data); } }
private static function requestCache($job_id) { $sql = "\n\t\t\tSELECT j.id, j.title, j.apply_url, j.begin_date, j.end_date, \n\t\t\t j.post_date, j.dma_code, j.city, j.state, j.zip, j.featured_flag,\n\t\t\t j.created_at, j.updated_at, s.display_name `source`,\n\t\t\t c.name `category`, i.name `industry`, \n\t\t\t comp.name `company`, comp.str_id `company_str_id`, comp.id `company_id`\n \t\t\t FROM jobs j \n \t\t\t LEFT JOIN sources s ON (j.source_id = s.id)\n \t\t\t LEFT JOIN categories c ON (j.category_id = c.id)\n \t\t\t LEFT JOIN industries i ON (j.industry_id = i.id)\n \t\t\t LEFT JOIN companies comp ON (j.company_id = comp.id)\n \t\t\t WHERE j.id = {$job_id}"; $jobObj = DB::select($sql); if (!empty($jobObj[0])) { $jobObj = $jobObj[0]; $cache_key = self::getCacheKey($job_id); $cache_data = ['JobID' => $jobObj->id, 'JobTitle' => $jobObj->title, 'JobUrl' => $jobObj->apply_url, 'JobCity' => $jobObj->city, 'JobState' => $jobObj->state, 'JobZip' => $jobObj->zip, 'JobBeginDate' => $jobObj->begin_date, 'JobEndDate' => $jobObj->end_date, 'JobPostDate' => $jobObj->post_date, 'JobDmaCode' => $jobObj->dma_code, 'JobCategory' => $jobObj->category, 'JobIndustry' => $jobObj->industry, 'JobSource' => $jobObj->source, 'JobCompany' => $jobObj->company ? trim($jobObj->company) : 'Confidential', 'JobCompanyId' => $jobObj->company_id ? trim($jobObj->company_id) : '', 'JobCompanyStrId' => $jobObj->company_str_id ? trim($jobObj->company_str_id) : '', 'JobIsFeatured' => $jobObj->featured_flag, 'JobCreatedAt' => $jobObj->created_at, 'JobUpdatedAt' => $jobObj->updated_at]; // adding keywords $cache_data['JobKeywords'] = ''; $k_q = "\n\t\t\t SELECT keyword\n\t\t\t \t FROM keywords k, job_keywords jk\n\t\t\t WHERE jk.keyword_id = k.id\n\t\t\t\t AND jk.job_id = {$job_id}"; $keywords = DB::select($k_q); if (!empty($keywords)) { foreach ($keywords as $k) { $kw_list[] = $k->keyword; } $cache_data['JobKeywords'] = implode(',', $kw_list); } Redis::hmset($cache_key, $cache_data); Redis::expire($cache_key, 60 * 60 * 24 * 7); } }