summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alex@spline.inf.fu-berlin.de>2013-10-09 19:53:34 +0000
committeraskbot <askbot@vm-askbot.spline.inf.fu-berlin.de>2013-10-09 19:53:34 +0000
commit96db9d00b86e40955a7facc1edbf8f3f4c181e49 (patch)
treeea1132b6f9017d8409c4d3eced50027b085a091c
downloadaskbot-notify-master.tar.gz
askbot-notify-master.tar.bz2
askbot-notify-master.zip
initial commitHEADmaster
-rw-r--r--.gitignore2
-rw-r--r--askbot_notify.py66
-rw-r--r--setup.py21
3 files changed, 89 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3864a16
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.egg*
+*.pyc
diff --git a/askbot_notify.py b/askbot_notify.py
new file mode 100644
index 0000000..c2bfd7f
--- /dev/null
+++ b/askbot_notify.py
@@ -0,0 +1,66 @@
+# This file is part of askbot_notify.
+# Copyright (C) 2013 Alexander Sulfrian <alex@spline.inf.fu-berlin.de>
+#
+# fedmsg is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# fedmsg is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with fedmsg; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+""" Plugin to notify via phenny on new messages from an askbot instance.
+
+Enable this plugin by editing the ``settings.py`` file in your askbot
+instance.
+
+Find MIDDLEWARE_CLASSES and add 'askbot_notify.NOOPMiddleware'
+to the tuple like:
+
+ MIDDLEWARE_CLASSES = (
+ ...
+ 'askbot_notify.NOOPMiddleware',
+ ...
+ )
+
+"""
+
+import socket
+import syslog
+from django.core import serializers
+from django.dispatch import receiver
+from askbot.models.signals import new_question_posted
+from askbot.utils.html import site_url
+
+def new_question(sender, **kwargs):
+ if 'question' in kwargs:
+ q = kwargs['question']
+ url = site_url(q.get_absolute_url(no_slug=True))
+ msg = "Neue Frage von %s: %s (%s)" % (q.author.username, q.get_question_title(), url)
+
+ s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ try:
+ s.connect('/var/run/phenny/socket')
+ s.sendall(msg)
+ s.close()
+ except socket.error:
+ syslog.syslog("Dropping message: '%s'" % msg)
+
+new_question_posted.connect(new_question, weak=False)
+
+
+class NOOPMiddleware(object):
+ """ Register our message-emitting plugin with django.
+
+ Django middleware is supposed to provide a bunch of methods to act on the
+ request/response pipeline. We ignore that and instead use middleware as
+ a convenient vector to get ourselves into the askbot runtime environment.
+
+ """
+ pass
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..d72e7e3
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+
+try:
+ from setuptools import setup
+except ImportError:
+ from ez_setup import use_setuptools
+ use_setuptools()
+ from setuptools import setup
+
+import sys
+
+setup(
+ name='askbot-notify',
+ version='0.0.1',
+ description="Askbot plugin for notifications via phenny",
+ author='Alexander Sulfrian',
+ author_email='alex@spline.inf.fu-berlin.de',
+ url='http://git.spline.inf.fu-berlin.de/askbot-notify/',
+ license='GPLv3',
+ py_modules=['askbot_notify'],
+)