File: /home/awaldron/_phpassport/api.pennhillspassport.com/v1/cron_news.php
<?php
//**********************************************************************************************************//
// Method: GET
// Endpoint: news/trib
function get_v1_news_trib($args, $body, $uid, $admin_level, $db)
{
$xmlUrl = 'https://triblive.com/category/local/penn-hills/feed/';
$xml = fetchXml($xmlUrl);
$array = xmlToArray($xml);
$ctr = 0;
$ctr2 = 0;
foreach ($array as $story) {
$existingId = qVal($db, "SELECT id FROM news WHERE ext_id='" . $story['link'] . "'");
if (!$existingId) {
$story_image =
getFirstCarouselImage($story['link'])
?? getFirstCarouselThumb($story['link'])
?? null;
$ins = "INSERT INTO news (`user_id`, `channel_id`, `image`, `headline`, `subhead`, `body`, `author`, `date_published`, `date_modified`, `ext_url`, `ext_id`, `approved`) VALUES (";
$ins .= '1001, ';
$ins .= '8, ';
$ins .= "'" . $story_image . "', ";
$ins .= "'" . formatHtml($story['title'], true) . "', ";
$ins .= "'" . formatHtml($story['description_text'], true) . "', ";
$ins .= "'', ";
$ins .= "'" . formatHtml($story['creator'], true) . "', ";
$ins .= "'" . $story['pubDate'] . "', ";
$ins .= "'" . $story['pubDate'] . "', ";
$ins .= "'" . $story['link'] . "', ";
$ins .= "'" . $story['link'] . "', ";
$ins .= "1";
$ins .= ")";
$result = $db->query($ins);
$newId = qVal($db, "SELECT MAX(id) FROM news WHERE approved=1");
sendpush($story['title'], $story['description_text'], 'news/detaildeep/'.$newId);
$ctr++;
}
else {
// $story_image =
// getFirstCarouselImage($story['link'])
// ?? getFirstCarouselThumb($story['link'])
// ?? null;
$upd = "UPDATE news SET ";
//$upd .= "`image`='".$story_image."', ";
$upd .= "`headline`='".formatHtml($story['title'], true)."', ";
$upd .= "`subhead`='".formatHtml($story['description_text'], true)."', ";
$upd .= "`author`='".formatHtml($story['creator'], true)."', ";
$upd .= "`ext_id`='".$story['link']."', ";
$upd .= "`ext_url`='".$story['link']."', ";
$upd .= "`date_published`='" . $story['pubDate'] . "', ";
$upd .= "`date_modified`='" . $story['pubDate'] . "' ";
$upd .= "WHERE id=".$existingId;
$result = $db->query($upd);
$ctr2++;
}
}
response(200, ['success' => true, 'inserted'=>$ctr, 'updated'=>$ctr2, 'lastrun'=> date('m/d/Y H:i:s') ]);
}
//**********************************************************************************************************//
// Method: GET
// Endpoint: news/phsd
function get_v1_news_phsd($args, $body, $uid, $admin_level, $db)
{
$feeds = [[6, 7], [12, 6], [8, 6], [5, 6], [7, 6], [3, 6], [13, 6]];
$ctr = 0;
$ctr2 = 0;
foreach ($feeds as $feed) {
$url = "https://www.phsd.org/fs/post-manager/boards/".$feed[0]."/posts/feed";
$stories = fetchAndParseRSS($url);
foreach ($stories['entry'] as $story) {
$existingId = qVal($db, "SELECT id FROM news WHERE ext_id='" . $story['link']['@attributes']['href'] . "'");
if (!$existingId) {
$ins = "INSERT INTO news (`user_id`, `channel_id`, `image`, `headline`, `subhead`, `body`, `author`, `date_published`, `date_modified`, `ext_url`, `ext_id`, `approved`) VALUES (";
$ins .= '1001, ';
$ins .= $feed[1].', ';
$ins .= "'" . $story['image_url'] . "', ";
$ins .= "'" . formatHtml($story['title'], true) . "', ";
$ins .= "'" . formatHtml($story['content'], true) . "', ";
$ins .= "'" . formatHtml($story['content'], true) . "', ";
$ins .= "'" . formatHtml($story['author']['name'], true) . "', ";
$ins .= "'" . str_ireplace('Z','.000Z', $story['published']) . "', ";
$ins .= "'" . str_ireplace('Z','.000Z', $story['updated']) . "', ";
$ins .= "'" . $story['link']['@attributes']['href'] . "', ";
$ins .= "'" . $story['link']['@attributes']['href'] . "', ";
$ins .= "1";
$ins .= ")";
$result = $db->query($ins);
$newId = qVal($db, "SELECT MAX(id) FROM news WHERE approved=1");
sendpush($story['title'], $story['content'], 'news/detaildeep/'.$newId);
$ctr++;
}
else {
$upd = "UPDATE news SET ";
$upd .= "`headline`='".formatHtml($story['title'], true)."', ";
$upd .= "`subhead`='".formatHtml($story['content'], true)."', ";
$upd .= "`body`='".formatHtml($story['content'], true)."', ";
$upd .= "`author`='".formatHtml($story['author']['name'], true)."', ";
$upd .= "`ext_id`='".$story['link']['@attributes']['href']."', ";
$upd .= "`ext_url`='".$story['link']['@attributes']['href']."', ";
$upd .= "`date_published`='" . str_ireplace('Z','.000Z', $story['published']) . "', ";
$upd .= "`date_modified`='" . str_ireplace('Z','.000Z', $story['updated']) . "' ";
$upd .= "WHERE id=".$existingId;
$result = $db->query($upd);
$ctr2++;
}
}
}
response(200, ['success' => true, 'inserted' => $ctr, 'updated' => $ctr2, 'lastrun'=> date('m/d/Y H:i:s') ]);
}
//**********************************************************************************************************//
// Method: GET
// Endpoint: news/phstcfb
function get_v1_news_phstcfb($args, $body, $uid, $admin_level, $db)
{
$jsonUrl = "https://fetchrss.com/feed/Z2H8KK7XeDGiaG6ZBxvwIftz.json";
$posts = json_decode(file_get_contents($jsonUrl), true);
$posts = pull_facebook_images($posts['items']);
$ctr = 0;
$ctr2 = 0;
// $posts2 = [];
// foreach ($posts as $post) {
// if (!stristr($post['description'], 'senior spotlight')) { // REMOVE SENIOR SPOTLIGHTS
// $posts2[] = $post;
// }
// }
//print_r($posts2); exit;
foreach ($posts as $story) {
$path = parse_url($story['link'], PHP_URL_PATH);
$segments = explode('/', rtrim($path, '/'));
$fbId = "".end($segments);
$ext_id = 'phstc-fb-'.end($segments);
$existingId = qVal($db, "SELECT id FROM news WHERE ext_id='" .$ext_id . "'");
if (empty($story['images']) || !count($story['images'])) {
$images = ['https://pennhillspassport.com/news/864566-974579-screenshot-2024-08-28-at-3-28-35-pm.png'];
} else {
$images = array_unique($story['images']);
for ($i = 0; $i < count($images); $i++) {
$images[$i] = save_facebook_image($images[$i]);
}
}
$title = formatHtml($story['description'], true);
$body = '<p>'.formatHtml($story['description'], '<p><br>').'</p>';
$body = nl2br($body);
if (empty(strip_tags($body))) {
//echo '--- skipping no content'."\n\n\n\n";
continue;
}
$body .= '<p><a href="'.$story['link'].'"><b>Visit Facebook for more info and discussion >></b></a></p>';
if ($images[0] !== 'https://pennhillspassport.com/news/864566-974579-screenshot-2024-08-28-at-3-28-35-pm.png') {
for ($i=0; $i<count($images); $i++) {
$body .= '<p><img src="'.$images[$i].'" style="max-width:100%;" /></p>';
}
$body .= '<p><a href="'.$story['link'].'"><b>Visit Facebook for more info and discussion >></b></a></p>';
}
$body = str_replace('•','•',$body);
$body = str_replace('•','• ',$body);
if (!$existingId) {
$title = str_replace('"','',chatgpt_post_title($title));
$ins = "INSERT INTO news (`user_id`, `channel_id`, `feed`, `image`, `headline`, `subhead`, `body`, `author`, `date_published`, `date_modified`, `ext_url`, `ext_id`, `pushed`, `approved`) VALUES (";
$ins .= '1001, ';
$ins .= '9, ';
$ins .= '1, ';
$ins .= "'".$images[0]."', ";
$ins .= "'" . addslashes($title) . "', "; // headline
$ins .= "'', "; // subhead
$ins .= "'" . $body . "', "; // body
$ins .= "'Penn Hills Shade Tree Commission', "; // author
$ins .= "'" . convertToISO($story['pubDate']) . "', "; // published
$ins .= "'" . convertToISO($story['pubDate']) . "', "; // modified
$ins .= "'', "; // ext_url
$ins .= "'" . $ext_id . "', "; // ext_id
$ins .= "0, 1";
$ins .= ")";
$result = $db->query($ins);
$newId = qVal($db, "SELECT MAX(id) FROM news WHERE approved=1");
sendpush($title, substr($body,0,85).'...', 'news/detaildeep/'.$newId);
$ctr++;
//echo '<p>'.$ins.'</p>'."\n\n\n";
}
else {
$upd = "UPDATE news SET ";
$upd .= "`body`='".$body."', ";
$upd .= "`author`='Penn Hills Shade Tree Commission', ";
$upd .= "`ext_id`='".$ext_id."', ";
$upd .= "`ext_url`='', ";
$upd .= "`date_published`='" . convertToISO($story['pubDate']) . "', ";
$upd .= "`date_modified`='" . convertToISO($story['pubDate']) . "' ";
$upd .= "WHERE id=".$existingId;
$result = $db->query($upd);
$ctr2++;
}
}
response(200, ['success' => true, 'inserted' => $ctr, 'updated' => $ctr2, 'lastrun'=> date('m/d/Y H:i:s') ]);
}
//**********************************************************************************************************//
// Method: GET
// Endpoint: news/phpdfb
function get_v1_news_phpdfb($args, $body, $uid, $admin_level, $db)
{
$jsonUrl = "https://fetchrss.com/feed/1tNg7s4Jj3Iw1uSxdY1oh3JD.json";
$posts = json_decode(file_get_contents($jsonUrl), true);
$posts = pull_facebook_images($posts['items']);
$ctr = 0;
$ctr2 = 0;
$posts2 = [];
foreach ($posts as $post) {
if (stristr($post['description'], '#php:')) {
$posts2[] = $post;
}
}
foreach ($posts2 as $story) {
$path = parse_url($story['link'], PHP_URL_PATH);
$segments = explode('/', rtrim($path, '/'));
$fbId = "".end($segments);
$ext_id = 'phpd-fb-'.end($segments);
//echo $fbId."<br/>";
$existingId = qVal($db, "SELECT id FROM news WHERE ext_id='" .$ext_id . "'");
if (empty($story['images']) || !count($story['images'])) {
$images = ['https://pennhillspassport.com/news/phpd-news.png'];
} else {
$images = array_unique($story['images']);
for ($i = 0; $i < count($images); $i++) {
$images[$i] = save_facebook_image($images[$i]);
}
}
$title = formatHtml($story['description'], true);
$body = '<p>'.formatHtml($story['description'], '<p><br>').'</p>';
$body = nl2br($body);
if (empty(strip_tags($body))) {
//echo '--- skipping no content'."\n\n\n\n";
continue;
}
$body .= '<p><a href="'.$story['link'].'"><b>Visit Facebook for more info and discussion >></b></a></p>';
if ($images[0] !== 'https://pennhillspassport.com/news/phpd-news.png') {
for ($i=0; $i<count($images); $i++) {
$body .= '<p><img src="'.$images[$i].'" style="max-width:100%;" /></p>';
}
$body .= '<p><a href="'.$story['link'].'"><b>Visit Facebook for more info and discussion >></b></a></p>';
}
$body = str_replace('•','•',$body);
$body = str_replace('•','• ',$body);
if (!$existingId) {
$title = str_replace('"','',chatgpt_post_title($title));
$ins = "INSERT INTO news (`user_id`, `channel_id`, `feed`, `image`, `headline`, `subhead`, `body`, `author`, `date_published`, `date_modified`, `ext_url`, `ext_id`, `pushed`, `approved`) VALUES (";
$ins .= '1001, ';
$ins .= '1, ';
$ins .= '5, ';
$ins .= "'".$images[0]."', ";
$ins .= "'" . addslashes($title) . "', "; // headline
$ins .= "'', "; // subhead
$ins .= "'" . $body . "', "; // body
$ins .= "'Penn Hills Police Dept.', "; // author
$ins .= "'" . convertToISO($story['pubDate']) . "', "; // published
$ins .= "'" . convertToISO($story['pubDate']) . "', "; // modified
$ins .= "'', "; // ext_url
$ins .= "'" . $ext_id . "', "; // ext_id
$ins .= "0, 1";
$ins .= ")";
$result = $db->query($ins);
$newId = qVal($db, "SELECT MAX(id) FROM news WHERE approved=1");
//sendpush($title, substr($body,0,85).'...', 'news/detaildeep/'.$newId);
$ctr++;
//echo '<p>'.$ins.'</p>'."\n\n\n";
}
else {
$upd = "UPDATE news SET ";
$upd .= "`body`='".$body."', ";
$upd .= "`author`='Penn Hills Police Dept.', ";
$upd .= "`ext_id`='".$ext_id."', ";
$upd .= "`channel_id`=5, ";
$upd .= "`feed`=1, ";
$upd .= "`ext_url`='', ";
$upd .= "`date_published`='" . convertToISO($story['pubDate']) . "', ";
$upd .= "`date_modified`='" . convertToISO($story['pubDate']) . "' ";
$upd .= "WHERE id=".$existingId;
$result = $db->query($upd);
$ctr2++;
}
}
response(200, ['success' => true, 'inserted' => $ctr, 'updated' => $ctr2, 'lastrun'=> date('m/d/Y H:i:s') ]);
}
//**********************************************************************************************************//
// Method: GET
// Endpoint: news/phsdfb
function get_v1_news_phsdfb($args, $body, $uid, $admin_level, $db)
{
$jsonUrl = "http://fetchrss.com/rss/6761fc28ae1e40d7780731a26825d5fe1c4b0d110102e612.json";
$posts = json_decode(file_get_contents($jsonUrl), true);
$posts = pull_facebook_images($posts['items']);
$ctr = 0;
$ctr2 = 0;
$posts2 = [];
foreach ($posts as $post) {
if (!stristr($post['description'], 'senior spotlight')) { // REMOVE SENIOR SPOTLIGHTS
$posts2[] = $post;
}
}
//print_r($posts2); exit;
foreach ($posts2 as $story) {
$path = parse_url($story['link'], PHP_URL_PATH);
$segments = explode('/', rtrim($path, '/'));
$fbId = "".end($segments);
$ext_id = 'phfd-fb-'.end($segments);
$existingId = qVal($db, "SELECT id FROM news WHERE ext_id='" .$ext_id . "'");
if (empty($story['images']) || !count($story['images'])) {
$images = ['https://pennhillspassport.com/news/phsd-default.jpg'];
} else {
$images = array_unique($story['images']);
for ($i = 0; $i < count($images); $i++) {
$images[$i] = save_facebook_image($images[$i]);
}
}
$title = formatHtml($story['description'], true);
$body = '<p>'.formatHtml($story['description'], '<p><br>').'</p>';
$body = nl2br($body);
if (empty(strip_tags($body))) {
//echo '--- skipping no content'."\n\n\n\n";
continue;
}
$body .= '<p><a href="'.$story['link'].'"><b>Visit Facebook for more info and discussion >></b></a></p>';
if ($images[0] !== 'https://pennhillspassport.com/news/phsd-default.jpg') {
for ($i=0; $i<count($images); $i++) {
$body .= '<p><img src="'.$images[$i].'" style="max-width:100%;" /></p>';
}
$body .= '<p><a href="'.$story['link'].'"><b>Visit Facebook for more info and discussion >></b></a></p>';
}
$body = str_replace('•','•',$body);
$body = str_replace('•','• ',$body);
if (!$existingId) {
$title = str_replace('"','',chatgpt_post_title($title));
$ins = "INSERT INTO news (`user_id`, `channel_id`, `feed`, `image`, `headline`, `subhead`, `body`, `author`, `date_published`, `date_modified`, `ext_url`, `ext_id`, `pushed`, `approved`) VALUES (";
$ins .= '1001, ';
$ins .= '6, ';
$ins .= '1, ';
$ins .= "'".$images[0]."', ";
$ins .= "'" . addslashes($title) . "', "; // headline
$ins .= "'', "; // subhead
$ins .= "'" . $body . "', "; // body
$ins .= "'Penn Hills School District', "; // author
$ins .= "'" . convertToISO($story['pubDate']) . "', "; // published
$ins .= "'" . convertToISO($story['pubDate']) . "', "; // modified
$ins .= "'', "; // ext_url
$ins .= "'" . $ext_id . "', "; // ext_id
$ins .= "0, 1";
$ins .= ")";
$result = $db->query($ins);
$newId = qVal($db, "SELECT MAX(id) FROM news WHERE approved=1");
//sendpush($title, substr($body,0,85).'...', 'news/detaildeep/'.$newId);
$ctr++;
//echo '<p>'.$ins.'</p>'."\n\n\n";
}
else {
//$title = str_replace('"','',chatgpt_post_title($title));
$upd = "UPDATE news SET ";
$upd .= "`body`='".$body."', ";
$upd .= "`author`='Penn Hills School District', ";
//$upd .= "`headline`='".addslashes($title)."', ";
$upd .= "`ext_id`='".$ext_id."', ";
$upd .= "`ext_url`='', ";
$upd .= "`date_published`='" . convertToISO($story['pubDate']) . "', ";
$upd .= "`date_modified`='" . convertToISO($story['pubDate']) . "' ";
$upd .= "WHERE id=".$existingId;
$result = $db->query($upd);
$ctr2++;
}
}
response(200, ['success' => true, 'inserted' => $ctr, 'updated' => $ctr2, 'lastrun'=> date('m/d/Y H:i:s') ]);
}
//**********************************************************************************************************//
// Method: GET
// Endpoint: news/phparks
function get_v1_news_phparks($args, $body, $uid, $admin_level, $db)
{
$jsonUrl = "http://fetchrss.com/rss/6761fc28ae1e40d7780731a26825fe4acf042e3afb0cdbd3.json";
$posts = json_decode(file_get_contents($jsonUrl), true);
$posts = pull_facebook_images($posts['items']);
$ctr = 0;
$ctr2 = 0;
// $posts2 = [];
// foreach ($posts as $post) {
// if (!stristr($post['description'], 'senior spotlight')) { // REMOVE SENIOR SPOTLIGHTS
// $posts2[] = $post;
// }
// }
//pp($posts); //exit;
foreach ($posts as $story) {
$path = parse_url($story['link'], PHP_URL_PATH);
$segments = explode('/', rtrim($path, '/'));
$fbId = "".end($segments);
$ext_id = 'phparks-fb-'.end($segments);
$existingId = qVal($db, "SELECT id FROM news WHERE ext_id='" .$ext_id . "'");
if (empty($story['images']) || !count($story['images'])) {
$images = ['https://pennhillspassport.com/news/muni-default-image.jpg'];
} else {
$images = array_unique($story['images']);
for ($i = 0; $i < count($images); $i++) {
$images[$i] = save_facebook_image($images[$i]);
}
}
$title = formatHtml($story['description'], true);
$body = '<p>'.formatHtml($story['description'], '<p><br>').'</p>';
$body = nl2br($body);
if (empty(strip_tags($body))) {
//echo '--- skipping no content'."\n\n\n\n";
continue;
}
$body .= '<p><a href="'.$story['link'].'"><b>Visit Facebook for more info and discussion >></b></a></p>';
if ($images[0] !== 'https://pennhillspassport.com/news/muni-default-image.jpg') {
for ($i=0; $i<count($images); $i++) {
$body .= '<p><img src="'.$images[$i].'" style="max-width:100%;" /></p>';
}
$body .= '<p><a href="'.$story['link'].'"><b>Visit Facebook for more info and discussion >></b></a></p>';
}
$body = str_replace('•','•',$body);
$body = str_replace('•','• ',$body);
if (!$existingId) {
$title = str_replace('"','',chatgpt_post_title($title));
$ins = "INSERT INTO news (`user_id`, `channel_id`, `feed`, `image`, `headline`, `subhead`, `body`, `author`, `date_published`, `date_modified`, `ext_url`, `ext_id`, `pushed`, `approved`) VALUES (";
$ins .= '1001, ';
$ins .= '4, ';
$ins .= '1, ';
$ins .= "'".$images[0]."', ";
$ins .= "'" . addslashes($title) . "', "; // headline
$ins .= "'', "; // subhead
$ins .= "'" . $body . "', "; // body
$ins .= "'John Scaglione', "; // author
$ins .= "'" . convertToISO($story['pubDate']) . "', "; // published
$ins .= "'" . convertToISO($story['pubDate']) . "', "; // modified
$ins .= "'', "; // ext_url
$ins .= "'" . $ext_id . "', "; // ext_id
$ins .= "0, 1";
$ins .= ")";
$result = $db->query($ins);
$newId = qVal($db, "SELECT MAX(id) FROM news WHERE approved=1");
//sendpush($title, substr($body,0,85).'...', 'news/detaildeep/'.$newId);
$ctr++;
//echo '<p>'.$ins.'</p>'."\n\n\n";
}
else {
$upd = "UPDATE news SET ";
$upd .= "`body`='".$body."', ";
$upd .= "`author`='John Scaglione', ";
$upd .= "`ext_id`='".$ext_id."', ";
$upd .= "`ext_url`='', ";
$upd .= "`date_published`='" . convertToISO($story['pubDate']) . "', ";
$upd .= "`date_modified`='" . convertToISO($story['pubDate']) . "' ";
$upd .= "WHERE id=".$existingId;
$result = $db->query($upd);
$ctr2++;
}
}
response(200, ['success' => true, 'inserted' => $ctr, 'updated' => $ctr2, 'lastrun'=> date('m/d/Y H:i:s') ]);
}
//**********************************************************************************************************//
// Method: GET
// Endpoint: news/muni
function get_v1_news_muni($args, $body, $uid, $admin_level, $db)
{
$xmlUrl = 'https://pennhillspa.gov/feed/';
$xml = fetchXml($xmlUrl);
$array = xmlToArray($xml);
$ctr = 0;
$ctr2 = 0;
//pp($array); exit;
foreach ($array as $story) {
$existingId = qVal($db, "SELECT id FROM news WHERE ext_id='" . removeQueryParams($story['link']) . "'");
if (!$existingId) {
$ins = "INSERT INTO news (`user_id`, `channel_id`, `image`, `headline`, `subhead`, `body`, `author`, `date_published`, `date_modified`, `ext_url`, `ext_id`, `approved`) VALUES (";
$ins .= '1001, ';
$ins .= '4, ';
$ins .= "'https://pennhillspassport.com/news/muni-default-image.jpg', ";
$ins .= "'" . formatHtml($story['title'], true) . "', ";
$ins .= "'" . formatHtml($story['description_text'], true) . "', ";
$ins .= "'" . formatHtml($story['description_text'], true) . "', ";
$ins .= "'" . formatHtml($story['creator'], true) . "', ";
$ins .= "'" . $story['pubDate'] . "', ";
$ins .= "'" . $story['pubDate'] . "', ";
$ins .= "'" . removeQueryParams($story['link']) . "', ";
$ins .= "'" . removeQueryParams($story['link']) . "', ";
$ins .= "1";
$ins .= ")";
$result = $db->query($ins);
$newId = qVal($db, "SELECT MAX(id) FROM news WHERE approved=1");
sendpush($story['title'], $story['description_text'], 'news/detaildeep/'.$newId);
$ctr++;
}
else {
$upd = "UPDATE news SET ";
$upd .= "`headline`='".formatHtml($story['title'], true)."', ";
$upd .= "`subhead`='".formatHtml($story['description_text'], true)."', ";
$upd .= "`body`='".formatHtml($story['description_text'], true)."', ";
$upd .= "`author`='".formatHtml($story['creator'], true)."', ";
$upd .= "`ext_id`='".removeQueryParams($story['link'])."', ";
$upd .= "`ext_url`='".removeQueryParams($story['link'])."', ";
$upd .= "`date_published`='" . $story['pubDate'] . "', ";
$upd .= "`date_modified`='" . $story['pubDate'] . "' ";
$upd .= "WHERE id=".$existingId;
$result = $db->query($upd);
$ctr2++;
}
}
response(200, ['success' => true, 'inserted' => $ctr, 'updated' => $ctr2, 'lastrun'=> date('m/d/Y H:i:s') ]);
}
//**********************************************************************************************************//
// Method: GET
// Endpoint: news/rotary
function get_v1_news_rotary( $args, $body, $uid, $admin_level, $db )
{
$url = 'https://www.pennhillsrotary.org/news?format=json';
$useragent = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0';
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_USERAGENT, $useragent);
curl_setopt($handle, CURLOPT_REFERER, 'https://www.pennhillsrotary.org');
$response = curl_exec($handle);
curl_close($handle);
$stories = json_decode($response, true);
$ctr1 = 0;
$ctr2 = 0;
//pp($stories['items']); exit;
foreach ($stories['items'] as $story) {
$existingId = qVal($db, "SELECT id FROM news WHERE ext_id='" . $story['fullUrl'] . "'");
if (!$existingId) {
$ins = "INSERT INTO news (`user_id`, `channel_id`, `image`, `headline`, `subhead`, `body`, `author`, `date_published`, `date_modified`, `ext_id`, `approved`) VALUES (";
$ins .= '1001, ';
$ins .= '2, ';
$ins .= "'".$story['assetUrl']."', ";
$ins .= "'" . formatHtml($story['title'], true) . "', ";
$ins .= "'" . formatHtml($story['excerpt'], true) . "', ";
$ins .= "'" . formatHtml($story['body'],'<a>') . "', ";
$ins .= "'" . formatHtml($story['author']['displayName'], true) . "', ";
$ins .= "'" . date('Y-m-d', round($story['addedOn'] / 1000 )) . 'T' . date('H:i:s', round($story['addedOn'] / 1000 )) . '.000Z' . "', ";
$ins .= "'" . date('Y-m-d', round($story['updatedOn'] / 1000 )) . 'T' . date('H:i:s', round($story['updatedOn'] / 1000 )) . '.000Z' . "', ";
$ins .= "'" . $story['fullUrl'] . "', ";
$ins .= "1";
$ins .= ")";
$result = $db->query($ins);
$newId = qVal($db, "SELECT MAX(id) FROM news WHERE approved=1");
sendpush($story['title'], $story['excerpt'], 'news/detaildeep/'.$newId);
$ctr1++;
}
else {
$upd = "UPDATE news SET ";
$upd .= "`image`='".$story['assetUrl']."', ";
$upd .= "`headline`='".formatHtml($story['title'], true)."', ";
$upd .= "`subhead`='".formatHtml($story['excerpt'], true)."', ";
$upd .= "`body`='".formatHtml($story['body'],'<p><a><img>')."', ";
$upd .= "`author`='".formatHtml($story['author']['displayName'], true)."', ";
$upd .= "`ext_id`='".$story['fullUrl']."', ";
$upd .= "`date_published`='" . date('Y-m-d', round($story['addedOn'] / 1000 )) . 'T' . date('H:i:s', round($story['addedOn'] / 1000 )) . '.000Z' . "', ";
$upd .= "`date_modified`='" . date('Y-m-d', round($story['updatedOn'] / 1000 )) . 'T' . date('H:i:s', round($story['updatedOn'] / 1000 )) . '.000Z' . "' ";
$upd .= "WHERE id=".$existingId;
$result = $db->query($upd);
$ctr2++;
}
}
response(200, ['success' => true, 'inserted' => $ctr1, 'updated' => $ctr2, 'lastrun'=> date('m/d/Y H:i:s') ]);
}
//**********************************************************************************************************//
// Method: GET
// Endpoint: news/rotary
function get_v1_news_phstc( $args, $body, $uid, $admin_level, $db )
{
$url = 'https://www.pennhillsstc.org/news-articles?format=json';
$useragent = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0';
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_USERAGENT, $useragent);
curl_setopt($handle, CURLOPT_REFERER, 'https://www.pennhillsstc.org');
$response = curl_exec($handle);
curl_close($handle);
$stories = json_decode($response, true);
$ctr1 = 0;
$ctr2 = 0;
//pp($stories['items']); exit;
foreach ($stories['items'] as $story) {
$existingId = qVal($db, "SELECT id FROM news WHERE ext_id='" . $story['fullUrl'] . "'");
if (!$existingId) {
$ins = "INSERT INTO news (`user_id`, `channel_id`, `image`, `headline`, `subhead`, `body`, `author`, `date_published`, `date_modified`, `ext_id`, `approved`) VALUES (";
$ins .= '1001, ';
$ins .= '2, ';
$ins .= "'".$story['assetUrl']."', ";
$ins .= "'" . formatHtml($story['title'], true) . "', ";
$ins .= "'" . formatHtml($story['excerpt'], true) . "', ";
$ins .= "'" . formatHtml($story['body'],'<a>') . "', ";
$ins .= "'" . formatHtml($story['author']['displayName'], true) . "', ";
$ins .= "'" . date('Y-m-d', round($story['addedOn'] / 1000 )) . 'T' . date('H:i:s', round($story['addedOn'] / 1000 )) . '.000Z' . "', ";
$ins .= "'" . date('Y-m-d', round($story['updatedOn'] / 1000 )) . 'T' . date('H:i:s', round($story['updatedOn'] / 1000 )) . '.000Z' . "', ";
$ins .= "'" . $story['fullUrl'] . "', ";
$ins .= "1";
$ins .= ")";
//echo $ins."\n\n";
$result = $db->query($ins);
$newId = qVal($db, "SELECT MAX(id) FROM news WHERE approved=1");
sendpush($story['title'], $story['excerpt'], 'news/detaildeep/'.$newId);
$ctr1++;
}
else {
$upd = "UPDATE news SET ";
$upd .= "`image`='".$story['assetUrl']."', ";
$upd .= "`headline`='".formatHtml($story['title'], true)."', ";
$upd .= "`subhead`='".formatHtml($story['excerpt'], true)."', ";
$upd .= "`body`='".formatHtml($story['body'],'<p><a><img>')."', ";
$upd .= "`author`='".formatHtml($story['author']['displayName'], true)."', ";
$upd .= "`ext_id`='".$story['fullUrl']."', ";
$upd .= "`date_published`='" . date('Y-m-d', round($story['addedOn'] / 1000 )) . 'T' . date('H:i:s', round($story['addedOn'] / 1000 )) . '.000Z' . "', ";
$upd .= "`date_modified`='" . date('Y-m-d', round($story['updatedOn'] / 1000 )) . 'T' . date('H:i:s', round($story['updatedOn'] / 1000 )) . '.000Z' . "' ";
$upd .= "WHERE id=".$existingId;
$result = $db->query($upd);
$ctr2++;
}
}
response(200, ['success' => true, 'inserted' => $ctr1, 'updated' => $ctr2, 'lastrun'=> date('m/d/Y H:i:s') ]);
}
//**********************************************************************************************************//
// Method: GET
// Endpoint: news/rotary
function get_v1_news_arbpa( $args, $body, $uid, $admin_level, $db )
{
$url = 'https://www.arbpa.org/news?format=json';
$useragent = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0';
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_USERAGENT, $useragent);
curl_setopt($handle, CURLOPT_REFERER, 'https://www.arbpa.org');
$response = curl_exec($handle);
curl_close($handle);
$stories = json_decode($response, true);
$ctr1 = 0;
$ctr2 = 0;
foreach ($stories['items'] as $story) {
$existingId = qVal($db, "SELECT id FROM news WHERE ext_id='" . $story['fullUrl'] . "'");
if (!$existingId) {
$ins = "INSERT INTO news (`user_id`, `channel_id`, `image`, `headline`, `subhead`, `body`, `author`, `date_published`, `date_modified`, `ext_id`, `approved`) VALUES (";
$ins .= '1001, ';
$ins .= '12, ';
$ins .= "'".$story['assetUrl']."', ";
$ins .= "'" . formatHtml($story['title'], true) . "', ";
$ins .= "'" . formatHtml($story['excerpt'], true) . "', ";
$ins .= "'" . formatHtml($story['excerpt'], true) . "', ";
$ins .= "'ARBPA', ";
$ins .= "'" . date('Y-m-d', round($story['addedOn'] / 1000 )) . 'T' . date('H:i:s', round($story['addedOn'] / 1000 )) . '.000Z' . "', ";
$ins .= "'" . date('Y-m-d', round($story['updatedOn'] / 1000 )) . 'T' . date('H:i:s', round($story['updatedOn'] / 1000 )) . '.000Z' . "', ";
$ins .= "'" . $story['fullUrl'] . "', ";
$ins .= "1";
$ins .= ")";
$result = $db->query($ins);
$newId = qVal($db, "SELECT MAX(id) FROM news WHERE approved=1");
sendpush($story['title'], $story['excerpt'], 'news/detaildeep/'.$newId);
$ctr1++;
}
else {
$upd = "UPDATE news SET ";
$upd .= "`image`='".$story['assetUrl']."', ";
$upd .= "`headline`='".formatHtml($story['title'], true)."', ";
$upd .= "`subhead`='".formatHtml($story['excerpt'], true)."', ";
$upd .= "`body`='".formatHtml($story['excerpt'], true)."', ";
$upd .= "`author`='ARBPA', ";
$upd .= "`channel_id`=12, ";
$upd .= "`ext_id`='".$story['fullUrl']."', ";
$upd .= "`date_published`='" . date('Y-m-d', round($story['addedOn'] / 1000 )) . 'T' . date('H:i:s', round($story['addedOn'] / 1000 )) . '.000Z' . "', ";
$upd .= "`date_modified`='" . date('Y-m-d', round($story['updatedOn'] / 1000 )) . 'T' . date('H:i:s', round($story['updatedOn'] / 1000 )) . '.000Z' . "' ";
$upd .= "WHERE id=".$existingId;
$result = $db->query($upd);
$ctr2++;
}
}
response(200, ['success' => true, 'inserted' => $ctr1, 'updated' => $ctr2, 'lastrun'=> date('m/d/Y H:i:s') ]);
}
//**********************************************************************************************************//
// Method: GET
// Endpoint: news/repjoe
function get_v1_news_repjoe($args, $body, $uid, $admin_level, $db)
{
$xmlUrl = 'https://www.pahouse.com/Handlers/rss.ashx?e=42&cID=latestNews';
$xml = fetchXml($xmlUrl);
$array = xmlToArray($xml);
$ctr = 0;
$ctr2 = 0;
//pp($array); exit;
foreach ($array as $story) {
$existingId = qVal($db, "SELECT id FROM news WHERE ext_id='" . $story['link'] . "'");
if (!$existingId) {
$ins = "INSERT INTO news (`user_id`, `channel_id`, `image`, `headline`, `subhead`, `body`, `author`, `date_published`, `date_modified`, `ext_url`, `ext_id`, `approved`) VALUES (";
$ins .= '1001, ';
$ins .= '15, ';
$ins .= "'".$story['image_url']."', ";
$ins .= "'" . formatHtml($story['title'], true) . "', ";
$ins .= "'" . formatHtml($story['description_text'], true) . "', ";
$ins .= "'', ";
$ins .= "'" . formatHtml($story['creator'], true) . "', ";
$ins .= "'" . convertJoeDate($story['pubDate']) . "', ";
$ins .= "'" . convertJoeDate($story['pubDate']) . "', ";
$ins .= "'" . $story['link'] . "', ";
$ins .= "'" . $story['link'] . "', ";
$ins .= "1";
$ins .= ")";
$result = $db->query($ins);
$newId = qVal($db, "SELECT MAX(id) FROM news WHERE approved=1");
sendpush($story['title'], $story['description_text'], 'news/detaildeep/'.$newId);
$ctr++;
//echo '<p>'.$ins.'</p>';
}
else {
$upd = "UPDATE news SET ";
$upd .= "`image`='".$story['image_url']."', ";
$upd .= "`headline`='".formatHtml($story['title'], true)."', ";
$upd .= "`subhead`='".formatHtml($story['description_text'], true)."', ";
$upd .= "`author`='".formatHtml($story['creator'], true)."', ";
$upd .= "`ext_id`='".$story['link']."', ";
$upd .= "`ext_url`='".$story['link']."', ";
$upd .= "`date_published`='" . convertJoeDate($story['pubDate']) . "', ";
$upd .= "`date_modified`='" . convertJoeDate($story['pubDate']) . "' ";
$upd .= "WHERE id=".$existingId;
$result = $db->query($upd);
$ctr2++;
}
}
response(200, ['success' => true, 'inserted' => $ctr, 'updated' => $ctr2, 'lastrun'=> date('m/d/Y H:i:s') ]);
}
//**********************************************************************************************************//
// Method: GET
// Endpoint: news/munipets
function get_v1_news_munipets($args, $body, $uid, $admin_level, $db)
{
$jsonUrl = "https://fetchrss.com/rss/6761fc28ae1e40d7780731a26761fc13361f178971097e92.json";
$posts = json_decode(file_get_contents($jsonUrl), true);
$posts = pull_facebook_images($posts['items']);
$ctr = 0;
$ctr2 = 0;
//pp($posts); exit;
foreach ($posts as $story) {
$path = parse_url($story['link'], PHP_URL_PATH);
$segments = explode('/', rtrim($path, '/'));
$fbId = "".end($segments);
$ext_id = 'fb'.end($segments);
if (stristr($story['description'], 'Lost Dog')) {
$existingId = qVal($db, "SELECT id FROM news WHERE ext_id='" .$ext_id . "'");
if (empty($story['images']) || !count($story['images'])) {
$images = ['https://pennhillspassport.com/news/muni-default-image.jpg'];
} else {
$images = array_unique($story['images']);
for ($i = 0; $i < count($images); $i++) {
$images[$i] = save_facebook_image($images[$i]);
}
}
$title = formatHtml($story['description'], true);
$body = formatHtml($story['description'], true);
$body .= '<p><a href="'.$story['link'].'"><b>Visit the Facebook post for more info >></b></a></p>';
if ($images[0] !== 'https://pennhillspassport.com/news/muni-default-image.jpg') {
for ($i=0; $i<count($images); $i++) {
$body .= '<p><img src="'.$images[$i].'" style="max-width:100%;" /></p>';
}
$body .= '<p><a href="'.$story['link'].'"><b>Visit Facebook for more info and discussion >></b></a></p>';
}
if (!$existingId) {
$ins = "INSERT INTO news (`user_id`, `channel_id`, `feed`, `image`, `headline`, `subhead`, `body`, `author`, `date_published`, `date_modified`, `ext_url`, `ext_id`, `approved`) VALUES (";
$ins .= '1001, ';
$ins .= '22, ';
$ins .= '3, ';
$ins .= "'".$images[0]."', ";
$ins .= "'" . $title . "', "; // headline
$ins .= "'', "; // subhead
$ins .= "'" . $body . "', "; // body
$ins .= "'Penn Hills Police Dept.', "; // author
$ins .= "'" . convertToISO($story['pubDate']) . "', "; // published
$ins .= "'" . convertToISO($story['pubDate']) . "', "; // modified
$ins .= "'', "; // ext_url
$ins .= "'" . $ext_id . "', "; // ext_id
$ins .= "1";
$ins .= ")";
$result = $db->query($ins);
$newId = qVal($db, "SELECT MAX(id) FROM news WHERE approved=1");
sendpush('Lost Dog', $title, 'news/detaildeep/'.$newId);
$ctr++;
//echo '<p>'.$ins.'</p>';
}
else {
$upd = "UPDATE news SET ";
$upd .= "`image`='".$images[0]."', ";
$upd .= "`headline`='".$title."', ";
$upd .= "`body`='".$body."', ";
$upd .= "`author`='Penn Hills Police Dept.', ";
$upd .= "`image`='".$images[0]."', ";
$upd .= "`ext_id`='".$ext_id."', ";
$upd .= "`ext_url`='', ";
$upd .= "`date_published`='" . convertToISO($story['pubDate']) . "', ";
$upd .= "`date_modified`='" . convertToISO($story['pubDate']) . "' ";
$upd .= "WHERE id=".$existingId;
$result = $db->query($upd);
$ctr2++;
}
}
}
response(200, ['success' => true, 'inserted' => $ctr, 'updated' => $ctr2, 'lastrun'=> date('m/d/Y H:i:s') ]);
}
//**********************************************************************************************************//
// Method: GET
// Endpoint: news/penndot
function get_v1_news_penndot($args, $body, $uid, $admin_level, $db)
{
$jsonUrl = "https://platform.cloud.coveo.com/rest/search/v2?organizationId=commonwealthofpennsylvaniaproductiono8jd9ckm";
$useragent = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0';
$token = 'xx4e57cda9-3464-437d-9375-b947ca6b72c8';
$data = [
'q' => '"penn hills"',
'sortCriteria' => '@copapwpeffectivedate descending',
'searchHub' => 'PennDot-News',
'firstResult' => 0,
'numberOfResults' => 15,
];
$jsonData = json_encode($data);
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $jsonUrl);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_USERAGENT, $useragent);
curl_setopt($handle, CURLOPT_REFERER, 'https://www.pa.gov/');
curl_setopt($handle, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($handle, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token,
'Content-Type: application/json'
]);
$json = curl_exec($handle);
curl_close($handle);
$parsed = json_decode($json, true);
$posts = $parsed['results'];
$ctr = 0;
$ctr2 = 0;
//pp($posts); exit;
foreach ($posts as $story) {
$story = $story['raw'];
$ext_id = 'penndot-' . $story['sysrowid'];
$existingId = qVal($db, "SELECT id FROM news WHERE ext_id='" . $ext_id . "'");
$url = $story['clickableuri'];
if (stristr($url, 'district-11')) {
if (!$existingId) {
$ins = "INSERT INTO news (`user_id`, `channel_id`, `feed`, `image`, `headline`, `subhead`, `body`, `author`, `date_published`, `date_modified`, `ext_url`, `ext_id`, `approved`) VALUES (";
$ins .= '1001, ';
$ins .= '20, ';
$ins .= '1, ';
$ins .= "'https://pennhillspassport.com/news/197407-473452-img-3980.jpg', ";
$ins .= "'" . $story['copapwppagetitle'] . "', "; // headline
$ins .= "'', "; // subhead
$ins .= "'', "; // body
$ins .= "'PennDOT', "; // author
$ins .= "'" . convertUnixToISO($story['date']/1000) . "', "; // published
$ins .= "'" . convertUnixToISO($story['date']/1000) . "', "; // modified
$ins .= "'" . $url . "', "; // ext_url
$ins .= "'" . $ext_id . "', "; // ext_id
$ins .= "1";
$ins .= ")";
//echo $ins."\n\n<p>";
$result = $db->query($ins);
$newId = qVal($db, "SELECT MAX(id) FROM news WHERE approved=1");
sendpush($story['copapwppagetitle'], '', 'news/detaildeep/' . $newId);
$ctr++;
} else {
$upd = "UPDATE news SET ";
//$upd .= "`image`='" . $images[0] . "', ";
$upd .= "`headline`='" . $story['copapwppagetitle'] . "', ";
$upd .= "`body`='', ";
$upd .= "`author`='PennDOT', ";
$upd .= "`ext_id`='" . $ext_id . "', ";
$upd .= "`ext_url`='" . $url . "', ";
$upd .= "`date_published`='" . convertUnixToISO($story['date']/1000) . "', ";
$upd .= "`date_modified`='" . convertUnixToISO($story['date']/1000) . "' ";
$upd .= "WHERE id=" . $existingId;
$result = $db->query($upd);
$ctr2++;
}
}
}
response(200, ['success' => true, 'inserted' => $ctr, 'updated' => $ctr2, 'lastrun'=> date('m/d/Y H:i:s') ]);
}
//**********************************************************************************************************//
// Method: GET
// Endpoint: news/phfdno7
function get_v1_news_phfdno7($args, $body, $uid, $admin_level, $db)
{
$jsonUrl = "http://fetchrss.com/rss/6761fc28ae1e40d7780731a267bdcbc77968cbd93f007ec2.json";
$posts = json_decode(file_get_contents($jsonUrl), true);
$posts = pull_facebook_images($posts['items']);
$ctr = 0;
$ctr2 = 0;
$posts2 = [];
foreach ($posts as $post) {
if (stristr($post['description'], 'units:')
|| stristr($post['description'], 'incident')
|| stristr($post['description'], 'donations')
|| stristr($post['description'], 'donate')) {
$posts2[] = $post;
}
}
//pp($posts2); exit;
foreach ($posts2 as $story) {
$path = parse_url($story['link'], PHP_URL_PATH);
$segments = explode('/', rtrim($path, '/'));
$fbId = "".end($segments);
$ext_id = 'phfd-fb-'.end($segments);
$existingId = qVal($db, "SELECT id FROM news WHERE ext_id='" .$ext_id . "'");
if (empty($story['images']) || !count($story['images'])) {
$images = ['https://pennhillspassport.com/news/phfd-default.jpg'];
} else {
$images = array_unique($story['images']);
for ($i = 0; $i < count($images); $i++) {
$images[$i] = save_facebook_image($images[$i]);
}
}
$title = formatHtml($story['description'], true);
$body = '<p>'.formatHtml($story['description'], '<p><br>').'</p>';
$body = nl2br($body);
$position = strpos($body, "We are always accepting applications");
if ($position !== false) {
$body = substr($body, 0, $position); // Keep everything before the search text
$body .= '</p>';
}
$body .= '<p><a href="'.$story['link'].'"><b>Visit Facebook for more info and discussion >></b></a></p>';
if ($images[0] !== 'https://pennhillspassport.com/news/phfd-default.jpg') {
for ($i=0; $i<count($images); $i++) {
$body .= '<p><img src="'.$images[$i].'" style="max-width:100%;" /></p>';
}
$body .= '<p><a href="'.$story['link'].'"><b>Visit Facebook for more info and discussion >></b></a></p>';
}
$body = str_replace('•','•',$body);
$body = str_replace('•','• ',$body);
if (!$existingId) {
$title = str_replace('"','',chatgpt_post_title($title));
$ins = "INSERT INTO news (`user_id`, `channel_id`, `feed`, `image`, `headline`, `subhead`, `body`, `author`, `date_published`, `date_modified`, `ext_url`, `ext_id`, `approved`) VALUES (";
$ins .= '1001, ';
$ins .= '24, ';
$ins .= '1, ';
$ins .= "'".$images[0]."', ";
$ins .= "'" . $title . "', "; // headline
$ins .= "'', "; // subhead
$ins .= "'" . $body . "', "; // body
$ins .= "'Penn Hills No.7 VFC', "; // author
$ins .= "'" . convertToISO($story['pubDate']) . "', "; // published
$ins .= "'" . convertToISO($story['pubDate']) . "', "; // modified
$ins .= "'', "; // ext_url
$ins .= "'" . $ext_id . "', "; // ext_id
$ins .= "1";
$ins .= ")";
$result = $db->query($ins);
$newId = qVal($db, "SELECT MAX(id) FROM news WHERE approved=1");
sendpush($title, substr($body,0,85).'...', 'news/detaildeep/'.$newId);
$ctr++;
//echo '<p>'.$ins.'</p>';
}
else {
$upd = "UPDATE news SET ";
$upd .= "`body`='".$body."', ";
$upd .= "`author`='Penn Hills No.7 VFC', ";
$upd .= "`ext_id`='".$ext_id."', ";
$upd .= "`ext_url`='', ";
$upd .= "`date_published`='" . convertToISO($story['pubDate']) . "', ";
$upd .= "`date_modified`='" . convertToISO($story['pubDate']) . "' ";
$upd .= "WHERE id=".$existingId;
$result = $db->query($upd);
$ctr2++;
}
}
response(200, ['success' => true, 'inserted' => $ctr, 'updated' => $ctr2, 'lastrun'=> date('m/d/Y H:i:s') ]);
}