Created
November 7, 2014 15:19
-
-
Save lov3catch/cdcb6b310bc122f67426 to your computer and use it in GitHub Desktop.
OANDA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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"e={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