From 9bbaf70145f3791c579288ce24e745dc2cd1322c Mon Sep 17 00:00:00 2001 From: Ace Date: Thu, 25 Jun 2026 16:04:05 +0200 Subject: [PATCH] Checks done --- browser-use-service/main.py | 96 ++++++++++++++++++++++++++++++------- 1 file changed, 78 insertions(+), 18 deletions(-) diff --git a/browser-use-service/main.py b/browser-use-service/main.py index a6599a3..af098c5 100644 --- a/browser-use-service/main.py +++ b/browser-use-service/main.py @@ -147,7 +147,7 @@ def extract_agent_posts(agent_result: str, page_text: str) -> list[dict]: if isinstance(item, dict) and item.get('content'): posts.append({ 'content': item.get('content', ''), - 'author': item.get('author', ''), + 'author': item.get('author', '') or item.get('publisher', '') or '', 'url': item.get('url', ''), 'date': item.get('date', ''), }) @@ -155,11 +155,20 @@ def extract_agent_posts(agent_result: str, page_text: str) -> list[dict]: pass if not posts: - lines = [l.strip() for l in page_text.split('\n') if l.strip()] - for line in lines: - if len(line) > 30 and not any(skip in line.lower() for skip in - ['facebook', 'messenger', 'notification', 'comment', 'like', 'share']): - posts.append({'content': line[:500], 'author': '', 'url': '', 'date': ''}) + lines = [l.strip() for l in agent_result.split('\n') if l.strip()] + cur = [] + for l in lines: + if l.startswith(('1.', '2.', '3.', '4.', '5.', '6.', '7.', '8.', '9.', '- ', '* ')): + if cur: + combined = ' '.join(cur) + if len(combined) > 30: + posts.append({'content': combined[:500], 'author': '', 'url': '', 'date': ''}) + cur = [] + cur.append(l) + if cur: + combined = ' '.join(cur) + if len(combined) > 30: + posts.append({'content': combined[:500], 'author': '', 'url': '', 'date': ''}) return posts @@ -443,6 +452,18 @@ def _parse_fb_date(block: list[str]) -> str: pass return datetime.now().strftime('%Y-%m-%d') + +def _is_within_days(date_str: str, max_days: int = 3) -> bool: + """Check if date is within max_days from now. Empty/unparseable = keep.""" + if not date_str: + return True + try: + dt = datetime.strptime(date_str.strip(), '%Y-%m-%d') + return (datetime.now() - dt).days <= max_days + except ValueError: + return True + + def _clean_fb_text(text: str) -> str: cleaned_lines = [] for l in text.split('\n'): @@ -475,13 +496,26 @@ def _extract_posts_from_elements(elements: list[dict], base_url: str) -> list[di seen_texts.add(dekey) request_score = 2 if is_request(text) else 0 post_url = el.get('url') or base_url + + # Prefer JS-extracted date, fall back to text parsing + js_date = (el.get('date') or '').strip() + if js_date: + # Try ISO datetime from