Mercurial > libervia-backend
comparison src/plugins/deprecated_misc_cs.py @ 587:952322b1d490
Remove trailing whitespaces.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 18 Jan 2013 17:55:34 +0100 |
parents | ca13633d3b6b |
children | beaf6bec2fcd |
comparison
equal
deleted
inserted
replaced
586:6a718ede8be1 | 587:952322b1d490 |
---|---|
81 def profileConnected(self, profile): | 81 def profileConnected(self, profile): |
82 self.data[profile] = PersistentBinaryDict("plugin_CS", profile) | 82 self.data[profile] = PersistentBinaryDict("plugin_CS", profile) |
83 def dataLoaded(ignore): | 83 def dataLoaded(ignore): |
84 if not self.data[profile]: | 84 if not self.data[profile]: |
85 self.data[profile] = {'cookies':{}} | 85 self.data[profile] = {'cookies':{}} |
86 | 86 |
87 self.data[profile].load().addCallback(dataLoaded) | 87 self.data[profile].load().addCallback(dataLoaded) |
88 | 88 |
89 def profileDisconnected(self, profile): | 89 def profileDisconnected(self, profile): |
90 del self.data[profile] | 90 del self.data[profile] |
91 | 91 |
102 if not login or not password: | 102 if not login or not password: |
103 message_data={"reason": "uncomplete", "message":_(u"You have to fill your CouchSurfing login & password in parameters before using this interface")} | 103 message_data={"reason": "uncomplete", "message":_(u"You have to fill your CouchSurfing login & password in parameters before using this interface")} |
104 self.host.bridge.actionResult("ERROR", id, message_data) | 104 self.host.bridge.actionResult("ERROR", id, message_data) |
105 return | 105 return |
106 | 106 |
107 post_data = urllib.urlencode({'auth_login[un]':login,'auth_login[pw]':password,'auth_login[action]':'Login...'}) | 107 post_data = urllib.urlencode({'auth_login[un]':login,'auth_login[pw]':password,'auth_login[action]':'Login...'}) |
108 | 108 |
109 self.data[profile]['cookies'] = {} | 109 self.data[profile]['cookies'] = {} |
110 | 110 |
111 d = getPage('http://www.couchsurfing.org/login.html', method='POST', postdata=post_data, headers={'Content-Type':'application/x-www-form-urlencoded'} , agent=AGENT, cookies=self.data[profile]['cookies']) | 111 d = getPage('http://www.couchsurfing.org/login.html', method='POST', postdata=post_data, headers={'Content-Type':'application/x-www-form-urlencoded'} , agent=AGENT, cookies=self.data[profile]['cookies']) |
112 d.addCallback(self.__connectionCB, id, profile) | 112 d.addCallback(self.__connectionCB, id, profile) |
113 d.addErrback(self.erroCB, id) | 113 d.addErrback(self.erroCB, id) |
114 | 114 |
115 #self.host.bridge.actionResult("SUPPRESS", id, {}) | 115 #self.host.bridge.actionResult("SUPPRESS", id, {}) |
191 regex_href = re.compile(r'/connections\.html\?id=([^&]+)') | 191 regex_href = re.compile(r'/connections\.html\?id=([^&]+)') |
192 a_tag = _tr.find('a',href=regex_href) | 192 a_tag = _tr.find('a',href=regex_href) |
193 friend_id = regex_href.search(unicode(a_tag)).groups()[0] | 193 friend_id = regex_href.search(unicode(a_tag)).groups()[0] |
194 | 194 |
195 debug(_("CS friend found: %(friend_name)s (id: %(friend_id)s, link: %(friend_link)s)") % {'friend_name':friend_name, 'friend_id':friend_id, 'friend_link':friend_link}) | 195 debug(_("CS friend found: %(friend_name)s (id: %(friend_id)s, link: %(friend_link)s)") % {'friend_name':friend_name, 'friend_id':friend_id, 'friend_link':friend_link}) |
196 friends[friend_name] = {'link':friend_link,'id':friend_id} | 196 friends[friend_name] = {'link':friend_link,'id':friend_id} |
197 a = soup.find('td','barmiddle next').a #is there several pages ? | 197 a = soup.find('td','barmiddle next').a #is there several pages ? |
198 if a: | 198 if a: |
199 #yes, we parse the next page | 199 #yes, we parse the next page |
200 d = getPage('http://www.couchsurfing.org/'+str(a['href']), agent=AGENT, cookies=self.data[profile]['cookies']) | 200 d = getPage('http://www.couchsurfing.org/'+str(a['href']), agent=AGENT, cookies=self.data[profile]['cookies']) |
201 d.addCallback(self.__friendsPageCB, id=id, profile=profile) | 201 d.addCallback(self.__friendsPageCB, id=id, profile=profile) |
253 friends = data['friends'].split('\t') | 253 friends = data['friends'].split('\t') |
254 subject = data['subject'] | 254 subject = data['subject'] |
255 message = data['message'] | 255 message = data['message'] |
256 info(_("sending message to %(friends)s with subject [%(subject)s]" % {'friends':friends, 'subject':subject})) | 256 info(_("sending message to %(friends)s with subject [%(subject)s]" % {'friends':friends, 'subject':subject})) |
257 self.__sendMessage(None, subject, message, self.data[profile], friends, id, profile) | 257 self.__sendMessage(None, subject, message, self.data[profile], friends, id, profile) |
258 | 258 |
259 def __showUnreadMessages2(self, html, id, profile): | 259 def __showUnreadMessages2(self, html, id, profile): |
260 """Called when the inbox page has been received""" | 260 """Called when the inbox page has been received""" |
261 #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. | 261 #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. |
262 soup = BeautifulSoup(html) | 262 soup = BeautifulSoup(html) |
263 for tag in soup.findAll(lambda tag: tag.name=='strong' and tag.a and tag.a['href'].startswith('messages.html?message_status=inbox')): | 263 for tag in soup.findAll(lambda tag: tag.name=='strong' and tag.a and tag.a['href'].startswith('messages.html?message_status=inbox')): |
267 def showUnreadMessages(self, id, data, profile): | 267 def showUnreadMessages(self, id, data, profile): |
268 """Called when user want to see all unread messages in the external browser""" | 268 """Called when user want to see all unread messages in the external browser""" |
269 d = getPage("http://www.couchsurfing.org/messages.html?message_status=inbox&show=10000", agent=AGENT, cookies=self.data[profile]['cookies']) | 269 d = getPage("http://www.couchsurfing.org/messages.html?message_status=inbox&show=10000", agent=AGENT, cookies=self.data[profile]['cookies']) |
270 d.addCallback(self.__showUnreadMessages2, id, profile) | 270 d.addCallback(self.__showUnreadMessages2, id, profile) |
271 d.addErrback(self.erroCB, id) | 271 d.addErrback(self.erroCB, id) |
272 | 272 |