[wip] work on chatoob frontend
This commit is contained in:
parent
8344824970
commit
44221c4c9e
5 changed files with 109 additions and 2 deletions
23
scripts/chatoob
Executable file
23
scripts/chatoob
Executable file
|
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=python et softtabstop=4 cinoptions=4 shiftwidth=4 ts=4 ai
|
||||
|
||||
# Copyright(C) 2010 Christophe Benz
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, version 3 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
from weboob.frontends.chatoob import Chatoob
|
||||
|
||||
if __name__ == '__main__':
|
||||
Chatoob.run()
|
||||
|
|
@ -139,3 +139,6 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesReply, ICapDating, ICapC
|
|||
|
||||
def send_chat_message(self, _id, message):
|
||||
return self.browser.send_chat_message(_id, message)
|
||||
|
||||
#def start_chat_polling(self):
|
||||
#self._profile_walker = ProfilesWalker(self.weboob.scheduler, self.storage, self.browser)
|
||||
|
|
|
|||
|
|
@ -16,10 +16,12 @@
|
|||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
import datetime
|
||||
import time
|
||||
from logging import warning
|
||||
import random
|
||||
import simplejson
|
||||
import urllib
|
||||
|
||||
from weboob.tools.browser import BaseBrowser
|
||||
from weboob.tools.parsers.html5libparser import Html5libParser
|
||||
|
|
@ -292,5 +294,10 @@ class AdopteUnMec(BaseBrowser):
|
|||
'Referer': 'http://www.adopteunmec.com/chat.php',
|
||||
'Origin': 'http://www.adopteunmec.com',
|
||||
}
|
||||
print url, data, headers
|
||||
return self.post_request(url, data, headers)
|
||||
request = self.request_class(url, urllib.urlencode(data), headers)
|
||||
response = self.openurl(request).read()
|
||||
try:
|
||||
datetime.datetime.strptime(response, '%Y-%m-%d %H:%M:%S')
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
|
|
|
|||
18
weboob/frontends/chatoob/__init__.py
Normal file
18
weboob/frontends/chatoob/__init__.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010 Christophe Benz
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, version 3 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
from .chatoob import Chatoob
|
||||
56
weboob/frontends/chatoob/chatoob.py
Normal file
56
weboob/frontends/chatoob/chatoob.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010 Christophe Benz
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, version 3 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
import logging
|
||||
|
||||
from weboob.tools.application import ConsoleApplication
|
||||
from weboob.capabilities.chat import ICapChat
|
||||
|
||||
|
||||
__all__ = ['Chatoob']
|
||||
|
||||
|
||||
class Chatoob(ConsoleApplication):
|
||||
APPNAME = 'chatoob'
|
||||
VERSION = '1.0'
|
||||
COPYRIGHT = 'Copyright(C) 2010 Christophe Benz'
|
||||
|
||||
def main(self, argv):
|
||||
self.load_config()
|
||||
self.load_backends(ICapChat)
|
||||
#for backend, result in self.weboob.do('start_chat_polling', self.on_new_chat_message):
|
||||
#logging.info(u'Polling chat messages for backend %s' % backend)
|
||||
return self.process_command(*argv[1:])
|
||||
|
||||
def on_new_chat_message(self, message):
|
||||
print 'on_new_chat_message: %s' % message
|
||||
|
||||
@ConsoleApplication.command('exit program')
|
||||
def command_exit(self):
|
||||
self.weboob.want_stop()
|
||||
|
||||
@ConsoleApplication.command('list online contacts')
|
||||
def command_list(self):
|
||||
for backend, contact in self.weboob.do('iter_chat_contacts', online=True, offline=False):
|
||||
self.format(contact)
|
||||
|
||||
@ConsoleApplication.command('send message to contact')
|
||||
def command_send(self, _id, message):
|
||||
for backend, result in self.weboob.do('send_chat_message', _id, message):
|
||||
if not result:
|
||||
logging.error(u'Failed to send message to contact id="%s" on backend "%s"' % (_id, backend.name))
|
||||
Loading…
Add table
Add a link
Reference in a new issue