comparison plugins/plugin_misc_cs.py @ 218:5c68a65548c3

Plugin CS: fixed forgotten debug stuff, CS plugin is now working again User agent changed to "Salut à Toi XMPP/CS Plugin".
author Goffi <goffi@goffi.org>
date Mon, 27 Dec 2010 18:37:56 +0100
parents 18b0cf49a6f1
children 782319a64ac6
comparison
equal deleted inserted replaced
217:b4dfe15c0b25 218:5c68a65548c3
50 "main": "CS_Plugin", 50 "main": "CS_Plugin",
51 "handler": "no", 51 "handler": "no",
52 "description": _(u"""This plugin allow to manage your CouchSurfing account throught your SàT frontend""") 52 "description": _(u"""This plugin allow to manage your CouchSurfing account throught your SàT frontend""")
53 } 53 }
54 54
55 AGENT = 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100423 Ubuntu/10.04 (lucid) Firefox/3.6.3' 55 AGENT = 'Salut à Toi XMPP/CS Plugin'
56 56
57 class CS_Plugin(): 57 class CS_Plugin():
58 58
59 params = """ 59 params = """
60 <params> 60 <params>
71 info(_("Plugin CS initialization")) 71 info(_("Plugin CS initialization"))
72 self.host = host 72 self.host = host
73 #parameters 73 #parameters
74 host.memory.importParams(CS_Plugin.params) 74 host.memory.importParams(CS_Plugin.params)
75 #menu 75 #menu
76 host.importMenu(_("Plugin"), "CouchSurfing", self.menuSelected, help_string = _("Launch CoushSurfing mangement interface")) 76 host.importMenu(_("Plugin"), "CouchSurfing", self.menuSelected, help_string = _("Launch CoushSurfing management interface"))
77 self.data=self.host.memory.getPrivate('plugin_cs_data') or {} #TODO: delete cookies/data after a while 77 self.data=self.host.memory.getPrivate('plugin_cs_data') or {} #TODO: delete cookies/data after a while
78 self.host.registerGeneralCB("plugin_CS_sendMessage", self.sendMessage) 78 self.host.registerGeneralCB("plugin_CS_sendMessage", self.sendMessage)
79 self.host.registerGeneralCB("plugin_CS_showUnreadMessages", self.showUnreadMessages) 79 self.host.registerGeneralCB("plugin_CS_showUnreadMessages", self.showUnreadMessages)
80 80
81 def erroCB(self, e, id): 81 def erroCB(self, e, id):
97 97
98 if not self.data.has_key(profile): 98 if not self.data.has_key(profile):
99 self.data[profile] = {'cookies':{}} 99 self.data[profile] = {'cookies':{}}
100 else: 100 else:
101 self.data[profile]['cookies'] = {} 101 self.data[profile]['cookies'] = {}
102 102
103
104
105
106
107 #tmp
108 """f = open('/home/goffi/tmp/CS_principale.html','r')
109 html = f.read()
110 self.__connectionCB(html, id, profile)"""
111
112 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']) 103 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'])
113 d.addCallback(self.__connectionCB, id, profile) 104 d.addCallback(self.__connectionCB, id, profile)
114 d.addErrback(self.erroCB, id) 105 d.addErrback(self.erroCB, id)
115 106
116 107 #self.host.bridge.actionResult("SUPPRESS", id, {})
117 #self.host.bridge.actionResult("SUPPRESS", id, {})
118 108
119 109
120 #pages parsing callbacks 110 #pages parsing callbacks
121 def savePage(self, name, html): 111 def savePage(self, name, html):
122 f = open ('/home/goffi/tmp/CS_'+name+'.html','w') 112 f = open ('/tmp/CS_'+name+'.html','w')
123 f.write(html) 113 f.write(html)
124 f.close() 114 f.close()
125 print "page [%s] sauvee" % name 115 print "page [%s] sauvee" % name
126 #pdb.set_trace() 116 #pdb.set_trace()
127 117
128 def __connectionCB(self, html, id, profile): 118 def __connectionCB(self, html, id, profile):
129 print 'Response received' 119 print 'Response received'
130 self.savePage('principale',html) 120 #self.savePage('principale',html)
131 soup = BeautifulSoup(html) 121 soup = BeautifulSoup(html)
132 self.data[profile]['user_nick'] = soup.find('a','item_link',href='/home.html').contents[0] 122 self.data[profile]['user_nick'] = soup.find('a','item_link',href='/home.html').contents[0]
133 self.data[profile]['user_name'] = soup.html.head.title.string.split(' - ')[1] 123 self.data[profile]['user_name'] = soup.html.head.title.string.split(' - ')[1]
134 #unread messages 124 #unread messages
135 try: 125 try:
143 self.data[profile]['unread_CR_messages'] = 0 133 self.data[profile]['unread_CR_messages'] = 0
144 134
145 #if we have already the list of friend, no need to make new requests 135 #if we have already the list of friend, no need to make new requests
146 if not self.data[profile].has_key('friends'): 136 if not self.data[profile].has_key('friends'):
147 self.data[profile]['friends'] = {} 137 self.data[profile]['friends'] = {}
148 """f = open('/home/goffi/tmp/CS_friends.html','r')
149 html = f.read()
150 self.__friendsPageCB(html, id, profile)"""
151 d = getPage('http://www.couchsurfing.org/connections.html?type=myfriends&show=10000', agent=AGENT, cookies=self.data[profile]['cookies']) 138 d = getPage('http://www.couchsurfing.org/connections.html?type=myfriends&show=10000', agent=AGENT, cookies=self.data[profile]['cookies'])
152 d.addCallback(self.__friendsPageCB, id=id, profile=profile) 139 d.addCallback(self.__friendsPageCB, id=id, profile=profile)
153 d.addErrback(self.erroCB, id) 140 d.addErrback(self.erroCB, id)
154 else: 141 else:
155 self.host.bridge.actionResult("XMLUI", id, {"type":"window", "xml":self.__buildUI(self.data[profile])}) 142 self.host.bridge.actionResult("XMLUI", id, {"type":"window", "xml":self.__buildUI(self.data[profile])})