Exemplo n.º 1
0
def _get_email(bot, db, title, additional_content=None):
    """ Return the content to be used for the newsletter. """

    # Get urls from the db
    bot.lock.acquire()
    urls = serialize.read_state(db)
    bot.lock.release()

    entries = [
        entry for entry in _get_email_content(bot, urls[:])

        if len(entry['url']) != 0
    ]
    context = {'title': title}

    for entry in entries:
        if 'github.com/punchagan/childrens-park' in entry['url']:
            context.setdefault('code_updates', []).append(entry)

        else:
            context.setdefault('shared_links', []).append(entry)

    if additional_content is not None:
        context.update(additional_content)

    template = join(HERE, 'data', 'newsletter_template.html')
    return transform(render_template(template, context))
Exemplo n.º 2
0
    def read_state(self):
        """ Reads the persisted state. """

        self.lock.acquire()
        data = serialize.read_state(self.db)
        self.lock.release()

        return data
Exemplo n.º 3
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
Exemplo n.º 4
0
    def test_should_save_state_on_shutdown(self):
        # Given
        bot = ChatRoomJabberBot(self.jid, self.password, root=self.tempdir)
        bot.users = {
            'foo': '*****@*****.**'
        }

        # When
        bot.shutdown()

        # Then
        self.assertTrue(exists(bot.db))
        self.assertDictEqual(bot.users, serialize.read_state(bot.db)['users'])

        return
Exemplo n.º 5
0
def main(bot, user, args):
    """ Show URLs posted by buddies. The ones since I last checked """

    path = join(bot.root, DB_NAME)

    bot.lock.acquire()
    data = serialize.read_state(path)
    bot.lock.release()

    if len(data) == 0:
        message = 'No new urls.'

    else:
        subject = 'Park updates since last newsletter'
        additional_content = {'stories': _get_stories(bot, save=False)}
        body = _get_email(bot, path, subject, additional_content)
        send_email(user, subject, body, typ_='html', debug=bot.debug)
        message = 'Sent email to %s' % user

    return message