You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@community.apache.org by se...@apache.org on 2015/07/20 23:37:47 UTC
svn commit: r1692026 -
/comdev/projects.apache.org/scripts/cronjobs/countaccounts.py
Author: sebb
Date: Mon Jul 20 21:37:47 2015
New Revision: 1692026
URL: http://svn.apache.org/r1692026
Log:
COMDEV-146 - countaccounts.py can miss a days worth of new accounts
TODO fix up historic values
Modified:
comdev/projects.apache.org/scripts/cronjobs/countaccounts.py
Modified: comdev/projects.apache.org/scripts/cronjobs/countaccounts.py
URL: http://svn.apache.org/viewvc/comdev/projects.apache.org/scripts/cronjobs/countaccounts.py?rev=1692026&r1=1692025&r2=1692026&view=diff
==============================================================================
--- comdev/projects.apache.org/scripts/cronjobs/countaccounts.py (original)
+++ comdev/projects.apache.org/scripts/cronjobs/countaccounts.py Mon Jul 20 21:37:47 2015
@@ -50,7 +50,7 @@ N.B. The script currently only updates t
"""
import json;
-from datetime import datetime
+from datetime import datetime, timedelta
import subprocess
js = {}
@@ -59,12 +59,26 @@ with open("../../site/json/foundation/ac
f.close()
now = datetime.now() # fetch time once
+if len(sys.argv) > 3:
+ now = datetime(year=int(sys.argv[1]),month=int(sys.argv[2]), day=int(sys.argv[3]))
+ print("Overriding current time: %s" % now)
+
currentMonth = now.month
currentYear = now.year
ym = "%04u-%02u" % (currentYear, currentMonth)
tym = "%04u%02u" % (currentYear, currentMonth)
print("Looking for entries for %s" % tym)
js[ym] = 0
+# Potentially check for the previous month as well
+ym1 = None
+tym1 = None
+if now.day == 1: # Day one of month, redo previous month to ensure all new entries are seen
+ yesterday = now - timedelta(days = 1)
+ ym1 = "%04u-%02u" % (yesterday.year, yesterday.month)
+ tym1 = "%04u%02u" % (yesterday.year, yesterday.month)
+ print("Also looking for entries for %s" % tym1)
+ js[ym1] = 0
+
proc = subprocess.Popen(['ldapsearch','-x', '-LLL', '-b', 'ou=people,dc=apache,dc=org', 'createTimestamp'],stdout=subprocess.PIPE)
@@ -77,9 +91,15 @@ while True:
# createTimestamp: 20150330152151Z
if line.startswith("createTimestamp: %s" % tym):
js[ym] += 1
+ else:
+ if not tym1 == None:
+ if line.startswith("createTimestamp: %s" % tym1):
+ js[ym1] += 1
with open("../../site/json/foundation/accounts-evolution.json", "w") as f:
f.write(json.dumps(js, sort_keys=True, indent=0))
f.close()
-print("Done, found %u entries for this month" % js[ym])
\ No newline at end of file
+print("Done, found %u entries for this month" % js[ym])
+if not tym1 == None:
+ print("Also found %u entries for the previous month (%s)" % (js[ym1], tym1))