首页 > 代码库 > 根据部门和城市自动创建邮箱

根据部门和城市自动创建邮箱


#!/usr/bin/python

# coding:utf-8


import sys

sys.path.append(‘/sw/systems/shared/python‘)

from DB import DB

con,cur = DB().connect()


from Company import Company

company = Company()

users = company.employees

departments = company.departments

user_list = {}

for key in users:

    city = users[key][‘location_code‘].lower()

    dep = users[key][‘department‘].lower()

    username = users[key][‘username‘].strip()

   

    if dep and city:

        user_list.setdefault(dep,[])

        user_list[dep].append(username)

        user_list.setdefault(dep+city,[])

        user_list[dep+city].append(username)

        user_list.setdefault(‘base%s‘ % city,[])

        user_list[‘base%s‘% city].append(username)

        if username not in [‘cbremble‘,‘nkovalevich‘,‘nrich‘,‘isugarman‘]:

            user_list.setdefault(‘attendance%s‘ % city,[])

            user_list[‘attendance%s‘% city].append(username)


        if departments[users[key][‘department‘]][‘is_production‘]:

                user_list.setdefault(‘prod‘,[])

                user_list.setdefault(‘prod%s‘ % city,[])

                user_list[‘prod%s‘% city].append(username)

                user_list[‘prod‘].append(username)





try:

    for dep in user_list:

        if dep in forwards.keys():

            if dep:

                need_add_alias = set(user_list[dep]) - set(forwards[dep])

        else:

            need_add_alias = user_list[dep]

        if need_add_alias:

            for user in need_add_alias:

                add_forward = """insert into mail.forward(name,forward_name,status) values (‘%s‘,‘%s‘,‘Enabled‘) """  % (dep,user)

                cur.execute(add_forward)

    con.commit()

except Exception,e:

    print type(e),e


本文出自 “8277056” 博客,请务必保留此出处http://8287056.blog.51cto.com/8277056/1944402

根据部门和城市自动创建邮箱