Website - API automation

Web hosting, FTP/database access, mirror services and hosted blogs
Post Reply
Pfitzy
Posts: 78
Joined: Wed Dec 20, 2006 1:26 pm
Location: Sydney

Website - API automation

Post by Pfitzy » Fri Feb 19, 2016 7:00 am

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.
Friendly fire, isn't...

Pfitzy
Posts: 78
Joined: Wed Dec 20, 2006 1:26 pm
Location: Sydney

Re: Website - API automation

Post by Pfitzy » Mon Mar 14, 2016 1:39 pm

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.
Friendly fire, isn't...

User avatar
Dazzled
Volunteer Site Admin
Posts: 5997
Joined: Mon Nov 13, 2006 1:16 pm
Location: Sydney

Re: Website - API automation

Post by Dazzled » Mon Mar 14, 2016 5:00 pm

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/

Pfitzy
Posts: 78
Joined: Wed Dec 20, 2006 1:26 pm
Location: Sydney

Re: Website - API automation

Post by Pfitzy » Mon Mar 14, 2016 5:45 pm

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.
Friendly fire, isn't...

Pfitzy
Posts: 78
Joined: Wed Dec 20, 2006 1:26 pm
Location: Sydney

Re: Website - API automation

Post by Pfitzy » Tue Mar 15, 2016 12:50 pm

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.
Friendly fire, isn't...

User avatar
Kumudh
Forum Admin
Posts: 374
Joined: Thu Sep 26, 2013 3:55 pm
Location: Australia

Re: Website - API automation

Post by Kumudh » Tue Mar 15, 2016 2:12 pm

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

Post Reply