调整离群代码,确保删除重复加入的数据
[gaetalk.git] / usermaintainer.py
blobea7820ce871ddedb1eff3a28281699c720afb35d
1 #!/usr/bin/env python2
2 # vim:fileencoding=utf-8
4 import gaetalk
5 import logging
6 from google.appengine.ext import webapp
7 from google.appengine.ext.webapp.util import run_wsgi_app
9 class Userdedup(webapp.RequestHandler):
10 def get(self):
11 users = {}
12 for u in gaetalk.User.all():
13 if u.jid in users:
14 users[u.jid].append(u)
15 else:
16 users[u.jid] = [u]
17 for k, v in users.items():
18 if len(v) == 1:
19 continue
20 v.sort(key=lambda u: gaetalk.STATUS_LIST.index(u.avail))
21 logging.error(' '.join([x.avail for x in v]))
22 for i in v[1:]:
23 l = gaetalk.Log(msg=u'删除重复用户', jid=i.jid,
24 nick=i.nick, type='misc')
25 l.put()
26 i.delete()
27 self.response.out.write(u'OK.'.encode('utf-8'))
29 application = webapp.WSGIApplication(
31 ('/_admin/userdedup', Userdedup),
33 debug=True)
35 def main():
36 run_wsgi_app(application)
38 if __name__ == "__main__":
39 main()