Update Gmail access with OAuth 2
This commit is contained in:
@@ -23,11 +23,11 @@ import time
|
||||
import requests
|
||||
from requests.auth import HTTPBasicAuth
|
||||
import xml.dom.minidom
|
||||
import getpass
|
||||
from threading import Thread
|
||||
from signal import signal, SIGINT
|
||||
import sys
|
||||
from genericmonitor import *
|
||||
from gmail import getUnreadMails
|
||||
|
||||
PURPLE_CONV_UPDATE_UNSEEN = 4
|
||||
PURPLE_MESSAGE_SEND = 0
|
||||
@@ -59,31 +59,23 @@ class PidginConversation:
|
||||
|
||||
class EventThread(Thread,GenericMonitor):
|
||||
SLEEP_TIME = 30
|
||||
MAIL_ADDRESS='XXX@gmail.com'
|
||||
|
||||
def stop(self):
|
||||
self._stopLoop = True
|
||||
self.stopMainLoop()
|
||||
|
||||
def _getMail(self):
|
||||
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:
|
||||
text = '1 msg'
|
||||
elif nb_messages > 1:
|
||||
text = '%d msgs' % (nb_messages)
|
||||
style = 'color:white'
|
||||
except Exception as e:
|
||||
text = str(e)
|
||||
else:
|
||||
text = 'Mail error %d' % (req.status_code)
|
||||
try:
|
||||
nb_messages = getUnreadMails()
|
||||
if nb_messages == 1:
|
||||
text = '1 msg'
|
||||
elif nb_messages > 1:
|
||||
text = '%d msgs' % (nb_messages)
|
||||
style = 'color:white'
|
||||
except Exception as e:
|
||||
text = str(e)
|
||||
|
||||
self.mailWidget.setText(text)
|
||||
self.mailWidget.setStyle(style)
|
||||
@@ -103,8 +95,6 @@ class EventThread(Thread,GenericMonitor):
|
||||
self.add_signal_receiver(self.pidginMessageWrote, 'WroteChatMsg', 'im.pidgin.purple.PurpleInterface')
|
||||
self.add_signal_receiver(self.pidginConversationUpdated, 'ConversationUpdated', 'im.pidgin.purple.PurpleInterface')
|
||||
|
||||
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])
|
||||
|
||||
Reference in New Issue
Block a user