CS plugin: unread messages can now be openned in external web browser
This commit is contained in:
parent
8c1ee1d907
commit
5842b14a32
1 changed files with 19 additions and 5 deletions
|
|
@ -35,6 +35,7 @@ from zope.interface import implements
|
|||
from wokkel import disco, iwokkel, data_form
|
||||
from tools.xml_tools import XMLUI
|
||||
import urllib
|
||||
import webbrowser
|
||||
|
||||
from BeautifulSoup import BeautifulSoup
|
||||
import re
|
||||
|
|
@ -75,6 +76,7 @@ class CS_Plugin():
|
|||
host.importMenu(_("Plugin"), "CouchSurfing", self.menuSelected, help_string = _("Launch CoushSurfing mangement interface"))
|
||||
self.data=self.host.memory.getPrivate('plugin_cs_data') or {} #TODO: delete cookies/data after a while
|
||||
self.host.registerGeneralCB("plugin_CS_sendMessage", self.sendMessage)
|
||||
self.host.registerGeneralCB("plugin_CS_showUnreadMessages", self.showUnreadMessages)
|
||||
|
||||
def erroCB(self, e, id):
|
||||
"""Called when something is going wrong when contacting CS website"""
|
||||
|
|
@ -164,6 +166,8 @@ class CS_Plugin():
|
|||
interface = XMLUI('window','tabs', title='CouchSurfing management')
|
||||
interface.addCategory(_("Messages"), "vertical")
|
||||
interface.addText(_("G'day %(name)s, you have %(nb_message)i unread message%(plural_mess)s and %(unread_CR_mess)s unread couch request message%(plural_CR)s\nIf you want to send a message, select the recipient(s) in the list below") % {'name':user_name, 'nb_message':unread_mess, 'plural_mess':'s' if unread_mess>1 else '', 'unread_CR_mess': unread_CR_mess, 'plural_CR':'s' if unread_CR_mess>1 else ''})
|
||||
if unread_mess:
|
||||
interface.addButton('plugin_CS_showUnreadMessages', 'showUnreadMessages', _('Show unread message%(plural)s in external web browser') % {'plural':'s' if unread_mess>1 else ''})
|
||||
interface.addList(friends_list, 'friends', style=['multi'])
|
||||
interface.changeLayout('pairs')
|
||||
interface.addLabel(_("Subject"))
|
||||
|
|
@ -240,10 +244,6 @@ class CS_Plugin():
|
|||
interface.addText(_('The message has been sent to every recipients'))
|
||||
self.host.bridge.actionResult("XMLUI", id, {"type":"window", "xml":interface.toXml()})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def sendMessage(self, id, data, profile):
|
||||
"""Called to send a message to a friend
|
||||
@param data: dict with the following keys:
|
||||
|
|
@ -263,4 +263,18 @@ class CS_Plugin():
|
|||
print "send message \o/ :) :) :)"
|
||||
info(_("sending message to %(friends)s with subject [%(subject)s]" % {'friends':friends, 'subject':subject}))
|
||||
self.__sendMessage(None, subject, message, self.data[profile], friends, id, profile)
|
||||
|
||||
|
||||
def __showUnreadMessages2(self, html, id, profile):
|
||||
"""Called when the inbox page has been received"""
|
||||
#FIXME: that's really too fragile, only works if the unread messages are in the first page, and it would be too resources consuming for the website to DL each time all pages. In addition, the show attribute doesn't work as expected.
|
||||
soup = BeautifulSoup(html)
|
||||
for tag in soup.findAll(lambda tag: tag.name=='strong' and tag.a and tag.a['href'].startswith('messages.html?message_status=inbox')):
|
||||
link = "http://www.couchsurfing.org/"+str(tag.a['href'])
|
||||
webbrowser.open(link, new=2) #TODO: the web browser need to already have CS cookies (i.e. already be opened & logged on CS, or be permanently loggued), a warning to the user should be sent
|
||||
|
||||
def showUnreadMessages(self, id, data, profile):
|
||||
"""Called when user want to see all unread messages in the external browser"""
|
||||
d = getPage("http://www.couchsurfing.org/messages.html?message_status=inbox&show=10000", agent=AGENT, cookies=self.data[profile]['cookies'])
|
||||
d.addCallback(self.__showUnreadMessages2, id, profile)
|
||||
d.addErrback(self.erroCB, id)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue