#!/usr/bin/env python

import bitso # put the package from https://github.com/bitsoex/bitso-py on your python env
import sys
from pprint import pprint
from  scarpkg import logStart, logStop, logMsg, Log, get_info, Bot
import getopt
import __main__
import os
from scarpkg.bitso_functions import get_bitso_balance
Tid=''
logPath='/tmp'
verbose=False
Tinfo=''
Tsilent=False

def get_arg(argv):
    try:
        opts, args = getopt.getopt(argv,"hm:sI:l:v",["message=","silent=","log=","verbose=","info="])
    except getopt.GetoptError:
        print 'bitso_balance -I <File_to_variables>'
        print '-l <logpath> default /tmp '
        print '-v "verbose output and write to log"'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'bitso_balance -I <File_to_variables>'
            print '-l <logpath> default /tmp '
            print '-v "verbose output and write to log"'
            sys.exit()
        elif opt in ("-s", "--silent"):
            global Tsilent
            Tsilent = True
        elif opt in ("-m", "--message"):
            global Tmsg
            Tmsg = arg
        elif opt in ("-l","--log"):
            global logPath
            logPath = arg
        elif opt in ("-I","--info"):
            global Tinfo
            Tinfo = arg
        elif opt in ("-v","--verbose"):
            global verbose
            verbose = 'yes'

if __name__ == "__main__":
    get_arg(sys.argv[1:])
    log = Log(logPath,verbose)
    INFO = get_info(Tinfo)
    
    Tmsg=get_bitso_balance(key=INFO['bitso']['key'],secret=INFO['bitso']['secret'])
    if not Tid:
        Tid = INFO['telegram']['id']
    if Tsilent:
        log.msg("Silent mode, not sending Telegram msg")
    else:
        my_bot=Bot(INFO['ScarCoin']['token'],Tid,INFO['ScarCoin']['user'])
        log.msg("Sendinf bitso information to user {0}".format(INFO['telegram']['user']))
        my_bot.msg(Tmsg)
    log.stop()
    sys.exit(0)

