Company directory using SecurePass
#!/usr/bin/python | |
## | |
## Company directory information with SecurePass | |
## Outputs Mediawiki compatible | |
## | |
## (c) 2014 Giuseppe Paterno' (gpaterno@gpaterno.com) | |
## GARL Sagl (www.garl.ch) | |
## | |
import os, sys | |
import logging | |
from optparse import OptionParser | |
import utils | |
import securepass | |
from collections import OrderedDict | |
## Logging format | |
FORMAT = '%(asctime)-15s %(levelname)s: %(message)s' | |
logging.basicConfig(format=FORMAT, level=logging.INFO) | |
## Load config | |
config = utils.loadConfig() | |
## Config the handler | |
sp_handler = securepass.SecurePass(app_id=config['app_id'], | |
app_secret=config['app_secret'], | |
endpoint=config['endpoint']) | |
## Set the realm/domain | |
REALM="mydomain.com" | |
try: | |
## Start table | |
print "{|" | |
print "! Surname Name\n! E-mail\n! Telephone" | |
print "|-" | |
## Get users in a dict for sort as surname | |
allusers = dict() | |
for user in sp_handler.user_list(realm=REALM): | |
user_detail = sp_handler.user_info(user=user) | |
allusers[user] = user_detail['surname'] | |
users_sorted_by_value = OrderedDict(sorted(allusers.items(), key=lambda x: x[1])) | |
employees = 0 | |
## Iterate users | |
for user in users_sorted_by_value.keys(): | |
user_detail = sp_handler.user_info(user=user) | |
user_link = user.split("@")[0] | |
print "| [[User:%s|%s %s]]" % (user_link, user_detail['surname'], user_detail['name']) | |
print "| [mailto:%s %s] " % (user_detail['email'], user_detail['email']) | |
print "| %s " % user_detail['mobile'] | |
employees = employees + 1 | |
if employees%2==1: | |
print '|- style="background: #EDEDED;"' | |
else: | |
print "|-" | |
# End table | |
print "|}" | |
print "Total headcount: '''%s'''" % employees | |
except Exception as e: | |
print e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment