Exemplo n.º 1
0
    def format(self, article, subscriber):
        """
        Constructs a dictionary that represents the parameters passed to the SMS InsertAlerts stored procedure
        :return: returns the sequence number of the subscriber and the constructed parameter dictionary
        """
        try:
            pub_seq_num = superdesk.get_resource_service(
                'subscribers').generate_sequence_number(subscriber)

            odbc_item = {
                'Sequence': pub_seq_num,
                'Category': article.get('anpa_category', [{}])[0].get('qcode'),
                'Headline': article.get('headline', '').replace('\'', '\'\''),
                'Priority': map_priority(article.get('priority'))
            }

            if article.get(EMBARGO):
                embargo = '{}{}'.format('Embargo Content. Timestamp: ',
                                        article.get(EMBARGO).isoformat())
                article['body_html'] = embargo + article['body_html']

            if article[ITEM_TYPE] == CONTENT_TYPE.PREFORMATTED:
                odbc_item['StoryText'] = article.get('body_html', '').replace(
                    '\'', '\'\'')  # @article_text
            elif article[ITEM_TYPE] == CONTENT_TYPE.TEXT:
                soup = BeautifulSoup(article.get('body_html', ''))
                odbc_item['StoryText'] = soup.text.replace('\'', '\'\'')

            odbc_item['ident'] = '0'

            return [(pub_seq_num, odbc_item)]
        except Exception as ex:
            raise FormatterError.AAPSMSFormatterError(ex, subscriber)
Exemplo n.º 2
0
    def format(self, article, subscriber, codes=None):
        """
        Constructs a dictionary that represents the parameters passed to the SMS InsertAlerts stored procedure
        :return: returns the sequence number of the subscriber and the constructed parameter dictionary
        """
        try:
            pub_seq_num = superdesk.get_resource_service(
                'subscribers').generate_sequence_number(subscriber)
            sms_message = article.get('sms_message',
                                      article.get('abstract',
                                                  '')).replace('\'', '\'\'')

            # category = 1 is used to indicate a test message
            category = '1' if superdesk.app.config.get('TEST_SMS_OUTPUT', True) is True \
                else article.get('anpa_category', [{}])[0].get('qcode').upper()

            odbc_item = {
                'Sequence': pub_seq_num,
                'Category': category,
                'Headline': BeautifulSoup(sms_message, 'html.parser').text,
                'Priority': map_priority(article.get('priority'))
            }

            body = self.append_body_footer(article)
            if article.get(EMBARGO):
                embargo = '{}{}'.format(
                    'Embargo Content. Timestamp: ',
                    get_utc_schedule(article, EMBARGO).isoformat())
                body = embargo + body

            if article[ITEM_TYPE] == CONTENT_TYPE.TEXT:
                body = BeautifulSoup(body, "html.parser").text

            odbc_item['StoryText'] = body.replace('\'',
                                                  '\'\'')  # @article_text
            odbc_item['ident'] = '0'

            return [(pub_seq_num, json.dumps(odbc_item))]
        except Exception as ex:
            raise FormatterError.AAPSMSFormatterError(ex, subscriber)