#!/usr/bin/env python

import sys
import os


try:
  # tentando usar o pacote instalado
  from bbvisa2ofx import bbvisa2ofx
except:
  # nao rolou, tentando carregar o pacote do src
  sys.path.insert (0,os.path.dirname(os.path.abspath(__file__))+"/..")
  from bbvisa2ofx import bbvisa2ofx

def main():
	args = sys.argv
	if(len(args) >= 2):
		pathTxt = sys.argv[1]
		if(not os.path.isfile(pathTxt)):
			print "File not found: %s" % pathTxt
		else:
			fileTxt = open(pathTxt,'r')
			fileOfx = open(pathTxt + ".ofx",'w')
			bbvisa2ofx.convert(fileTxt,fileOfx)
  	else:
		print "USO: bbvisa2ofx <caminho para arquivo a ser convertido>"



if __name__ == '__main__':
  main()
