Skip to content

Commit

Permalink
Merge pull request #9 from sopel-irc/missing-url
Browse files Browse the repository at this point in the history
Handle missing/empty `url` in story & job item types
  • Loading branch information
dgw authored Dec 8, 2023
2 parents 0193dd3 + 24ffda2 commit e782c2b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions sopel_hackernews/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,29 +113,29 @@ def forward_hn(bot, trigger):
truncation=' […]',
)
elif item['type'] == 'story':
domain = urlparse(item['url']).hostname
url = item.get('url')

bot.say(
'Story: {title}{dead} | 👤 {author} | 📆 {when} | ▲ {score} | 🗨️ {comments} | {url}'.format(
'Story: {title}{dead} | 👤 {author} | 📆 {when} | ▲ {score} | 🗨️ {comments}{url}'.format(
title=item['title'],
dead=' [DEAD]' if item.get('dead', False) else '',
author=item.get('by') or '(nobody)',
when=get_formatted_timestamp(item['time'], trigger.sender, bot),
score=item['score'],
comments=item['descendants'],
url=item['url'],
url=(' | ' + url) if url else '',
),
truncation=' ' + domain,
truncation=(' ' + urlparse(url).hostname) if url else ' …',
)
elif item['type'] == 'job':
domain = urlparse(item['url']).hostname
url = item.get('url')

bot.say(
'Job: {title} | 👤 {author} | 📆 {when} | {url}'.format(
'Job: {title} | 👤 {author} | 📆 {when}{url}'.format(
title=item['title'],
author=item.get('by') or '(nobody)',
when=get_formatted_timestamp(item['time'], trigger.sender, bot),
url=item['url'],
url=(' | ' + url) if url else '',
),
truncation=' ' + domain,
truncation=(' ' + urlparse(url).hostname) if url else ' …',
)

0 comments on commit e782c2b

Please sign in to comment.