# Path: intuition/constants.py
# FINANCE_URLS = {
#     'yahoo_hist': 'http://ichart.yahoo.com/table.csv',
#     'yahoo_infos': 'http://finance.yahoo/q/pr',
#     'google_prices': 'http://www.google.com/finance/getprices',
#     'snapshot_google_light': 'http://www.google.com/finance/info',
#     'info_lookup': ('http://d.yimg.com/autoc.finance.yahoo.com/autoc?' +
#                     'query={}&callback=YAHOO.Finance.SymbolSuggest.ssCallback')
# }
# 
# Path: intuition/data/utils.py
# def use_google_symbol(fct):
#     '''
#     Removes ".PA" or other market indicator from yahoo symbol
#     convention to suit google convention
#     '''
#     def decorator(symbols):
#         google_symbols = []
# 
#         # If one symbol string
#         if isinstance(symbols, str):
#             symbols = [symbols]
# 
#         symbols = sorted(symbols)
#         for symbol in symbols:
#             dot_pos = symbol.find('.')
#             google_symbols.append(
#                 symbol[:dot_pos] if (dot_pos > 0) else symbol)
# 
#         data = fct(google_symbols)
#         #NOTE Not very elegant
#         data.columns = [s for s in symbols if s.split('.')[0] in data.columns]
#         return data
#     return decorator
# 
# def invert_dataframe_axis(fct):
#     '''
#     Make dataframe index column names,
#     and vice et versa
#     '''
#     def inner(*args, **kwargs):
#         df_to_invert = fct(*args, **kwargs)
#         return pd.DataFrame(df_to_invert.to_dict().values(),
#                             index=df_to_invert.to_dict().keys())
#     return inner
# 
# def apply_mapping(raw_row, mapping):
#     '''
#     Override this to hand craft conversion of row.
#     '''
#     row = {target: mapping_func(raw_row[source_key])
#            for target, (mapping_func, source_key)
#            in mapping.fget().items()}
#     return row


import json
import requests
import pandas as pd
import dna.logging
from pandas.io.data import DataReader, get_quote_yahoo
from intuition.constants import FINANCE_URLS
from intuition.data.utils import (
    use_google_symbol, invert_dataframe_axis, apply_mapping)

    return pd.DataFrame(snapshot)


@property
def google_light_mapping():
    return {
        'change': (str, 'c'),
        'str_change': (str, 'ccol'),
        'perc_change': (float, 'cp'),
        'exchange': (str, 'e'),
        'id': (int, 'id'),
        'price': (str, 'l'),
        'last_price': (lambda x: x, 'l_cur'),
        'date': (str, 'lt'),
        'time': (str, 'ltt'),
        's': (int, 's'),
        'symbol': (str, 't'),
    }


def lookup_symbol(company):
    ''' Fetch company info
    >>> lookup_symbol("Apple Inc.")
          {u'exch': u'NMS',
           u'market': u'NASDAQ',
           u'name': u'Apple Inc.',
           u'symbol': u'AAPL',
           u'type': u'Equity'}
    '''

# Path: intuition/constants.py
# FINANCE_URLS = {
#     'yahoo_hist': 'http://ichart.yahoo.com/table.csv',
#     'yahoo_infos': 'http://finance.yahoo/q/pr',
#     'google_prices': 'http://www.google.com/finance/getprices',
#     'snapshot_google_light': 'http://www.google.com/finance/info',
#     'info_lookup': ('http://d.yimg.com/autoc.finance.yahoo.com/autoc?' +
#                     'query={}&callback=YAHOO.Finance.SymbolSuggest.ssCallback')
# }
# 
# Path: intuition/data/utils.py
# def use_google_symbol(fct):
#     '''
#     Removes ".PA" or other market indicator from yahoo symbol
#     convention to suit google convention
#     '''
#     def decorator(symbols):
#         google_symbols = []
# 
#         # If one symbol string
#         if isinstance(symbols, str):
#             symbols = [symbols]
# 
#         symbols = sorted(symbols)
#         for symbol in symbols:
#             dot_pos = symbol.find('.')
#             google_symbols.append(
#                 symbol[:dot_pos] if (dot_pos > 0) else symbol)
# 
#         data = fct(google_symbols)
#         #NOTE Not very elegant
#         data.columns = [s for s in symbols if s.split('.')[0] in data.columns]
#         return data
#     return decorator
# 
# def invert_dataframe_axis(fct):
#     '''
#     Make dataframe index column names,
#     and vice et versa
#     '''
#     def inner(*args, **kwargs):
#         df_to_invert = fct(*args, **kwargs)
#         return pd.DataFrame(df_to_invert.to_dict().values(),
#                             index=df_to_invert.to_dict().keys())
#     return inner
# 
# def apply_mapping(raw_row, mapping):
#     '''
#     Override this to hand craft conversion of row.
#     '''
#     row = {target: mapping_func(raw_row[source_key])
#            for target, (mapping_func, source_key)
#            in mapping.fget().items()}
#     return row


# Path: intuition/data/remote.py
import json
import requests
import pandas as pd
import dna.logging
from pandas.io.data import DataReader, get_quote_yahoo
from intuition.constants import FINANCE_URLS
from intuition.data.utils import (
    use_google_symbol, invert_dataframe_axis, apply_mapping)


    return pd.DataFrame(snapshot)


@property
def google_light_mapping():
    return {
        'change': (str, 'c'),
        'str_change': (str, 'ccol'),
        'perc_change': (float, 'cp'),
        'exchange': (str, 'e'),
        'id': (int, 'id'),
        'price': (str, 'l'),
        'last_price': (lambda x: x, 'l_cur'),
        'date': (str, 'lt'),
        'time': (str, 'ltt'),
        's': (int, 's'),
        'symbol': (str, 't'),
    }


def lookup_symbol(company):
    ''' Fetch company info
    >>> lookup_symbol("Apple Inc.")
          {u'exch': u'NMS',
           u'market': u'NASDAQ',
           u'name': u'Apple Inc.',
           u'symbol': u'AAPL',
           u'type': u'Equity'}
    '''

    request = requests.get(FINANCE_URLS['info_lookup'].format(company))