Page 1 of 1

Website - API automation

Posted: Fri Feb 19, 2016 7:00 am
by Pfitzy
Going to build a website (paid webspace), and pull stats from an API available to me in order to populate the database. I can't refresh the stats every time a user accesses the site because I have a limited number of API calls per day.

Does anyone know if I can access a scheduler to do this in the Exetel environment? e.g. cron? Would it be possible to set up something like this in WordPress?


Alternative:

1) Retrieve stats on page load, and save to database with a timestamp
2) On subsequent page loads, check age of timestamp and refresh as required.

But that is a little clunky. I'd prefer consistent updates as they make better graphs.

Re: Website - API automation

Posted: Mon Mar 14, 2016 1:39 pm
by Pfitzy
Hi can anyone help with this?

I have a page set up that will automatically run my scheduler, but it needs to be called from something other than the wp_cron.php which only activates when someone visits the site.

I've looked at options like pingdom and statuscake but don't actually want to pay $15 a month for the privilege of running one file.

Re: Website - API automation

Posted: Mon Mar 14, 2016 5:00 pm
by Dazzled
Can you script a running computer to periodically connect and collect the information, and then transfer it to the website file using ftp?

curl available for most systems, makes light work of the transfer, something along the lines of:
curl -T localfile.xyz ftp://username:password@ftp.server.com.au/remotedir/

Re: Website - API automation

Posted: Mon Mar 14, 2016 5:45 pm
by Pfitzy
I had thought about that, but it relies too much on the scripting PC being available. FTP is a clunkfest.

The code for GET requests to the API is written in the PHP function, and puts data directly into MySQL. Efficient.

If I had access to cron on the hosting service it would make life a lot easier.

Re: Website - API automation

Posted: Tue Mar 15, 2016 12:50 pm
by Pfitzy
Sorted in a couple of easy steps without the need for cron or the WordPress version of it:

1) Create a Google Sheet
2) Go to Tools | Script Editor - may need to sign in
3) Create a function as follows:

Code: Select all

function runThis() {
  var resp = UrlFetchApp.fetch("http://your_domain_here.com/your_folder/your.php");
}
4) Save script
5) From the script menu, click on Resources | Current project's triggers
6) Create a new trigger to run the function every X minutes as required

Runs even if your Google sheet is closed, or even your whole browser.

Mint.

Re: Website - API automation

Posted: Tue Mar 15, 2016 2:12 pm
by Kumudh
Pfitzy wrote:Sorted in a couple of easy steps without the need for cron or the WordPress version of it:

1) Create a Google Sheet
2) Go to Tools | Script Editor - may need to sign in
3) Create a function as follows:

Code: Select all

function runThis() {
  var resp = UrlFetchApp.fetch("http://your_domain_here.com/your_folder/your.php");
}
4) Save script
5) From the script menu, click on Resources | Current project's triggers
6) Create a new trigger to run the function every X minutes as required

Runs even if your Google sheet is closed, or even your whole browser.

Mint.

Hi Pfitzy,

Thank you for this valuable information. We will keep this for our reference as well.

Cheers,
Kumudh