def get_quote(symbol):
    global debug
    # Download conid and quote from IB
    # Also, update count percentage
    if debug:
        log('Start %s' % symbol)
    try:
        global count_done
        global count_perc
        global count_total
        global dir_quote
        ret = {}
        c = Company(symbol)
        quote = c.get_quote(period='3d', bar='1d')
        count_done += 1
        if (count_done / count_total) * 10 >= count_perc:
            log(str(count_perc * 10) + '%')
            count_perc = count_perc + 1
        with open(dir_quote + '/' + symbol + '.json', 'w') as f:
            # Save quote to dir
            f.write(json.dumps(quote))
        if debug:
            log('End %s' % symbol)
        return {
            'symbol': symbol,
            'data': quote,
        }
    except Exception as e:
        # Failed to get conid, print the ticker
        raise Exception('symbol: %s: %s' % (symbol, e))
# Run as:  ./script.py TICKER
# Example: ./script.py AAPL

# OS
import argparse
import json
import os
import urllib3

# Local
import sys, os
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../'))
from lib.company import Company

# Config
urllib3.disable_warnings()

### MAIN ###
# Parse args
parser = argparse.ArgumentParser(
    description='Get quote for symbol')
parser.add_argument('symbol', metavar='SYMBOL', type=str,
    help='Symbol, e.g. AAPL')
args = parser.parse_args()
symbol = args.symbol

# Get quote
c = Company(symbol)
quote = c.get_quote(period='3d', bar='1d')
print(quote)