#!/usr/bin/env python
# -*- coding: utf-8 -*-
#***************************************************************************
#*    Pysmssend  ( Source Code )
#***************************************************************************
# This file is part of Pysmssend Project
#
#    Pysmssend Project is free software; you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation; either version 3 of the License, or
#     (at your option) any later version.
#
#    Pysmssend is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#     along with this program.  If not, see <http://www.gnu.org/licenses/>.

import sys,signal 
import os
import getopt
from mechanize import Browser 
from pysmssendmod.cmdfunc import *

SHAREDIR="/usr/share/pysmssend/"
TEMPDIR="/.pysmssend/"
verbose = False
foobar = Browser()
foobar.set_handle_robots(False)

try:
	o, a = getopt.getopt(sys.argv[1:], 'a:u:p:n:h:v',["help"])                            
	opts = {}
	for k,v in o:                                                             
		opts[k] = v
        	if k == "-v":
            		verbose = True
	        if k in ("-h", "--help"):
        	    usage()
        	    sys.exit()
	if len(opts) < 4:
		usage()
		if len(a) < 1: 
			sys.exit("No text specified.")
		else:
			sys.exit("Invalid number of parameters.")		
	else:
		if len(a) < 1: usage(); sys.exit("No text specified.")
		#Assign variables
		account = str.lower(opts["-a"])
		username = opts["-u"]
		password = opts["-p"]
		phone = opts["-n"]
		text = a[0]
		if len(text) > (145 - len(username)): sys.exit("Max characters allowed are (145-username) length.")
		leftcred=cmdlogin(account,username,password,verbose)
		sendsmscmd(account,username,password,phone,text,verbose,leftcred)
except getopt.GetoptError, msg:
    		usage()
		sys.exit("Invalid Option(s) specified")
