diff --git a/modules/okc/backend.py b/modules/okc/backend.py index c6f87703..ce0715b6 100644 --- a/modules/okc/backend.py +++ b/modules/okc/backend.py @@ -25,7 +25,6 @@ from html2text import unescape from dateutil import tz from dateutil.parser import parse as _parse_dt -from weboob.capabilities.base import NotLoaded from weboob.capabilities.messages import ICapMessages, ICapMessagesPost, Message, Thread from weboob.capabilities.dating import ICapDating, OptimizationNotFound, Event from weboob.capabilities.contact import ICapContact, ContactPhoto, Contact, Query, QueryError @@ -140,12 +139,17 @@ class OkCBackend(BaseBackend, ICapMessages, ICapContact, ICapMessagesPost, ICapD thread = id id = thread.id + if not thread and isinstance(id, basestring) and not id.isdigit(): + for t in self.browser.get_threads_list(): + if t['username'] == id: + id = t['id'] + break + else: + return None + if not thread: thread = Thread(int(id)) thread.flags = Thread.IS_DISCUSSION - full = False - else: - full = True with self.browser: mails = self.browser.get_thread_mails(id, 100) @@ -192,13 +196,8 @@ class OkCBackend(BaseBackend, ICapMessages, ICapContact, ICapMessagesPost, ICapD child = msg - if full and msg: - # If we have get all the messages, replace NotLoaded with None as - # parent. + if msg: msg.parent = None - if not full and not msg: - # Perhaps there are hidden messages - msg = NotLoaded thread.root = msg @@ -353,7 +352,7 @@ class OkCBackend(BaseBackend, ICapMessages, ICapContact, ICapMessagesPost, ICapD threads = self.browser.get_threads_list(count=100) for thread in threads: - c = self._get_partial_contact(thread['member']) + c = self.get_contact(thread['username']) if c and (c.status & status) and (not ids or c.id in ids): yield c diff --git a/modules/okc/optim/profiles_walker.py b/modules/okc/optim/profiles_walker.py index 21584a22..f9b77570 100644 --- a/modules/okc/optim/profiles_walker.py +++ b/modules/okc/optim/profiles_walker.py @@ -25,24 +25,34 @@ from random import randint from weboob.tools.browser import BrowserUnavailable from weboob.capabilities.dating import Optimization from weboob.tools.log import getLogger +from weboob.tools.value import Value, ValuesDict __all__ = ['ProfilesWalker'] class ProfilesWalker(Optimization): + CONFIG = ValuesDict(Value('first_message', label='First message to send to matched profiles', default='')) + def __init__(self, sched, storage, browser): self.sched = sched self.storage = storage self.browser = browser self.logger = getLogger('walker', browser.logger) + self.config = storage.get('priority_connection', 'config', default=None) + if self.config == {}: + self.config = None + self.view_cron = None self.visited_profiles = set(storage.get('profiles_walker', 'viewed')) self.logger.info(u'Loaded %d already visited profiles from storage.' % len(self.visited_profiles)) self.profiles_queue = set() def save(self): + if self.config is None: + return False + self.storage.set('profiles_walker', 'viewed', list(self.visited_profiles)) self.storage.save() @@ -58,6 +68,15 @@ class ProfilesWalker(Optimization): def is_running(self): return self.view_cron is not None + def set_config(self, params): + self.config = params + self.storage.set('priority_connection', 'config', self.config) + self.storage.save() + + def get_config(self): + return self.config + + def view_profile(self): try: id = self.browser.find_match_profile() @@ -69,7 +88,8 @@ class ProfilesWalker(Optimization): # profile = self.browser.get_profile(id) self.browser.do_rate(id) self.browser.visit_profile(id) - self.browser.post_mail(id, u"Sympa ton profil :)") + if self.config['first_message'] != '': + self.browser.post_mail(id, unicode(self.config['first_message'])) self.logger.info(u'Visited profile %s ' % (id)) # Get score from the aum_score module diff --git a/modules/okc/pages.py b/modules/okc/pages.py index e638008d..77360c7c 100644 --- a/modules/okc/pages.py +++ b/modules/okc/pages.py @@ -188,8 +188,8 @@ class PhotosPage(BasePage): class PostMessagePage(BasePage): def post_mail(self, id, content): self.browser.select_form(name='f2') - self.browser['r1'] = id - self.browser['body'] = content + self.browser['r1'] = id.encode('utf-8') + self.browser['body'] = content.encode('utf-8') self.browser.submit() class VisitsPage(BasePage):