#!python
# -*- coding: UTF-8 -*-
##############################################
# Home	: http://netkiller.github.io
# Author: Neo <netkiller@msn.com>
##############################################
try:
	import requests, os, sys
	import logging, logging.handlers
	from configparser import ConfigParser
	from optparse import OptionParser, OptionGroup
	module = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
	sys.path.insert(0,module)
	from netkiller.wework import WeWork
except ImportError as err:
	print("Error: %s" %(err))

class Wechat():

	def __init__(self): 
		usage = "usage: %prog [options] message"
		self.parser = OptionParser(usage)
		self.parser.add_option("-c", "--config", dest="config", help="config file", default='/usr/local/etc/wechat.ini', metavar="/usr/local/etc/wechat.ini")
		# self.parser.add_option('-l','--logfile', dest='logfile', help='logs file.', default='/var/log/wechat.log', metavar='/var/log/wechat.log')
		self.parser.add_option('-t','--totag', dest='totag', help='tag', default='1',metavar='"1|2|3"')
		self.parser.add_option("", "--debug", action="store_true", dest="debug", help="debug mode")

		(options, args) = self.parser.parse_args()

		# if options.logfile :
			# self.logfile = options.logfile	
		# 	logging.basicConfig(level=logging.NOTSET,format='%(asctime)s %(levelname)-8s %(message)s',datefmt='%Y-%m-%d %H:%M:%S',
		# 	filename=options.logfile,filemode='a')

		# self.logging = logging.getLogger()

		if options.debug:
			print("="*50)
			print(options, args)
			print("="*50)

		if args :
			message = ' '.join(args)
			wework = WeWork(options.config)
			wework.sendTextMessage(options.totag, message)
			# print(message)
		else:
			self.usage()

	def usage(self):
		self.parser.print_help()
		print("\nHomepage: http://www.netkiller.cn\tAuthor: Neo <netkiller@msn.com>")
		exit()

if __name__ == '__main__':
	wechat = Wechat()