fcn-dolibarr 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  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"])
  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.sections()
  18. config.read(args.config)
  19. configdb = config['database']
  20. conn = psycopg2.connect(database=configdb['database'],
  21. user=configdb['user'], password=configdb['password'], host=configdb['host'])
  22. doli = dolibarr.Instance(conn)
  23. if args.selection == "get-adherents":
  24. adherents = doli.get_adherent(fields = ['email'])
  25. print("\n".join(map(lambda x: x[0], adherents)))
  26. elif args.selection == "get-subscribers":
  27. subscribers = doli.get_subscriber(args.product, ['email'])
  28. print("\n".join(map(lambda x: x[0], subscribers)))