#!/usr/bin/env python

import sys
import os


try:
  # attempt to use the installed python package
  from bbvisa2ofx import bbvisa2ofx
except:
  # attempt to run the package from the source directory
  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 "USAGE: bbvisa2ofx <file to convert>"



if __name__ == '__main__':
  main()
