Skip to content

Commit

Permalink
fix(ipnews format) match the paragraph markers
Browse files Browse the repository at this point in the history
  • Loading branch information
marwoodandrew committed Jun 30, 2016
1 parent 94efa1f commit 3509e36
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
9 changes: 5 additions & 4 deletions server/aap/publish/formatters/aap_ipnews_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,20 @@ def format(self, article, subscriber, codes=None):
elif article.get(FORMAT, FORMATS.HTML) == FORMATS.HTML:
text = StringIO()
for p in soup.findAll('p'):
text.write('\x19\r\n')
text.write(' ')
ptext = p.get_text('\n')
for l in ptext.split('\n'):
if len(l) > 80:
text.write(textwrap.fill(l, 80).replace('\n', ' \r\n'))
else:
text.write(l + ' \r\n')
text.write('\x19\r\n')
body = text.getvalue().replace('\'', '\'\'')
# if this is the first take and we have a dateline inject it
if self.is_first_part(article) and 'dateline' in article and 'text' in article.get('dateline', {}):
if body.startswith('\x19\r\n'):
body = '\x19\r\n{} {}'.format(article.get('dateline').get('text').replace('\'', '\'\''),
body[3:])
if body.startswith(' '):
body = ' {} {}'.format(article.get('dateline').get('text').replace('\'', '\'\''),
body[3:])

odbc_item['article_text'] = body
odbc_item['texttab'] = 'x'
Expand Down
9 changes: 4 additions & 5 deletions server/aap/publish/formatters/aap_ipnews_formatter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def testIPNewsHtmlToText(self):
seq, item = f.format(article, subscriber)[0]
item = json.loads(item)

expected = '\r\nThe story body line 1 \r\nLine 2 \r\n\r\nabcdefghi abcdefghi abcdefghi abcdefghi ' \
'abcdefghi abcdefghi abcdefghi abcdefghi \r\n\r\nMORE'
expected = ' The story body line 1 \r\nLine 2 \r\n\r\n abcdefghi abcdefghi abcdefghi abcdefghi ' \
'abcdefghi abcdefghi abcdefghi abcdefghi \r\n\r\n\r\nMORE'
self.assertEqual(item['article_text'], expected)

def testLastTake(self):
Expand Down Expand Up @@ -150,9 +150,8 @@ def testLastTake(self):
f = AAPIpNewsFormatter()
seq, item = f.format(article, subscriber)[0]
item = json.loads(item)

expected = '\r\nThe story body line 1 \r\nLine 2 \r\n\r\nabcdefghi abcdefghi abcdefghi abcdefghi ' \
'abcdefghi abcdefghi abcdefghi abcdefghi \r\n\r\nAAP'
expected = ' The story body line 1 \r\nLine 2 \r\n\r\n abcdefghi abcdefghi abcdefghi abcdefghi ' \
'abcdefghi abcdefghi abcdefghi abcdefghi \r\n\r\n\r\nAAP'
self.assertEqual(item['article_text'], expected)

def testMultipleCategories(self):
Expand Down

0 comments on commit 3509e36

Please sign in to comment.