Skip to content

Commit

Permalink
Fix linkedin parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
amadejkastelic committed Nov 29, 2024
1 parent ea01859 commit e390206
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
15 changes: 11 additions & 4 deletions bot/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ def date_to_human_format(date: datetime.datetime) -> str:

def parse_relative_time(relative_time: str) -> datetime.timedelta:
units = {
'y': 'years',
'mo': 'months',
'w': 'weeks',
'd': 'days',
'h': 'hours',
'm': 'minutes',
Expand All @@ -165,7 +162,17 @@ def parse_relative_time(relative_time: str) -> datetime.timedelta:
unit = ''.join([ch for ch in relative_time if ch.isalpha()])

if unit not in units:
raise ValueError(f"Unsupported time unit: {unit}")
if unit in ['w', 'week', 'weeks']:
number *= 7
unit = 'd'
elif unit in ['mo', 'month', 'months']:
number *= 30
unit = 'd'
elif unit in ['y', 'year', 'years']:
number *= 365
unit = 'd'
else:
raise ValueError(f"Unsupported time unit: {unit}")

# Return the appropriate timedelta
return datetime.timedelta(**{units[unit]: number})
Expand Down
8 changes: 4 additions & 4 deletions bot/integrations/linkedin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ async def get_post(self, url: str) -> domain.Post:
page = await context.new_page()
await page.goto(url)

author = await page.locator('[data-tracking-control-name="public_post_feed-actor-name"]').inner_text()
description = await page.locator('[data-test-id="main-feed-activity-card__commentary"]').inner_text()
likes_text = await page.locator('[data-test-id="social-actions__reaction-count"]').inner_text()
author = await page.locator('[data-tracking-control-name="public_post_feed-actor-name"]').first.inner_text()
description = await page.locator('[data-test-id="main-feed-activity-card__commentary"]').first.inner_text()
likes_text = await page.locator('[data-test-id="social-actions__reaction-count"]').first.inner_text()
likes = int(likes_text.replace(',', '').replace('.', '') or 0)
relative_time = await page.locator('time').inner_text()
relative_time = await page.locator('time').first.inner_text()

post = domain.Post(
url=url,
Expand Down

0 comments on commit e390206

Please sign in to comment.