Esempio n. 1
0
def test_gohugo_parser(title, desc, content, tags, date, clean):
    expected_template = '''
---
title: ''' + title + '''
date: ''' + date + '''
draft: true
summary: ''' + desc + ''' ''' + content + '''
tags: ''' + str(tags) + '''
isfeed: true
id: 1
---
        '''
    parser = Parser()
    template, post_id = parser.gohugo_parser(title,
                                             desc,
                                             content,
                                             tags,
                                             date,
                                             post_id=1)

    if clean:
        assert_that(template).is_equal_to(expected_template) if title != '' \
            else assert_that(len(template)).is_greater_than(len(expected_template))
        assert_that(len(template)).is_equal_to(len(expected_template)) if title != '' \
            else assert_that(template).is_not_equal_to(expected_template)
    else:
        assert_that(template).is_not_equal_to(expected_template)
        assert_that(len(template)).is_less_than(len(expected_template)) if title != '' \
            else assert_that(len(template)).is_not_equal_to(len(expected_template))

    assert_that(post_id).is_not_none()
Esempio n. 2
0
def channel_handler(update: Update, context: CallbackContext) -> None:
    """handle channel messages"""

    chat_id = update.channel_post.chat_id
    message_id = update.channel_post.message_id

    message = update.channel_post
    entities = message.entities

    if len(message.text) <= 9:
        return

    tags = []
    title = []
    desc = []
    url = []

    for entity in entities:
        limit = entity.offset + entity.length
        value = message.text[entity.offset:limit]

        if entity.type == 'hashtag':
            tags.append(value)
        elif entity.type == 'bold':
            title.append(value)
        elif entity.type == 'italic':
            desc.append(value)
        elif entity.type == 'url':
            url.append(value)

    title = '. '.join(title)
    desc = '. '.join(desc)
    content = '\n'.join(url)

    parser = Parser()
    parser.gohugo_parser(title, desc, content, tags,
                         message.date.strftime("%Y-%m-%d"))

    Thread(target=parser.gohugo_save).start()
Esempio n. 3
0
def test_gohugo_save_with_git(title, desc, content, tags, date):
    parser = Parser()
    template, post_id = parser.gohugo_parser(title, desc, content, tags, date)
    filename = parser.gohugo_save()

    assert_that(filename).is_not_none()