import sys
import os
import time
import datetime
import pymqi

# Get Current Path
dir_path = os.path.dirname(os.path.realpath(__file__))

def read_file(file_name):
	file_path_map = os.path.join(dir_path, file_name)
	iDocMsg = open(file_path_map,"r")
	message = ""
	for line in iDocMsg:
		line = line.replace('\n','')
		message +=line
	iDocMsg.close()
	
	if sys.version_info[0] < 3:
		return str(message)
	else:
		return bytes(message, 'utf-8')
		
#	return message
		
def put_mq(message):

#	qmgr = pymqi.connect('VIMSRRI10', 'SYSTEM.DEF.SVRCONN', '172.18.21.5(1415)')

	queue_manager = 'VIMSRRI10'
	channel = 'SYSTEM.DEF.SVRCONN'
	host = '172.18.21.5'
	port = '1415'
#	queue_name = 'BMW.LSP_SHPCON.VIMS'
	queue_name = 'VIMS.LSP_ASN.BMW'
	conn_info = '%s(%s)' % (host, port)

	qmgr = pymqi.connect(queue_manager, channel, conn_info)

	pcf = pymqi.PCFExecute(qmgr)
		
	putq = pymqi.Queue(qmgr, queue_name)

	md = pymqi.MD()
	md.Format = pymqi.CMQC.MQFMT_STRING
	putq.put(message, md, None)

	putq.close()
	qmgr.disconnect()
	
message = read_file('idocoutdataout.txt')
if len(message) > 0:
	put_mq(message)
	
#	put_mq('C://MQ//myMessage.xml')