Beispiel #1
0
 def update_contacts(self):
     for contact in self.get_contacts():
         if Buddy.filter(account=contact['account'],
                         identifier=contact['identifier']).count() < 1:
             buddy = Buddy(enabled=False, **contact)
             buddy.save()
         else:
             print('Contact already exists: {}'.format(contact['identifier']))
Beispiel #2
0
def run_generators(q_messages):
    print('run_generator')
    from hubbub.generator import HeartBeatGenerator

    if 'fake' in argv:
        from hubbub.adapter.fake import FakeAdapter as Adapter
    else:
        from hubbub.adapter.pidgin_dbus import PidginDBusAdapter as Adapter
    adapter = Adapter(None)  # Write-only adapter, no queue

    import threading
    try:
        from Queue import Queue as QQueue
    except ImportError:
        from queue import Queue as QQueue
    def start_generator(buddy, q):
        print('B', [buddy.id])
        generator = HeartBeatGenerator(adapter, buddy.id, q)
        generator.run()

    from hubbub.drugstore.models import Buddy
    queues = {}
    #for buddy in Buddy.select().where(Buddy.enabled):
    for buddy in Buddy.select():
        q = QQueue()
        queues[buddy.identifier] = q
        t = threading.Thread(target=start_generator, args=(buddy, q))
        t.start()

    while True:
        msg = q_messages.get()
        for q in queues.values():
            q.put(msg)
Beispiel #3
0
def friends_switch(friend_id):
    active = request.params.get('active') == "true"
    buddy = Buddy.get(identifier=friend_id)
    buddy.enabled = not active
    buddy.save()
    print('friend_id', friend_id)
    print('active', active)
    return json.dumps({'active': buddy.enabled})
Beispiel #4
0
def friends_list():
    return json.dumps([
        {
            'id': b.identifier,
            'alias': b.alias,
            'active': b.enabled,
        }
        for b in Buddy.select()
        ])
Beispiel #5
0
 def run(self):
     while True:
         print('generator: new loop')
         delay = self.delay()
         print('delay: {}s'.format(delay))
         try:
             # We get a real message
             # TODO: Distinguish between received and sent messages !!!
             message = self.q_messages.get(timeout=delay)
             # We don't so we send a dummy one
             print('generator: got a real message:', message)
         except Empty:
             print('generator: sending a dummy message')
             buddy = Buddy.get(id=self.buddy_id)
             if buddy.enabled:
                 length = int(gauss(10, 8))
                 self.adapter.send_im_msg('?DUMMY:' + ('.' * max(1, length)),
                                          buddy.identifier)
Beispiel #6
0
 def run(self):
     while True:
         buddy = Buddy.get(id=self.buddy_id)
         if buddy.enabled:
             self.adapter.send_im_msg('?DUMMY:', buddy.identifier)
         sleep(5)