gcconv 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/python
  2. # coding=utf-8
  3. """Convert bank statement CSV to GnuCash-importable CSV
  4. usage: gcconv [options] <format> <file>
  5. gcconv --list
  6. Options:
  7. -e, --encoding ENCODING input file encoding as understood by Python [default: utf-8]
  8. -l, --list list known formats
  9. --help show this screen
  10. --version show version
  11. """
  12. __VERSION__ = "gcconv 0.0.1"
  13. import sys
  14. import docopt
  15. import gcconv
  16. class App(object):
  17. """
  18. Main application
  19. """
  20. class UsageError(ValueError):
  21. """Usage error"""
  22. pass
  23. def __init__(self, args):
  24. self.args = args
  25. @classmethod
  26. def main(cls, args):
  27. """
  28. Main entry point
  29. """
  30. app = cls(args)
  31. app.run()
  32. def run(self):
  33. """
  34. Run the app (main entry point)
  35. """
  36. if self.args['--list']:
  37. print "\n".join(gcconv.valid_formats())
  38. sys.exit(0)
  39. print gcconv.convert_file(
  40. self.args['<file>'],
  41. self.args['<format>'],
  42. encoding=self.args['--encoding']
  43. )
  44. if __name__ == "__main__":
  45. App.main(docopt.docopt(__doc__, version=__VERSION__))