fcn-dolibarr 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/python3
  2. import argparse
  3. import configparser
  4. import psycopg2
  5. import fcntoolbox.dolibarr as dolibarr
  6. parser = argparse.ArgumentParser()
  7. parser.add_argument("selection", type=str,
  8. choices=["get-adherents", "get-subscribers", "get-bank-accounts", "get-users"])
  9. parser.add_argument("-c", "--config", type=str,
  10. default="/etc/fcntoolbox/config.ini",
  11. help="specify a configuration file")
  12. parser.add_argument("--product", type=str,
  13. default="%",
  14. help="product code (can contain %)")
  15. args = parser.parse_args()
  16. config = configparser.RawConfigParser()
  17. config.read(args.config)
  18. configdb = config['dolibarr']
  19. conn = psycopg2.connect(database=configdb['database'],
  20. user=configdb['user'], password=configdb['password'], host=configdb['host'])
  21. doli = dolibarr.Instance(conn)
  22. if args.selection == "get-adherents":
  23. adherents = doli.get_adherent(fields = ['email'])
  24. print("\n".join(map(lambda x: x[0], adherents)))
  25. elif args.selection == "get-subscribers":
  26. subscribers = doli.get_subscriber(args.product, ['email'])
  27. print("\n".join(map(lambda x: x[0], subscribers)))
  28. elif args.selection == "get-bank-accounts":
  29. accounts = doli.get_bank_accounts(fields=['iban_prefix'])
  30. print("\n".join(map(lambda x: x[0], accounts)))
  31. elif args.selection == "get-users":
  32. users = doli.get_users(fields = ['email'])
  33. print("\n".join(map(lambda x: ','.join(x), users)))