#!/usr/bin/env python
from  scarpkg import logStart, logStop, logMsg, Log, get_info, Bot
import sys
import getopt
Tid=''
logPath='/tmp'
verbose=False
Tinfo=''
import __main__
import os

def get_arg(argv):
    try:
        opts, args = getopt.getopt(argv,"hm:i:I:l:v",["message=","id=","log=","verbose=","info="])
    except getopt.GetoptError:
        print 'Tnotify -m "Message" -i "telegram_id"'
        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 'Tnotify -m "Message" -i "telegram_id"'
            print '-l <logpath> default /tmp '
            print '-v "verbose output and write to log"'
            sys.exit()
        elif opt in ("-i", "--id"):
            global Tid
            Tid = arg
        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)
    if not Tid:
        Tid = INFO['telegram']['id']
    my_bot=Bot(INFO['telegram']['token'],Tid,INFO['telegram']['user'])
    log.msg("Sending message : {0}".format(Tmsg))
    log.msg("To user {0}".format(INFO['telegram']['user']))
    my_bot.msg(Tmsg)
    log.stop()
    
