adhcount-json.py 713 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. # https://gitorious.org/dolicount/
  4. import sys, os, json
  5. import MySQLdb
  6. info = '/path/to/your/web/directory/isp.json'
  7. data = json.loads(open(info).read())
  8. connection = MySQLdb.connect(host = "localhost", user = "user", passwd = "password", db = "dolibarr_database")
  9. cursor = connection.cursor()
  10. cursor.execute("SELECT COUNT(*) FROM llx_adherent WHERE statut = '1'")
  11. row = cursor.fetchone()
  12. data['memberCount'] = row[0]
  13. cursor.execute("SELECT COUNT(*) FROM llx_societe WHERE status = '1' AND client='1'")
  14. row = cursor.fetchone()
  15. data['subscriberCount'] = row[0]
  16. with open(info, 'w') as outfile:
  17. json.dump(data, outfile)
  18. cursor.close()
  19. connection.close()
  20. sys.exit()