Example #1
0
def _save_entries(path, entries):
    """ Save the url data to the db. """

    data = read_state(path)
    data = [] if not data else data
    data.extend(entries)
    save_state(path, data)

    return
Example #2
0
    def test_should_read_state_file(self):
        # Given
        _bot = ChatRoomJabberBot(self.jid, self.password, root=self.tempdir)
        state = {
            'users': {
                'foo': '*****@*****.**',
                'bar': '*****@*****.**'
            }
        }
        serialize.save_state(_bot.db, state)

        # When
        bot = ChatRoomJabberBot(self.jid, self.password, root=self.tempdir)

        # Then
        self.assertDictEqual(bot.users, state['users'])

        return
Example #3
0
    def save_state(self, extra_state=None):
        """ Persists the state of the bot. """

        self.lock.acquire()
        old_state = self.read_state()
        new_state = dict(
            users=self.users,
            invited=self.invited,
            storytellers=self.storytellers,
            topic=self.topic,
            ideas=self.ideas,
            gist_urls=self.gist_urls
        )
        old_state.update(new_state)
        if extra_state is not None:
            old_state.update(extra_state)

        serialize.save_state(self.db, old_state)

        self.lock.release()

        return