Downloading data from API to database

Hi

I have a currency widget that updates currency rates every minute or so. For a number of reasons i would prefer to have just one or two updates daily.

is it possible to create an automatic database that updates the latest rate at a certain time daily, so that my page could then get the rate from MY database rather than querying the API?

How do I go about it?

question: what currency rate are you interested in? because the official exchange rate is set only once a (work) day. then it would suffice to run the API call at that time.

Hi Dormilich

All currencies!

In fact, currencies change by the second as buying and selling takes place.

I do have a Test widget that can choose any pair of cyrrencies, but my question now is whether I can create a database.

I assume, in ignorance, that I would have to:

  1. create a database
  2. write a php programme that would query the API once a day at a certain time, AUTOMATICALLY, and update the one and only data entry
  3. get the data entry from the webpage, with a php query?

Is that it, more or less, or is it not possible?

that’s correct, but there is only one official end-of-the-day exchange rate. for example, if you‘re looking for the exchange rate USD-EUR on 20-05-2015, there will only be one value (1.1118).

that’s what cronjobs are for. execute a script at predefined times (resp. intervals).

How could I find out how to write one (Ive never touched or understood php…)?´

Are there ready to use examples?

cronjobs are an OS service. it has nothing to do with PHP at all.

Could you point me in the right direction to try and get something started, please?

Thanks

the above link doesn’t suffice? or are you on Windows (see http://stackoverflow.com/questions/132971/what-is-the-windows-version-of-cron)?

Hi

i didn’t realize cron was a link…

So, I need to

create a database at the server
create a cron file (but if it is to reside in the server, why the question of whether my PC runs on Windows? It does)
have a script (php?) to downloasd the data from the Api
access the data from the webpage

is that it?

  1. the server might operate on Windows
  2. you have a dev environment using Windows

that script has to do all the work. i.e. download data, insert data into db, cleanup (if necessary)

and mind that PHP on CLI is not exactly the same as PHP as web server module/CGI.

On which door do I have to go and knock to get help on this, to get me started?

the Manual’s door: http://php.net/cli

That’s the Chinese version… or at least that’s what it seems.

Never mind, I’ll have a crack at it, slowly.

Thanks

Maybe what I call psuedo-cron would be good enough?
That is, if your site has enough traffic you can have the job run the first page load after an arbitrary time.
Pros - no real cron used
Cons - whoever triggers that job may get slower load times
the run time is not as precise

Hi Mittineague

Right now I’m trying to work out what is involved and your idea is very interesting.

It looks as if my first problem is to get a script to download the data to a database in the server. That should be very interesting as I know ABSOLUTELY NOTHING about php…

But maybe with some help from my friends…

What’s wrong with having a real cron once it gets sorted out?

Nothing. In fact that would be the preferred way.
If your host lets you do cron jobs IMHO that is how you should do it.

No matter how the script is initiated, you will need that.
I’d start with thinking about what information is available and what you might need to have in the database. i.e. the database schema

I’m talking about over 100 currencies, and starting to think if this makes sense. I already have a widget with that information that is updated EVERY TIME the page is opened. One of the reasons (there are others) for doing this database business is to get rid of a script in the page. But… in order for the widget, in future, to gather the necessary information in respect of a pair of currencies, I am starting to think that another script is needed.

I thought originally that the rates could be got directly from the database, but even if it is a page that deals with exchange between GBP and EUR, there is a drop-down list that allows any combination of over 100 currencies.

is this doable without scripts?

You could have a link to the source and let users find what they want from there.
Or you could create a static page every day.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.