12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- #!/usr/bin/python3
- import argparse
- import configparser
- import psycopg2
- parser = argparse.ArgumentParser()
- parser.add_argument("selection", type=str,
- choices=["get-subscribers"])
- parser.add_argument("-c", "--config", type=str,
- default="/etc/fcn-toolbox/config.ini",
- help="specify a configuration file")
- parser.add_argument("--product", type=str,
- default="%",
- help="product code (can contain %)")
- args = parser.parse_args()
- config = configparser.RawConfigParser()
- config.sections()
- config.read(args.config)
- configdb = config['database']
- conn = psycopg2.connect(database=configdb['database'],
- user=configdb['user'], password=configdb['password'])
- cur = conn.cursor()
- def getMemberCount():
- cur.execute("SELECT count(*) FROM llx_adherent WHERE statut = '1'")
- return cur.fetchone()[0]
- def getSubscriberInfo(product, fields):
- fieldsel = ','.join(fields)
- cur.execute("""SELECT %s
- FROM llx_societe, llx_contrat, llx_contratdet, llx_product
- WHERE llx_societe.rowid=llx_contrat.fk_soc
- AND llx_contrat.rowid=llx_contratdet.fk_contrat
- AND llx_product.rowid=llx_contratdet.fk_product
- AND llx_product.ref LIKE %s
- AND llx_contrat.statut=1
- AND llx_contratdet.statut=4
- ORDER BY llx_product.ref, llx_contrat.rowid ASC;""" % (fieldsel, '%s'), (product, ))
- return cur.fetchall()
- if args.selection == "get-subscribers":
- subscribers = getSubscriberInfo(args.product, ['llx_societe.email'])
- print("\n".join(map(lambda x: x[0], subscribers)))
|