[dss-commits] r8835 - dss/branches/0.5/examples

dss-commits at forum.digitalstrom.org dss-commits at forum.digitalstrom.org
Wed Oct 7 14:46:00 CEST 2009


Author: jwinkelmann
Date: 2009-10-07 14:46:00 +0200 (Wed, 07 Oct 2009)
New Revision: 8835

Added:
   dss/branches/0.5/examples/twitter_bell.py
   dss/branches/0.5/examples/twitter_phone.py
Log:
branches/0.5: merge 8825 from trunk ("Example using twitter and events Files")


Copied: dss/branches/0.5/examples/twitter_bell.py (from rev 8826, dss/trunk/examples/twitter_bell.py)
===================================================================
--- dss/branches/0.5/examples/twitter_bell.py	                        (rev 0)
+++ dss/branches/0.5/examples/twitter_bell.py	2009-10-07 12:46:00 UTC (rev 8835)
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+
+#
+#    Copyright (c) 2009 digitalSTROM.org, Zurich, Switzerland
+#    Copyright (c) 2009 futureLAB AG, Winterthur, Switzerland
+#
+#    This file is part of digitalSTROM Server.
+#
+#    digitalSTROM Server is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    digitalSTROM Server 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 General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with digitalSTROM Server. If not, see <http://www.gnu.org/licenses/>.
+#
+
+
+
+from suds.client import Client
+import telnetlib
+import time
+
+# Uses twitter API from http://mike.verdone.ca/twitter/
+from twitter.api import Twitter, TwitterError
+import datetime
+
+url = 'http://localhost:8080/dss.wsdl'
+twitterEmail = 'your at email.com'
+twitterPassword = 'yourPassword'
+
+while 1:
+  client = Client(url);
+  try:
+    while 1:
+      token = client.service.Authenticate('user', 'pass')
+      client.service.EventSubscribeTo(token, 'bell')
+      print 'Waiting for event'
+      client.service.EventWaitFor(token, 0)
+      print 'Received event'
+      twitter = Twitter(twitterEmail, twitterPassword, agent='dssTwitter')
+      t = datetime.datetime.now()
+      stat = t.strftime('%d.%m.%Y %H:%M') + ' => somebody is at the door'
+      print stat
+      twitter.statuses.update(status=stat)
+  except Exception, inst:
+    print 'error ', inst

Copied: dss/branches/0.5/examples/twitter_phone.py (from rev 8826, dss/trunk/examples/twitter_phone.py)
===================================================================
--- dss/branches/0.5/examples/twitter_phone.py	                        (rev 0)
+++ dss/branches/0.5/examples/twitter_phone.py	2009-10-07 12:46:00 UTC (rev 8835)
@@ -0,0 +1,66 @@
+#!/usr/bin/python
+
+#
+#    Copyright (c) 2009 digitalSTROM.org, Zurich, Switzerland
+#    Copyright (c) 2009 futureLAB AG, Winterthur, Switzerland
+#
+#    This file is part of digitalSTROM Server.
+#
+#    digitalSTROM Server is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    digitalSTROM Server 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 General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with digitalSTROM Server. If not, see <http://www.gnu.org/licenses/>.
+#
+
+
+
+from suds.client import Client
+import telnetlib
+import time
+
+# Uses twitter API from http://mike.verdone.ca/twitter/
+from twitter.api import Twitter, TwitterError
+import datetime
+
+url = 'http://localhost:8080/dss.wsdl'
+twitterEmail = 'your at email.com'
+twitterPassword = 'yourPassword'
+
+def lookupNumber(number):
+  if number == '0791234567':
+    return 'Patrick'
+  return number
+
+while 1:
+  client = Client(url);
+  try:
+    while 1:
+      token = client.service.Authenticate('user', 'pass')
+      client.service.EventSubscribeTo(token, 'phone')
+      print 'Waiting for event'
+      events = client.service.EventWaitFor(token, 0)
+      print events
+      caller = 'unknown'
+      for event in events:
+        for parameter in event.parameter:
+	  key,value = parameter.split('=',1)
+	  if key == 'source':
+	    caller = lookupNumber(value)
+	    
+      print 'Received event'
+      twitter = Twitter(twitterEmail, twitterPassword, agent='dssTwitter')
+      t = datetime.datetime.now()
+      stat = t.strftime('%d.%m.%Y %H:%M') + ' => call from ' + caller
+      print stat
+      twitter.statuses.update(status=stat)
+      client.service.SignOff(token)
+  except Exception, inst:
+    print 'error ', inst



More information about the dss-commits mailing list