The Dayboro Events Data extraction Plan.

We want to promote the Dayboro Events to a broader community, this means we have to get our “hands” on the Dayboro Events Data which is stored in the database.

To post to social media we have two options, one is to visit the event post and publish it to social media. That is fun for the first few but it becomes boring very quickly. Needless to say that this will take up a lot of our time every day so it is time to automate a few things. 

The second option is to automate it. First, we have to understand that we have no “Coders” in the office. All coding is self-thought and will look like a bunch of “rubbish” in the eyes of more experienced coders. The plan is to make it as simple as possible, use as many “already existing” code and applications (plugins) to make this happen. We need to take into consideration that this automation needs to be as user friendly in the “backend” as possible. 

Now we got that out of the way, here we go

Social Media Posting Steps

The Code

We are no coders, nor do we claim we are. Feel free to comment and to provide pointers, all help is welcome. 

<?php

// Connect to database server to write clean the table and write new entries.
include(“xxxxxxxxServer.php”);
echo “<br />”;
echo “<br />”;
$temp = “truncate todaysevents;”;
if(!$result = $con->query($temp)){
die(‘There was an error running the query [‘ . $con->error . ‘]’);
}
echo “Done ” .$temp;
echo “<br />”;
echo “<br />”;
echo “<br />”;

// now the Database is empty it is time to get the info. We use today plus 2 days.
// that should get tomorrows events.
$startDate = date(‘Y-m-d’);
$addTimeToDate = date(‘Y-m-d’,strtotime(‘+2 day’,strtotime($startDate)));
$endDate = $addTimeToDate;
echo $startDate;
echo “<br />”;
echo $endDate;
echo “<br />”;

// use the API/JSON to collect the data.
// the dates are variables created above..
$jsonlink = “https://dayboroevents.com/wp-json/stec/v2/get/events/”.$startDate.”/”.$endDate;

echo $jsonlink;
echo “<br />”;
echo “<br />”;

// Read JSON file
$json = file_get_contents($jsonlink);

//Decode JSON
$json_data = json_decode($json,true);

// Loop through the json file to find all the events.
// We then get the Event?Status and the Eventlink to put into our database.
foreach($json_data as $elem) {
( $elem[‘data’]);
foreach ($elem[‘events’] as $events ) {
$EventStatus = ($events[‘event_status’]);
echo “Event Status “.$EventStatus;

$permalink = ($events[‘permalink’]);
echo ” this is the permalink “.$permalink;
echo(“<br/>”) ;

// database fields values are the values taken from the $filename content that is converted in the above section.
$sql = “INSERT INTO `todaysevents`(EventStatus, EventLink)
VALUES
(‘$EventStatus’, ‘$permalink’)”;
echo “Start Running Query”;
if(!$result = $con->query($sql)){
die(‘There was an error running the query [‘ . $con->error . ‘]’);

}

}
}

?>x

We have stuff in the DB.

Pretty excited, we now have Dayboro Events in our database. We have extracted from the plugin Database. 

The plugin Stachethemes Event Calendar is written pretty cleverly, from what we see it does not pollute the DataBase will include entries etc. On the other hand, that is what creates our “problem” to find the data in the back end. 

Thanks to the quick response cooperation from the plugin Author we can use their API and some of our “code” to retrieve the records we want in the format we want. 

Sure we could write the information to a TXT file. We decided just to put it in a separate database table. We are more familiar with that. 

This is what we are at, for now. 

Having this data in a database now gives us a few paths we can follow, we can use the data to pop-up in the Dayboro Directory on the Dayboro Weather site or even other areas like mail merge etc. 

As it so happens we just received an email from the Author of StacheThemes with an update API, we will incorporate the new API as it makes our code above a lot easier… Thanks GUYS. 

We do like to thank the Author(s) of the Stachethemes Event Calendar plugin, their support is fantastic and their response is very quick. 

They send us an email last night they made changes to the API, especially for us to incorporate our “requirements”. That is fantastic you do not get any of that with the big commercial “guys”.