public function generate_daily_digest() { $api_key = get_option('ourcog_gemini_api_key', ''); if (empty($api_key)) { return 'API key is required.'; } // Get today's posts (excluding videos) $today_posts = get_posts(array( 'posts_per_page' => 4, 'post_status' => 'publish', 'date_query' => array( array( 'after' => date('Y-m-d 00:00:00'), 'before' => date('Y-m-d 23:59:59'), 'inclusive' => true, ) ), 'category__not_in' => array(get_cat_ID('video')) )); // Get latest video posts $video_posts = get_posts(array( 'posts_per_page' => 3, 'post_status' => 'publish', 'category_name' => 'video' )); // Format post titles $posts_content = ''; if (!empty($today_posts)) { $titles = array(); foreach ($today_posts as $post) { $titles[] = $post->post_title; } $posts_content = implode(', ', $titles); } $video_titles = ''; if (!empty($video_posts)) { $titles = array(); foreach ($video_posts as $post) { $titles[] = $post->post_title; } $video_titles = implode(', ', $titles); } // Fetch titles from the external RSS feed $rss_titles = $this->get_rss_titles('https://www.faithnews.cc/?feed=rss2', 4); $rss_content = !empty($rss_titles) ? implode(', ', $rss_titles) : 'No recent faith-based news found.'; // Fetch content from Rapture Ready news feed $pro_posts = $this->get_rss_content('https://www.raptureready.com/category/rapture-ready-news/feed/', 4); $pro_content_string = ''; if (!empty($pro_posts)) { foreach ($pro_posts as $post) { $pro_content_string .= "Title: " . $post['title'] . ". Content: " . $post['content'] . "\n\n"; } } else { $pro_content_string = 'No recent prophecy news found.'; } // Fetch latest Jewish history post with content $jewish_history_posts = $this->get_rss_content('https://thisdayinjewishhistory.blogspot.com/feeds/posts/default?alt=rss', 1); $jewish_history_content = ''; if (!empty($jewish_history_posts)) { $post = $jewish_history_posts[0]; $jewish_history_content = "Title: " . $post['title'] . "\nContent: " . $post['content']; } else { $jewish_history_content = 'No recent Jewish history post found'; } // Fetch US and World News content from CBN $us_news_posts = $this->get_cbn_content('https://rss.csmonitor.com/feeds/usa', 5); $world_news_posts = $this->get_cbn_content('https://rss.csmonitor.com/feeds/world', 3); $us_news_content_string = ''; foreach ($us_news_posts as $post) { $us_news_content_string .= "Title: " . $post['title'] . ". Content: " . $post['content'] . "\n\n"; } $world_news_content_string = ''; foreach ($world_news_posts as $post) { $world_news_content_string .= "Title: " . $post['title'] . ". Content: " . $post['content'] . "\n\n"; } $current_date = date('F j, Y', current_time('timestamp')); // Clean and validate all content to ensure valid UTF-8 $video_titles = mb_convert_encoding($video_titles, 'UTF-8', 'UTF-8'); $rss_content = mb_convert_encoding($rss_content, 'UTF-8', 'UTF-8'); $pro_content_string = mb_convert_encoding($pro_content_string, 'UTF-8', 'UTF-8'); $jewish_history_content = mb_convert_encoding($jewish_history_content, 'UTF-8', 'UTF-8'); $us_news_content_string = mb_convert_encoding($us_news_content_string, 'UTF-8', 'UTF-8'); $world_news_content_string = mb_convert_encoding($world_news_content_string, 'UTF-8', 'UTF-8'); $prompt = "Create a daily digest from the following post titles: START WITH: Good evening, and welcome to #ourCOG Daily Brief for {$current_date}. FIRST PARAGRAPH: Summarize today's U.S. and world news using the provided content. U.S. News: {$us_news_content_string} World News: {$world_news_content_string} SECOND PARAGRAPH: Create a single paragraph mentioning the last 5 video titles. The video titles are: {$video_titles} THIRD PARAGRAPH: Create a paragraph with the last 5 titles from the provided FaithNews RSS feed: {$rss_content} FOURTH PARAGRAPH: Create a single paragraph summarizing the latest prophecy news from the following content: {$pro_content_string} FIFTH PARAGRAPH: Finally in Jewish history, create a natural paragraph summarizing the most recent post from the Jewish history blog (regardless of the specific date). Use this content: {$jewish_history_content} Make it sound natural and conversational, like a news anchor would deliver it."; // Use the correct API URL for gemini-2.5-flash $api_url = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=' . $api_key; $headers = array( 'Content-Type' => 'application/json', ); $body = array( 'contents' => array( array( 'parts' => array( array('text' => $prompt) ) ) ) ); // Encode the body and check for errors $json_body = json_encode($body); if ($json_body === false) { return 'JSON encoding error: ' . json_last_error_msg(); } $response = wp_remote_post( $api_url, array( 'headers' => $headers, 'body' => $json_body, 'timeout' => 45, ) ); if (is_wp_error($response)) { return 'API Error: ' . $response->get_error_message(); } $response_body = wp_remote_retrieve_body($response); $data = json_decode($response_body); $http_status = wp_remote_retrieve_response_code($response); if ($http_status !== 200) { if (isset($data->error->message)) { return 'Gemini API Error (' . $http_status . '): ' . $data->error->message; } else { return 'Gemini API Error (' . $http_status . '): An unexpected error occurred.'; } } if (isset($data->candidates) && !empty($data->candidates)) { $digest_content = $data->candidates[0]->content->parts[0]->text; $new_post_id = wp_insert_post(array( 'post_title' => '#ourCOG Daily Brief ' . date('[F j, Y]', current_time('timestamp')), 'post_content' => wp_kses_post($digest_content), 'post_status' => 'publish', 'post_type' => 'post', )); if (is_wp_error($new_post_id)) { return 'Error creating the digest post: ' . $new_post_id->get_error_message(); } return true; } elseif (isset($data->promptFeedback) && isset($data->promptFeedback->safetyRatings)) { $reasons = array(); foreach ($data->promptFeedback->safetyRatings as $rating) { if ($rating->probability === 'HIGH' || $rating->probability === 'MEDIUM') { $reasons[] = $rating->category; } } return 'Gemini API Error: The prompt was blocked due to safety concerns. Reasons: ' . implode(', ', $reasons); } else { return 'No content received from the Gemini API.'; } } place – Page 2 – All #ourCOG News
Profile
Author

Lee University will welcome hundreds of guests, alumni, and community leaders on Friday, Sept. 20, to “Celebration 2024,” a morning planned to commemorate “the blessings of God, the faithfulness of […]
The post “Celebration 2024” to T…

Author

Lee University’s Small Jazz Ensemble will present a concert on Tuesday, April 9, at 7:30 p.m. in the Squire’s Recital Hall on Lee’s campus.    The Small Jazz Ensemble is directed […]
The post Small Jazz Ensemble Concert to Take Place Tuesday appe…

Author

There are 7 Feasts of the Lord, 4 of them for the Church in the Spring, and 3 of them for the Jews and Israel in the Fall In his excellent whole Bible commentary known as Dispensational Truth, Clarence Larkin says this “The 23d chapter of the Book of Leviticus gives us an account of […]

The post NTEB RADIO BIBLE STUDY: 4 Feasts Of The Lord For The Church Take Place In The Spring, And 3 Feasts For The Jews And Israel Are In The Fall appeared first on Now The End Begins.

Author

Lee University senior Sarah Bertram recently won third place for her poster presentation at the 133rd annual meeting of the Tennessee Academy of Science. Her research, “Type II Diabetes: Knowledge […]
The post Bertram Earns Third Place at Tenness…

Author

If you enjoy the message we put out, make sure to subscribe to our channel. Omega Center International is an Evangelical convention center in Cleveland, TN, that is home to the Ramp at OCI. Make sure to watch our live streams Tuesdays at 7:00 PM. Follow us on Facebook at the Ramp at OCI for […]

Author

Pastor Shane Brown gives a Bible-based teaching about the importance of every Christian spending daily time in prayer and the Word. http://www.wordfaithministry.weebly.com