Periodically send request to https://free.currencyconverterapi.com without exceeding "Requests per Hour" limit and cache the result. Useful for application that don't need realtime and accurate conversion rate.
- Fullfill the pip requirements by doing:
pip install -r requirements.txt
- Make sure you have your own API key from https://free.currencyconverterapi.com
- Put your API key into
apikey.txt
file - Adjust your
baseCurrency
inconfig.py
- Adjust your
numberOfRequests
inconfig.py
. This will control how much request to be sent every timecreate_cache.py
run. For example, if I set a cron job to runcreate_cache.py
every 5 minutes, there will be 72 request sent in 1 hour (60 minutes / 5 minutes * 6 requests) which is still below the 100 requests per hour limit. Since each request will ask for 2 pairs of currency, 144 pairs will be updated every hour. - Run
update_currencies.py
to get all currencies offered by https://free.currencyconverterapi.com. You can remove currencies that you don't need fromcurrencies.json
.
Run create_cache.py
periodically (use script or cron job). In my case, I run it once every 5 minutes. Run app.py
to start the Flask server (or use passenger) to serve the cached result:
GET currency
will return all cached currenciesGET curerncy/XXX/YYY
will return the rate for XXX and YYY pair.