import Quandl
import pandas as pd
import numpy as np
import blaze as bz

"""
Explanation: Introduction
Simply the first step to prepare the data for the following notebooks
End of explanation
"""


with open('../.quandl_api_key.txt', 'r') as f:
    api_key = f.read()

db = Quandl.get("EOD/DB", authtoken=api_key)
bz.odo(db['Rate'].reset_index(), '../data/db.bcolz')

fx = Quandl.get("CURRFX/EURUSD", authtoken=api_key)
bz.odo(fx['Rate'].reset_index(), '../data/eurusd.bcolz')

"""
Explanation: Data source is http://www.quandl.com.
We use blaze to store data.
End of explanation
"""


bz.odo('../data/db.bcolz', 'sqlite:///osqf.db::db')

%load_ext sql

%%sql sqlite:///osqf.db
select * from db

"""
Explanation: Can also migrate it to a sqlite database
End of explanation
"""


d = bz.Data('../data/db.bcolz')
d.Close.max()

"""
Explanation: Can perform queries
End of explanation
"""


