Browse Source

add json version of adhcount (dump and update adherents and members counters)

Sebastien Badia 11 years ago
parent
commit
850a58174b
1 changed files with 26 additions and 0 deletions
  1. 26 0
      adhcount-json.py

+ 26 - 0
adhcount-json.py

@@ -0,0 +1,26 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+# https://gitorious.org/dolicount/
+
+import sys, os, json
+import MySQLdb
+
+info = '/path/to/your/web/directory/info.json'
+data = json.loads(open(info).read())
+
+connection = MySQLdb.connect(host = "localhost", user = "user", passwd = "password", db = "dolibarr_database")
+cursor = connection.cursor()
+cursor.execute("SELECT COUNT(*) FROM llx_adherent WHERE statut = '1'")
+row = cursor.fetchone()
+data['subscriberCount'] = row[0]
+cursor.execute("SELECT COUNT(*) FROM llx_societe WHERE status = '1' AND client='1'")
+row = cursor.fetchone()
+data['memberCount'] = row[0]
+
+with open(info, 'w') as outfile:
+  json.dump(data, outfile)
+
+cursor.close()
+connection.close()
+sys.exit()
+