Skip to content

Instantly share code, notes, and snippets.

@lov3catch
Created November 7, 2014 15:19
Show Gist options
  • Save lov3catch/cdcb6b310bc122f67426 to your computer and use it in GitHub Desktop.
Save lov3catch/cdcb6b310bc122f67426 to your computer and use it in GitHub Desktop.
OANDA
#coding: utf-8;
__author__ = 'lov3catch'
from datetime import datetime
import time
import requests
currencies_optional = ['ADP', 'CZK', 'GBP']
args = dict(
key = 'HVKotzDshPBgK3HB5aCYavfx',
date = datetime.today().strftime("%Y-%m-%d"), # 2014-11-06
base = 'USD',
)
api_url = 'https://www.oanda.com/rates/api/v1/rates/{base}.json?api_key={key}&decimal_places=5&date={date}&fields=all&quote={optional}'
def save(txt):
print txt
with open('myfile', 'a+') as f:
f.write('{0}\n'.format(txt))
def make_request():
for currency in currencies_optional:
args.update({'optional': currency})
new_api_url= api_url.format(**args)
result = requests.get(new_api_url).json()
save(result)
while True:
print 'writing'
try:
make_request()
time.sleep(1800)
except:
print 'Error'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment