Update Python example with new API
This commit is contained in:
@@ -27,7 +27,7 @@ import getpass
|
||||
from threading import Thread
|
||||
from signal import signal, SIGINT
|
||||
import sys
|
||||
from genericmonitor import GenericMonitor, GenericMonitorGroup, GenericMonitorItem
|
||||
from genericmonitor import *
|
||||
|
||||
PURPLE_CONV_UPDATE_UNSEEN = 4
|
||||
PURPLE_MESSAGE_SEND = 0
|
||||
@@ -66,27 +66,28 @@ class EventThread(Thread,GenericMonitor):
|
||||
self.stopMainLoop()
|
||||
|
||||
def _getMail(self):
|
||||
mailItem = GenericMonitorItem('mail')
|
||||
mailGroup = GenericMonitorGroup('Mail', [mailItem])
|
||||
|
||||
address = "https://mail.google.com/mail/feed/atom"
|
||||
auth = HTTPBasicAuth(self.MAIL_ADDRESS, self._mail_password)
|
||||
req = requests.get(address, auth=auth)
|
||||
text = ''
|
||||
style = ''
|
||||
if req.status_code == requests.codes.ok:
|
||||
dom = xml.dom.minidom.parseString(req.text)
|
||||
try:
|
||||
nb_messages = int(dom.getElementsByTagName('fullcount')[0].firstChild.nodeValue)
|
||||
if nb_messages == 1:
|
||||
mailItem.text = '1 msg'
|
||||
text = '1 msg'
|
||||
elif nb_messages > 1:
|
||||
mailItem.text = '%d msgs' % (nb_messages)
|
||||
mailItem.style = 'color:white'
|
||||
text = '%d msgs' % (nb_messages)
|
||||
style = 'color:white'
|
||||
except Exception as e:
|
||||
mailItem.text = str(e)
|
||||
text = str(e)
|
||||
else:
|
||||
mailItem.text = 'Mail error %d' % (req.status_code)
|
||||
|
||||
self.notify(mailGroup)
|
||||
text = 'Mail error %d' % (req.status_code)
|
||||
|
||||
self.mailWidget.setText(text)
|
||||
self.mailWidget.setStyle(style)
|
||||
self.notify(self.mailGroup)
|
||||
|
||||
def getEvents(self):
|
||||
self._getMail()
|
||||
@@ -104,6 +105,14 @@ class EventThread(Thread,GenericMonitor):
|
||||
|
||||
self._mail_password = getpass.getpass('Enter password for address %s: ' % (self.MAIL_ADDRESS))
|
||||
|
||||
self.mailWidget = GenericMonitorTextWidget('')
|
||||
mailItem = GenericMonitorItem('mail', [self.mailWidget])
|
||||
self.mailGroup = GenericMonitorGroup('Mail', [mailItem])
|
||||
|
||||
icon = GenericMonitorIconWidget('/usr/share/icons/hicolor/22x22/apps/pidgin.png', 'icon-size:22px')
|
||||
pidginItem = GenericMonitorItem('pidgin', [icon])
|
||||
self.pidginGroup = GenericMonitorGroup('Pidgin', pidginItem)
|
||||
|
||||
while not self._stopLoop:
|
||||
self.getEvents()
|
||||
# Be more reactive on signal capture
|
||||
@@ -129,9 +138,7 @@ class EventThread(Thread,GenericMonitor):
|
||||
pidginConversation.nbMessages = 1
|
||||
|
||||
def displayIcon(self):
|
||||
pidginItem = GenericMonitorItem('pidgin', icon='/usr/share/icons/hicolor/22x22/apps/pidgin.png', iconStyle='icon-size:22px')
|
||||
pidginGroup = GenericMonitorGroup('Pidgin', pidginItem)
|
||||
self.notify(pidginGroup)
|
||||
self.notify(self.pidginGroup)
|
||||
|
||||
def pidginConversationUpdated(self, conversation, _type):
|
||||
if _type != PURPLE_CONV_UPDATE_UNSEEN:
|
||||
|
||||
Reference in New Issue
Block a user