Skip to content

Commit 5aa5b20

Browse files
authored
Add news-use demo: News monitoring agent with sentiment analysis (#3066)
News monitoring agent with sentiment analysis. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds the News-Use demo: a browser agent that monitors news sites, opens the latest article, and summarizes it with sentiment. Includes CLI and docs, with JSON persistence and dedup for continuous runs. - **New Features** - New example app (examples/apps/news-use) with news_monitor.py and README. - Agent opens the newest headline and extracts title, URL, posting time, and content. - Generates short (10-word) and long (~100-word) summaries plus sentiment (positive/neutral/negative). - CLI supports --once, --interval, --url, and --debug; saves to news_data.json with hash-based dedup. - Docs page (docs/examples/apps/news-use.mdx) with setup, video, and programmatic API; requires browser-use v0.7.7+ and GEMINI_API_KEY. <!-- End of auto-generated description by cubic. -->
2 parents 2633cf7 + 123ac79 commit 5aa5b20

File tree

3 files changed

+511
-0
lines changed

3 files changed

+511
-0
lines changed

docs/examples/apps/news-use.mdx

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
title: "News-Use (News Monitor)"
3+
description: "Monitor news websites and extract articles with sentiment analysis using browser agents and Google Gemini."
4+
icon: "newspaper"
5+
mode: "wide"
6+
---
7+
8+
<Note>
9+
This demo requires browser-use v0.7.7+.
10+
</Note>
11+
12+
<video
13+
controls
14+
className="w-full aspect-video rounded-xl"
15+
src="https://github.com/user-attachments/assets/650843ee-0b4d-431a-983f-6c1af3d0ffd8">
16+
</video>
17+
18+
## Features
19+
20+
1. Agent visits any news website automatically
21+
2. Finds and clicks the most recent headline article
22+
3. Extracts title, URL, posting time, and full content
23+
4. Generates short/long summaries with sentiment analysis
24+
5. Persistent deduplication across monitoring sessions
25+
26+
## Setup
27+
28+
Make sure the newest version of browser-use is installed:
29+
```bash
30+
pip install -U browser-use
31+
```
32+
33+
Export your Gemini API key, get it from: [Google AI Studio](https://makersuite.google.com/app/apikey)
34+
```bash
35+
export GEMINI_API_KEY='your-google-api-key-here'
36+
```
37+
38+
## Usage Examples
39+
40+
```bash
41+
# One-time extraction - Get the latest article and exit
42+
python news_monitor.py --once
43+
44+
# Monitor Bloomberg continuously (default)
45+
python news_monitor.py
46+
47+
# Monitor TechCrunch every 60 seconds
48+
python news_monitor.py --url https://techcrunch.com --interval 60
49+
50+
# Debug mode - See browser in action
51+
python news_monitor.py --once --debug
52+
```
53+
54+
## Output Format
55+
56+
Articles are displayed with timestamp, sentiment emoji, and summary:
57+
58+
```
59+
[2025-09-11 02:49:21] - 🟢 - Klarna's IPO raises $1.4B, benefiting existing investors
60+
[2025-09-11 02:54:15] - 🔴 - Tech layoffs continue as major firms cut workforce
61+
[2025-09-11 02:59:33] - 🟡 - Federal Reserve maintains interest rates unchanged
62+
```
63+
64+
**Sentiment Indicators:**
65+
- 🟢 **Positive** - Good news, growth, success stories
66+
- 🟡 **Neutral** - Factual reporting, announcements, updates
67+
- 🔴 **Negative** - Challenges, losses, negative events
68+
69+
## Data Persistence
70+
71+
All extracted articles are saved to `news_data.json` with complete metadata:
72+
73+
```json
74+
{
75+
"hash": "a1b2c3d4...",
76+
"pulled_at": "2025-09-11T02:49:21Z",
77+
"data": {
78+
"title": "Klarna's IPO pops, raising $1.4B",
79+
"url": "https://techcrunch.com/2025/09/11/klarna-ipo/",
80+
"posting_time": "12:11 PM PDT · September 10, 2025",
81+
"short_summary": "Klarna's IPO raises $1.4B, benefiting existing investors like Sequoia.",
82+
"long_summary": "Fintech Klarna successfully IPO'd on the NYSE...",
83+
"sentiment": "positive"
84+
}
85+
}
86+
```
87+
88+
## Programmatic Usage
89+
90+
```python
91+
import asyncio
92+
from news_monitor import extract_latest_article
93+
94+
async def main():
95+
# Extract latest article from any news site
96+
result = await extract_latest_article(
97+
site_url="https://techcrunch.com",
98+
debug=False
99+
)
100+
101+
if result["status"] == "success":
102+
article = result["data"]
103+
print(f"📰 {article['title']}")
104+
print(f"😊 Sentiment: {article['sentiment']}")
105+
print(f"📝 Summary: {article['short_summary']}")
106+
107+
asyncio.run(main())
108+
```
109+
110+
## Advanced Configuration
111+
112+
```python
113+
# Custom monitoring with filters
114+
async def monitor_with_filters():
115+
while True:
116+
result = await extract_latest_article("https://bloomberg.com")
117+
if result["status"] == "success":
118+
article = result["data"]
119+
# Only alert on negative market news
120+
if article["sentiment"] == "negative" and "market" in article["title"].lower():
121+
send_alert(article)
122+
await asyncio.sleep(300) # Check every 5 minutes
123+
```
124+
125+
## Source Code
126+
127+
Full implementation: [https://github.com/browser-use/browser-use/tree/main/examples/apps/news-use](https://github.com/browser-use/browser-use/tree/main/examples/apps/news-use)

examples/apps/news-use/README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# News-Use
2+
3+
Automatically monitor news websites and extract the latest articles with sentiment analysis using browser agents and Google Gemini.
4+
5+
> [!CAUTION]
6+
> This demo requires browser-use v0.7.7+.
7+
8+
https://github.com/user-attachments/assets/650843ee-0b4d-431a-983f-6c1af3d0ffd8
9+
10+
## Features
11+
12+
1. Agent visits any news website
13+
2. Finds and clicks the most recent headline article
14+
3. Extracts title, URL, posting time, and content
15+
4. Generates short/long summaries with sentiment analysis
16+
5. Persistent deduplication across restarts
17+
18+
## Setup
19+
20+
Make sure the newest version of browser-use is installed:
21+
```bash
22+
pip install -U browser-use
23+
```
24+
25+
Export your Gemini API key, get it from: [Google AI Studio](https://makersuite.google.com/app/apikey)
26+
```
27+
export GEMINI_API_KEY='your-google-api-key-here'
28+
```
29+
30+
## Usage
31+
32+
```bash
33+
# One-time extraction - Get the latest article and exit
34+
python news_monitor.py --once
35+
36+
# Continuous monitoring - Check every 5 minutes (default)
37+
python news_monitor.py
38+
39+
# Custom interval - Check every 60 seconds
40+
python news_monitor.py --interval 60
41+
42+
# Different news site
43+
python news_monitor.py --url https://techcrunch.com
44+
45+
# Debug mode - See browser in action with verbose output
46+
python news_monitor.py --once --debug
47+
```
48+
49+
## Output Format
50+
51+
Articles are displayed with timestamp, sentiment emoji, and summary:
52+
```
53+
[2025-09-11 02:49:21] - 🟢 - Klarna's IPO raises $1.4B, benefiting existing investors
54+
```
55+
56+
Sentiment indicators:
57+
- 🟢 Positive
58+
- 🟡 Neutral
59+
- 🔴 Negative
60+
61+
## Programmatic Usage
62+
63+
```python
64+
import asyncio
65+
from news_monitor import extract_latest_article
66+
67+
async def main():
68+
result = await extract_latest_article(
69+
site_url="https://techcrunch.com",
70+
debug=False
71+
)
72+
if result["status"] == "success":
73+
article = result["data"]
74+
print(f"Latest: {article['title']}")
75+
76+
asyncio.run(main())
77+
```
78+
79+
## License
80+
81+
MIT

0 commit comments

Comments
 (0)