summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorHostmaster of the Day <root@localhost>2011-04-01 02:23:43 +0200
committerHostmaster of the Day <root@localhost>2011-04-01 02:23:43 +0200
commit3813d329d10557ef5fc520db8f58edb64763817b (patch)
tree09cd4ffcd38ac4fbffc44072aa5952c5ad8c4cfa /bin
parentacc5ec0d9b7496fdf36b88ed111b8b32ac50a497 (diff)
downloaddev-scripts-3813d329d10557ef5fc520db8f58edb64763817b.tar.gz
dev-scripts-3813d329d10557ef5fc520db8f58edb64763817b.tar.xz
dev-scripts-3813d329d10557ef5fc520db8f58edb64763817b.zip
added script for sending an email to allHEADmaster
Diffstat (limited to '')
-rw-r--r--bin/send_emails_to_all.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/bin/send_emails_to_all.py b/bin/send_emails_to_all.py
new file mode 100644
index 0000000..736831d
--- /dev/null
+++ b/bin/send_emails_to_all.py
@@ -0,0 +1,51 @@
+#!/usr/bin/python
+
+# setup django environment, so we can use their template engine
+from django.template import Context
+from django.template.loader import render_to_string
+# import mysql bindings
+import MySQLdb
+
+# render mail template and send it using local sendmail binary
+def sendmail(c, template):
+ msg = render_to_string(template + "_mail.txt", c)
+
+ # open sendmail process for writing
+ p = os.popen("/usr/sbin/sendmail -t", 'w')
+ p.write(msg)
+
+ # close will return exit status
+ # TODO: log error to some file
+ if p.close():
+ return False
+ return True
+
+def get_emails():
+ db = MySQLdb.connect(host="localhost", user="apache", passwd="password", db="trac")
+ cursor = db.cursor()
+ cursor.execute("SELECT login, email FROM user")
+ users = cursor.fetchall()
+
+ for user in users:
+ c = Context()
+ c['from_addr'] = "dev@spline.de"
+ c['to_addr'] = user[1]
+ c['name'] = user[0]
+ cursor.execute("select project_name from project_members where login = '%s'" % (user[0], ))
+ projects = cursor.fetchall()
+ if len(projects) < 1:
+ continue
+ pstring = ""
+ for project in projects:
+ pstring += "* %s\n" % (project[0], )
+ c['projects'] = pstring
+ sendmail(c, "delete_reminder")
+
+ cursor.close()
+ db.close()
+
+import os, sys
+sys.path = ['/var/www/localhost/htdocs'] + sys.path
+os.environ['DJANGO_SETTINGS_MODULE'] = 'account.settings'
+
+get_emails()