diff --git a/batch-delete.py b/tools/batch-delete.py similarity index 100% rename from batch-delete.py rename to tools/batch-delete.py diff --git a/tools/send_mail.sh.template b/tools/send_mail.sh.template new file mode 100755 index 0000000000..f27d809e74 --- /dev/null +++ b/tools/send_mail.sh.template @@ -0,0 +1,6 @@ +#!/bin/sh + +export PYTHONPATH=thirdpart +export DJANGO_SETTINGS_MODULE=settings + +./user_notification.py diff --git a/tools/user_notification.py b/tools/user_notification.py new file mode 100755 index 0000000000..ed33e0f7f3 --- /dev/null +++ b/tools/user_notification.py @@ -0,0 +1,41 @@ +#!/usr/bin/python +# encoding: utf-8 + +import string +from django.core.mail import send_mail + +from notifications.models import UserNotification +import settings + +email_template = u'''${username}您好: + +您有${cnt}条新消息,请点击下面的链接查看: +${msg_url} + +感谢使用我们的网站! + +Seafile团队 +''' + +subject = u'SeaCloud:新消息' +url = 'http://localhost:8000/home/my/' + +notifications = UserNotification.objects.all() + +d = {} +for e in notifications: + if d.has_key(e.to_user): + d[e.to_user] += 1 + else: + d[e.to_user] = 1 + +for k in d.keys(): + to_user = k + cnt = d[k] + + template = string.Template(email_template) + content = template.substitute(username=to_user, cnt=cnt, msg_url=url) + send_mail(subject, content, settings.DEFAULT_FROM_EMAIL, [to_user], \ + fail_silently=False) + +