首页 > 代码库 > 改变邮件组显示格式
改变邮件组显示格式
按公司要求把已经存在的城市+部门(bjxxx,xmxxx)邮件组改成部门+城市(xxxbj,xxxxm)格式。
注意:原来的bjxxx组里已经有人员,需要把原来的人员都删除,然后再添加xxxbj邮件组。
#!/usr/bin/python import sys sys.path.append(‘/sw/systems/shared/python‘) from DB import DB con,cur = DB().connect() #从数据库里列出符合bjxxx的邮件组 def mail_forward(): query = """ SELECT name,forward_name from mail.forward WHERE `name` like ‘bj%‘ or `name` like ‘xm%‘ or `name` like ‘wx%‘ and name != ‘wxa‘ """ cur.execute(query) results = cur.fetchall() forwards = {} for result in results: name = result[‘name‘] forward_name = result[‘forward_name‘].lower().strip() forwards.setdefault(name,[]) forwards[name].append(forward_name) return forwards forwards = mail_forward() #把bjxxx格式变成xxxbj格式 new_deps = {} for f in forwards: str1 = f[0:2] str2 = f[2:] str2 +=str1 new_deps.setdefault(f,str2) try: for dep,users in forwards.items(): print dep,users for user in users: delete = ‘delete from mail.forward where name = "%s" and forward_name = "%s"‘ % (dep, user) cur.execute(delete) if dep in new_deps.keys(): insert = ‘insert ignore into mail.forward (name,forward_name) values("%s","%s")‘ % (dep,new_deps[dep]) cur.execute(insert) con.commit() except Exception,e: print type(e),e
改变邮件组显示格式
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。