trendscout 0.3.0__tar.gz → 1.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- trendscout-1.1.0/PKG-INFO +255 -0
- trendscout-1.1.0/README.md +227 -0
- {trendscout-0.3.0 → trendscout-1.1.0}/pyproject.toml +3 -3
- trendscout-1.1.0/tests/test_basic.py +198 -0
- trendscout-1.1.0/trendscout/__init__.py +227 -0
- trendscout-1.1.0/trendscout/scraper.py +55 -0
- trendscout-1.1.0/trendscout/sentiment.py +113 -0
- trendscout-1.1.0/trendscout/sources/__init__.py +1 -0
- trendscout-1.1.0/trendscout/sources/hackernews.py +121 -0
- trendscout-1.1.0/trendscout/sources/rss.py +152 -0
- trendscout-1.1.0/trendscout/velocity.py +87 -0
- trendscout-1.1.0/trendscout.egg-info/PKG-INFO +255 -0
- {trendscout-0.3.0 → trendscout-1.1.0}/trendscout.egg-info/SOURCES.txt +5 -1
- trendscout-0.3.0/PKG-INFO +0 -68
- trendscout-0.3.0/README.md +0 -40
- trendscout-0.3.0/tests/test_basic.py +0 -56
- trendscout-0.3.0/trendscout/__init__.py +0 -42
- trendscout-0.3.0/trendscout/scraper.py +0 -52
- trendscout-0.3.0/trendscout/sentiment.py +0 -31
- trendscout-0.3.0/trendscout.egg-info/PKG-INFO +0 -68
- {trendscout-0.3.0 → trendscout-1.1.0}/setup.cfg +0 -0
- {trendscout-0.3.0 → trendscout-1.1.0}/trendscout.egg-info/dependency_links.txt +0 -0
- {trendscout-0.3.0 → trendscout-1.1.0}/trendscout.egg-info/requires.txt +0 -0
- {trendscout-0.3.0 → trendscout-1.1.0}/trendscout.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: trendscout
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Real-time trend intelligence with HackerNews, RSS feeds, trend velocity, and multi-domain sentiment
|
|
5
|
+
Author-email: Teyfik OZ <teyfikoz@yahoo.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/teyfikoz/trendscout
|
|
8
|
+
Project-URL: Repository, https://github.com/teyfikoz/trendscout
|
|
9
|
+
Project-URL: Issues, https://github.com/teyfikoz/trendscout/issues
|
|
10
|
+
Keywords: trends,sentiment,market-analysis,nlp,scraping
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
Requires-Dist: beautifulsoup4>=4.12.0
|
|
22
|
+
Requires-Dist: pandas>=2.0.0
|
|
23
|
+
Requires-Dist: requests>=2.31.0
|
|
24
|
+
Requires-Dist: textblob>=0.17.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
27
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
28
|
+
|
|
29
|
+
# TrendScout
|
|
30
|
+
|
|
31
|
+
**Real-time trend intelligence** — HackerNews search, RSS feed parsing, trend velocity scoring, and multi-domain sentiment analysis. No API key required.
|
|
32
|
+
|
|
33
|
+
[](https://pypi.org/project/trendscout/)
|
|
34
|
+
[](https://github.com/teyfikoz/trendscout/actions/workflows/ci.yml)
|
|
35
|
+
[](https://www.python.org/)
|
|
36
|
+
[](https://opensource.org/licenses/MIT)
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install trendscout
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Quick Start
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from trendscout import TrendScout
|
|
48
|
+
|
|
49
|
+
ts = TrendScout()
|
|
50
|
+
|
|
51
|
+
# Real HackerNews data — no API key needed
|
|
52
|
+
df = ts.get_hackernews_trends("AI agents", limit=10)
|
|
53
|
+
print(df[['title', 'score', 'num_comments']].head())
|
|
54
|
+
|
|
55
|
+
# Sentiment with market signal
|
|
56
|
+
result = ts.analyze_sentiment("GPT-5 crushes every benchmark!", domain="tech")
|
|
57
|
+
print(result)
|
|
58
|
+
|
|
59
|
+
# Trend velocity
|
|
60
|
+
velocity = ts.get_trend_velocity("rust programming language")
|
|
61
|
+
print(velocity)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Features at a Glance
|
|
67
|
+
|
|
68
|
+
| Feature | Description |
|
|
69
|
+
|---------|-------------|
|
|
70
|
+
| **HackerNews API** | Real stories via Algolia — free, no key, always fresh |
|
|
71
|
+
| **RSS/Atom Feeds** | Tech, AI, business, Python presets + custom URLs |
|
|
72
|
+
| **Trend Velocity** | Momentum score 0–1 with status: emerging/peak/stable/declining |
|
|
73
|
+
| **Sentiment Analysis** | TextBlob + domain-aware lexicons (financial, tech, social) |
|
|
74
|
+
| **Multi-topic Analysis** | Compare topics side-by-side in a ranked DataFrame |
|
|
75
|
+
| **DataFrame Batch** | Bulk sentiment analysis on any text DataFrame |
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## HackerNews Trends (Real Data)
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from trendscout import TrendScout
|
|
83
|
+
|
|
84
|
+
ts = TrendScout()
|
|
85
|
+
|
|
86
|
+
# Search by keyword — uses HN Algolia API
|
|
87
|
+
df = ts.get_hackernews_trends("large language models", limit=20)
|
|
88
|
+
print(df[['title', 'score', 'num_comments', 'author']].head(5))
|
|
89
|
+
# title score num_comments author
|
|
90
|
+
# 0 LLMs are now good enough for production use 847 312 pg
|
|
91
|
+
# 1 Show HN: Open-source LLM benchmark suite 412 189 teyfikoz
|
|
92
|
+
# ...
|
|
93
|
+
|
|
94
|
+
# Top stories right now
|
|
95
|
+
from trendscout.sources.hackernews import HackerNewsSource
|
|
96
|
+
hn = HackerNewsSource()
|
|
97
|
+
top = hn.get_top_stories(limit=10)
|
|
98
|
+
for story in top:
|
|
99
|
+
print(f"[{story.score:4d}] {story.title[:70]}")
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## RSS / Atom Feed Parsing
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
ts = TrendScout()
|
|
108
|
+
|
|
109
|
+
# Preset categories: tech | ai | business | python | startup
|
|
110
|
+
tech_news = ts.get_rss_trends(category="tech", limit=15)
|
|
111
|
+
ai_news = ts.get_rss_trends(category="ai", limit=10)
|
|
112
|
+
|
|
113
|
+
print(tech_news[['title', 'published', 'feed_name']].head())
|
|
114
|
+
|
|
115
|
+
# Custom feed URLs
|
|
116
|
+
custom = ts.get_rss_trends(
|
|
117
|
+
feeds=[
|
|
118
|
+
"https://feeds.hnrss.org/newest?points=100",
|
|
119
|
+
"https://planetpython.org/rss20.xml",
|
|
120
|
+
],
|
|
121
|
+
limit=20,
|
|
122
|
+
)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Trend Velocity Scoring
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
velocity = ts.get_trend_velocity("quantum computing")
|
|
131
|
+
print(velocity)
|
|
132
|
+
# Trend : quantum computing
|
|
133
|
+
# Velocity: [████████░░░░░░░░░░░░] 0.42
|
|
134
|
+
# Status : PEAK
|
|
135
|
+
# Articles: 12 | Avg engagement: 156
|
|
136
|
+
# → Trending now — maximise exposure before it plateaus
|
|
137
|
+
|
|
138
|
+
# Status meanings:
|
|
139
|
+
# emerging (0.70–1.00) — fast-growing, act now
|
|
140
|
+
# peak (0.40–0.70) — trending, maximise reach
|
|
141
|
+
# stable (0.15–0.40) — evergreen, good for long-form
|
|
142
|
+
# declining (0.00–0.15) — losing momentum, pivot keywords
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Multi-Topic Comparison
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
report = ts.analyze_topics(
|
|
151
|
+
["AI agents", "blockchain", "quantum computing", "WebAssembly", "Rust"],
|
|
152
|
+
source="hackernews",
|
|
153
|
+
)
|
|
154
|
+
print(report.to_string(index=False))
|
|
155
|
+
# topic velocity_score status article_count avg_engagement
|
|
156
|
+
# AI agents 0.87 emerging 24 312.4
|
|
157
|
+
# Rust 0.64 peak 18 198.2
|
|
158
|
+
# quantum computing 0.42 peak 12 156.1
|
|
159
|
+
# blockchain 0.21 stable 8 89.3
|
|
160
|
+
# WebAssembly 0.09 declining 4 42.0
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## Sentiment Analysis
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
# General sentiment
|
|
169
|
+
result = ts.analyze_sentiment("The product launch exceeded all expectations.")
|
|
170
|
+
print(result.label) # positive
|
|
171
|
+
print(result.intensity) # strong
|
|
172
|
+
print(result.polarity) # 0.625
|
|
173
|
+
|
|
174
|
+
# Financial domain (detects bullish/bearish signals)
|
|
175
|
+
fin = ts.analyze_sentiment("Revenue surged 40% beating analyst estimates.", domain="financial")
|
|
176
|
+
print(fin.market_signal) # bullish
|
|
177
|
+
print(fin.confidence) # 0.92
|
|
178
|
+
|
|
179
|
+
# Tech news domain
|
|
180
|
+
tech = ts.analyze_sentiment("Critical vulnerability found in popular library.", domain="tech")
|
|
181
|
+
print(tech.market_signal) # bearish
|
|
182
|
+
print(tech.label) # negative
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Batch DataFrame Analysis
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
import pandas as pd
|
|
189
|
+
|
|
190
|
+
headlines = pd.DataFrame({
|
|
191
|
+
'headline': [
|
|
192
|
+
"OpenAI releases new model beating GPT-4",
|
|
193
|
+
"Tech stocks plunge amid regulatory fears",
|
|
194
|
+
"Startup raises $50M Series B for AI platform",
|
|
195
|
+
"Security breach affects millions of users",
|
|
196
|
+
]
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
result = ts.analyze_dataframe(headlines, text_col="headline", domain="financial")
|
|
200
|
+
print(result[['headline', 'sentiment_label', 'market_signal', 'polarity']])
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## Direct Source Access
|
|
206
|
+
|
|
207
|
+
```python
|
|
208
|
+
from trendscout.sources.hackernews import HackerNewsSource
|
|
209
|
+
from trendscout.sources.rss import RSSFeedSource
|
|
210
|
+
|
|
211
|
+
# HackerNews
|
|
212
|
+
hn = HackerNewsSource()
|
|
213
|
+
stories = hn.search("python async", limit=5)
|
|
214
|
+
for s in stories:
|
|
215
|
+
print(f"[{s.score}] {s.title}")
|
|
216
|
+
|
|
217
|
+
# RSS
|
|
218
|
+
rss = RSSFeedSource()
|
|
219
|
+
items = rss.fetch("https://feeds.hnrss.org/newest?points=100", limit=5)
|
|
220
|
+
for item in items:
|
|
221
|
+
print(item.title)
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## Full Intelligence Pipeline
|
|
227
|
+
|
|
228
|
+
```python
|
|
229
|
+
from trendscout import TrendScout
|
|
230
|
+
|
|
231
|
+
ts = TrendScout()
|
|
232
|
+
topics = ["AI agents", "edge computing", "Web3", "open source LLMs"]
|
|
233
|
+
|
|
234
|
+
# 1. Velocity comparison
|
|
235
|
+
report = ts.analyze_topics(topics)
|
|
236
|
+
|
|
237
|
+
# 2. Fetch real articles for the top trend
|
|
238
|
+
top_topic = report.iloc[0]['topic']
|
|
239
|
+
articles = ts.get_hackernews_trends(top_topic, limit=20)
|
|
240
|
+
|
|
241
|
+
# 3. Batch sentiment on the articles
|
|
242
|
+
enriched = ts.analyze_dataframe(articles, text_col="title", domain="tech")
|
|
243
|
+
|
|
244
|
+
# 4. Summary
|
|
245
|
+
bullish_count = (enriched['market_signal'] == 'bullish').sum()
|
|
246
|
+
print(f"Top trend: {top_topic}")
|
|
247
|
+
print(f"Velocity: {report.iloc[0]['velocity_score']:.2f} ({report.iloc[0]['status']})")
|
|
248
|
+
print(f"Positive articles: {bullish_count}/{len(enriched)}")
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## License
|
|
254
|
+
|
|
255
|
+
MIT — [Teyfik Öz](https://github.com/teyfikoz)
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
# TrendScout
|
|
2
|
+
|
|
3
|
+
**Real-time trend intelligence** — HackerNews search, RSS feed parsing, trend velocity scoring, and multi-domain sentiment analysis. No API key required.
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/trendscout/)
|
|
6
|
+
[](https://github.com/teyfikoz/trendscout/actions/workflows/ci.yml)
|
|
7
|
+
[](https://www.python.org/)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install trendscout
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from trendscout import TrendScout
|
|
20
|
+
|
|
21
|
+
ts = TrendScout()
|
|
22
|
+
|
|
23
|
+
# Real HackerNews data — no API key needed
|
|
24
|
+
df = ts.get_hackernews_trends("AI agents", limit=10)
|
|
25
|
+
print(df[['title', 'score', 'num_comments']].head())
|
|
26
|
+
|
|
27
|
+
# Sentiment with market signal
|
|
28
|
+
result = ts.analyze_sentiment("GPT-5 crushes every benchmark!", domain="tech")
|
|
29
|
+
print(result)
|
|
30
|
+
|
|
31
|
+
# Trend velocity
|
|
32
|
+
velocity = ts.get_trend_velocity("rust programming language")
|
|
33
|
+
print(velocity)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Features at a Glance
|
|
39
|
+
|
|
40
|
+
| Feature | Description |
|
|
41
|
+
|---------|-------------|
|
|
42
|
+
| **HackerNews API** | Real stories via Algolia — free, no key, always fresh |
|
|
43
|
+
| **RSS/Atom Feeds** | Tech, AI, business, Python presets + custom URLs |
|
|
44
|
+
| **Trend Velocity** | Momentum score 0–1 with status: emerging/peak/stable/declining |
|
|
45
|
+
| **Sentiment Analysis** | TextBlob + domain-aware lexicons (financial, tech, social) |
|
|
46
|
+
| **Multi-topic Analysis** | Compare topics side-by-side in a ranked DataFrame |
|
|
47
|
+
| **DataFrame Batch** | Bulk sentiment analysis on any text DataFrame |
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## HackerNews Trends (Real Data)
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from trendscout import TrendScout
|
|
55
|
+
|
|
56
|
+
ts = TrendScout()
|
|
57
|
+
|
|
58
|
+
# Search by keyword — uses HN Algolia API
|
|
59
|
+
df = ts.get_hackernews_trends("large language models", limit=20)
|
|
60
|
+
print(df[['title', 'score', 'num_comments', 'author']].head(5))
|
|
61
|
+
# title score num_comments author
|
|
62
|
+
# 0 LLMs are now good enough for production use 847 312 pg
|
|
63
|
+
# 1 Show HN: Open-source LLM benchmark suite 412 189 teyfikoz
|
|
64
|
+
# ...
|
|
65
|
+
|
|
66
|
+
# Top stories right now
|
|
67
|
+
from trendscout.sources.hackernews import HackerNewsSource
|
|
68
|
+
hn = HackerNewsSource()
|
|
69
|
+
top = hn.get_top_stories(limit=10)
|
|
70
|
+
for story in top:
|
|
71
|
+
print(f"[{story.score:4d}] {story.title[:70]}")
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## RSS / Atom Feed Parsing
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
ts = TrendScout()
|
|
80
|
+
|
|
81
|
+
# Preset categories: tech | ai | business | python | startup
|
|
82
|
+
tech_news = ts.get_rss_trends(category="tech", limit=15)
|
|
83
|
+
ai_news = ts.get_rss_trends(category="ai", limit=10)
|
|
84
|
+
|
|
85
|
+
print(tech_news[['title', 'published', 'feed_name']].head())
|
|
86
|
+
|
|
87
|
+
# Custom feed URLs
|
|
88
|
+
custom = ts.get_rss_trends(
|
|
89
|
+
feeds=[
|
|
90
|
+
"https://feeds.hnrss.org/newest?points=100",
|
|
91
|
+
"https://planetpython.org/rss20.xml",
|
|
92
|
+
],
|
|
93
|
+
limit=20,
|
|
94
|
+
)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Trend Velocity Scoring
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
velocity = ts.get_trend_velocity("quantum computing")
|
|
103
|
+
print(velocity)
|
|
104
|
+
# Trend : quantum computing
|
|
105
|
+
# Velocity: [████████░░░░░░░░░░░░] 0.42
|
|
106
|
+
# Status : PEAK
|
|
107
|
+
# Articles: 12 | Avg engagement: 156
|
|
108
|
+
# → Trending now — maximise exposure before it plateaus
|
|
109
|
+
|
|
110
|
+
# Status meanings:
|
|
111
|
+
# emerging (0.70–1.00) — fast-growing, act now
|
|
112
|
+
# peak (0.40–0.70) — trending, maximise reach
|
|
113
|
+
# stable (0.15–0.40) — evergreen, good for long-form
|
|
114
|
+
# declining (0.00–0.15) — losing momentum, pivot keywords
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Multi-Topic Comparison
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
report = ts.analyze_topics(
|
|
123
|
+
["AI agents", "blockchain", "quantum computing", "WebAssembly", "Rust"],
|
|
124
|
+
source="hackernews",
|
|
125
|
+
)
|
|
126
|
+
print(report.to_string(index=False))
|
|
127
|
+
# topic velocity_score status article_count avg_engagement
|
|
128
|
+
# AI agents 0.87 emerging 24 312.4
|
|
129
|
+
# Rust 0.64 peak 18 198.2
|
|
130
|
+
# quantum computing 0.42 peak 12 156.1
|
|
131
|
+
# blockchain 0.21 stable 8 89.3
|
|
132
|
+
# WebAssembly 0.09 declining 4 42.0
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Sentiment Analysis
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
# General sentiment
|
|
141
|
+
result = ts.analyze_sentiment("The product launch exceeded all expectations.")
|
|
142
|
+
print(result.label) # positive
|
|
143
|
+
print(result.intensity) # strong
|
|
144
|
+
print(result.polarity) # 0.625
|
|
145
|
+
|
|
146
|
+
# Financial domain (detects bullish/bearish signals)
|
|
147
|
+
fin = ts.analyze_sentiment("Revenue surged 40% beating analyst estimates.", domain="financial")
|
|
148
|
+
print(fin.market_signal) # bullish
|
|
149
|
+
print(fin.confidence) # 0.92
|
|
150
|
+
|
|
151
|
+
# Tech news domain
|
|
152
|
+
tech = ts.analyze_sentiment("Critical vulnerability found in popular library.", domain="tech")
|
|
153
|
+
print(tech.market_signal) # bearish
|
|
154
|
+
print(tech.label) # negative
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Batch DataFrame Analysis
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
import pandas as pd
|
|
161
|
+
|
|
162
|
+
headlines = pd.DataFrame({
|
|
163
|
+
'headline': [
|
|
164
|
+
"OpenAI releases new model beating GPT-4",
|
|
165
|
+
"Tech stocks plunge amid regulatory fears",
|
|
166
|
+
"Startup raises $50M Series B for AI platform",
|
|
167
|
+
"Security breach affects millions of users",
|
|
168
|
+
]
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
result = ts.analyze_dataframe(headlines, text_col="headline", domain="financial")
|
|
172
|
+
print(result[['headline', 'sentiment_label', 'market_signal', 'polarity']])
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## Direct Source Access
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
from trendscout.sources.hackernews import HackerNewsSource
|
|
181
|
+
from trendscout.sources.rss import RSSFeedSource
|
|
182
|
+
|
|
183
|
+
# HackerNews
|
|
184
|
+
hn = HackerNewsSource()
|
|
185
|
+
stories = hn.search("python async", limit=5)
|
|
186
|
+
for s in stories:
|
|
187
|
+
print(f"[{s.score}] {s.title}")
|
|
188
|
+
|
|
189
|
+
# RSS
|
|
190
|
+
rss = RSSFeedSource()
|
|
191
|
+
items = rss.fetch("https://feeds.hnrss.org/newest?points=100", limit=5)
|
|
192
|
+
for item in items:
|
|
193
|
+
print(item.title)
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## Full Intelligence Pipeline
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
from trendscout import TrendScout
|
|
202
|
+
|
|
203
|
+
ts = TrendScout()
|
|
204
|
+
topics = ["AI agents", "edge computing", "Web3", "open source LLMs"]
|
|
205
|
+
|
|
206
|
+
# 1. Velocity comparison
|
|
207
|
+
report = ts.analyze_topics(topics)
|
|
208
|
+
|
|
209
|
+
# 2. Fetch real articles for the top trend
|
|
210
|
+
top_topic = report.iloc[0]['topic']
|
|
211
|
+
articles = ts.get_hackernews_trends(top_topic, limit=20)
|
|
212
|
+
|
|
213
|
+
# 3. Batch sentiment on the articles
|
|
214
|
+
enriched = ts.analyze_dataframe(articles, text_col="title", domain="tech")
|
|
215
|
+
|
|
216
|
+
# 4. Summary
|
|
217
|
+
bullish_count = (enriched['market_signal'] == 'bullish').sum()
|
|
218
|
+
print(f"Top trend: {top_topic}")
|
|
219
|
+
print(f"Velocity: {report.iloc[0]['velocity_score']:.2f} ({report.iloc[0]['status']})")
|
|
220
|
+
print(f"Positive articles: {bullish_count}/{len(enriched)}")
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## License
|
|
226
|
+
|
|
227
|
+
MIT — [Teyfik Öz](https://github.com/teyfikoz)
|
|
@@ -4,15 +4,15 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "trendscout"
|
|
7
|
-
version = "
|
|
8
|
-
description = "
|
|
7
|
+
version = "1.1.0"
|
|
8
|
+
description = "Real-time trend intelligence with HackerNews, RSS feeds, trend velocity, and multi-domain sentiment"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [
|
|
11
11
|
{ name = "Teyfik OZ", email = "teyfikoz@yahoo.com" }
|
|
12
12
|
]
|
|
13
13
|
license = {text = "MIT"}
|
|
14
14
|
classifiers = [
|
|
15
|
-
"Development Status ::
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
16
|
"Intended Audience :: Developers",
|
|
17
17
|
"Programming Language :: Python :: 3",
|
|
18
18
|
"Programming Language :: Python :: 3.10",
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"""Tests for TrendScout v1.0.0."""
|
|
2
|
+
|
|
3
|
+
import pandas as pd
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def test_version():
|
|
8
|
+
import trendscout
|
|
9
|
+
assert trendscout.__version__ == "1.1.0"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_all_exports():
|
|
13
|
+
from trendscout import TrendScout, TrendScraper, SentimentAnalyzer, SentimentResult
|
|
14
|
+
from trendscout import TrendVelocity, VelocityResult
|
|
15
|
+
assert all(cls is not None for cls in [TrendScout, SentimentAnalyzer, TrendVelocity])
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# ── SentimentAnalyzer ─────────────────────────────────────────────────────────
|
|
19
|
+
|
|
20
|
+
def test_sentiment_basic():
|
|
21
|
+
from trendscout import SentimentAnalyzer
|
|
22
|
+
analyzer = SentimentAnalyzer()
|
|
23
|
+
result = analyzer.analyze("This is a fantastic product!")
|
|
24
|
+
assert "polarity" in result
|
|
25
|
+
assert "label" in result
|
|
26
|
+
assert "intensity" in result
|
|
27
|
+
assert "market_signal" in result
|
|
28
|
+
assert isinstance(result["polarity"], float)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_sentiment_positive():
|
|
32
|
+
from trendscout import SentimentAnalyzer
|
|
33
|
+
analyzer = SentimentAnalyzer()
|
|
34
|
+
result = analyzer.analyze("Incredible growth, record profits, soaring revenue!")
|
|
35
|
+
assert result["label"] == "positive"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_sentiment_negative():
|
|
39
|
+
from trendscout import SentimentAnalyzer
|
|
40
|
+
analyzer = SentimentAnalyzer()
|
|
41
|
+
result = analyzer.analyze("Terrible crash, massive loss, declining performance.")
|
|
42
|
+
assert result["label"] == "negative"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_sentiment_rich_result():
|
|
46
|
+
from trendscout import SentimentAnalyzer, SentimentResult
|
|
47
|
+
analyzer = SentimentAnalyzer()
|
|
48
|
+
result = analyzer.analyze_rich("The market surged 30% today.")
|
|
49
|
+
assert isinstance(result, SentimentResult)
|
|
50
|
+
assert hasattr(result, "market_signal")
|
|
51
|
+
assert hasattr(result, "intensity")
|
|
52
|
+
assert hasattr(result, "confidence")
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_sentiment_domain_financial():
|
|
56
|
+
from trendscout import SentimentAnalyzer
|
|
57
|
+
analyzer = SentimentAnalyzer()
|
|
58
|
+
r_bullish = analyzer.analyze("Revenue surged 40% beating all analyst estimates.", domain="financial")
|
|
59
|
+
r_bearish = analyzer.analyze("Massive crash, terrible loss, slump continues.", domain="financial")
|
|
60
|
+
assert r_bullish["polarity"] > r_bearish["polarity"]
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def test_sentiment_dataframe():
|
|
64
|
+
from trendscout import SentimentAnalyzer
|
|
65
|
+
analyzer = SentimentAnalyzer()
|
|
66
|
+
df = pd.DataFrame({"text": ["Great!", "Terrible crash!", "Neutral news"]})
|
|
67
|
+
result = analyzer.analyze_dataframe(df, "text")
|
|
68
|
+
assert "polarity" in result.columns
|
|
69
|
+
assert "sentiment_label" in result.columns
|
|
70
|
+
assert "market_signal" in result.columns
|
|
71
|
+
assert len(result) == 3
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
# ── TrendScraper (mock fallback) ──────────────────────────────────────────────
|
|
75
|
+
|
|
76
|
+
def test_trend_scraper_mock():
|
|
77
|
+
from trendscout import TrendScraper
|
|
78
|
+
scraper = TrendScraper(use_mock=True)
|
|
79
|
+
df = scraper.get_trends("technology", limit=5)
|
|
80
|
+
assert isinstance(df, pd.DataFrame)
|
|
81
|
+
assert "title" in df.columns
|
|
82
|
+
assert len(df) > 0
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_trend_scraper_volatility():
|
|
86
|
+
from trendscout import TrendScraper
|
|
87
|
+
scraper = TrendScraper()
|
|
88
|
+
v = scraper.get_volatility("AI")
|
|
89
|
+
assert "keyword" in v
|
|
90
|
+
assert "volatility" in v
|
|
91
|
+
assert 0.0 <= v["volatility"] <= 1.0
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
# ── TrendVelocity ─────────────────────────────────────────────────────────────
|
|
95
|
+
|
|
96
|
+
def test_velocity_empty_stories():
|
|
97
|
+
from trendscout import TrendVelocity
|
|
98
|
+
tv = TrendVelocity()
|
|
99
|
+
result = tv.calculate("empty topic", [])
|
|
100
|
+
assert result.status == "unknown"
|
|
101
|
+
assert result.score == 0.0
|
|
102
|
+
assert result.article_count == 0
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def test_velocity_high_engagement():
|
|
106
|
+
from trendscout import TrendVelocity
|
|
107
|
+
tv = TrendVelocity()
|
|
108
|
+
stories = [{"score": 500, "num_comments": 100} for _ in range(25)]
|
|
109
|
+
result = tv.calculate("viral topic", stories)
|
|
110
|
+
assert result.score > 0.5
|
|
111
|
+
assert result.status in ("emerging", "peak")
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def test_velocity_low_engagement():
|
|
115
|
+
from trendscout import TrendVelocity
|
|
116
|
+
tv = TrendVelocity()
|
|
117
|
+
stories = [{"score": 5, "num_comments": 1} for _ in range(2)]
|
|
118
|
+
result = tv.calculate("niche topic", stories)
|
|
119
|
+
assert result.status in ("declining", "stable", "peak")
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
# ── TrendScout facade ─────────────────────────────────────────────────────────
|
|
123
|
+
|
|
124
|
+
def test_trendscout_analyze_sentiment():
|
|
125
|
+
from trendscout import TrendScout, SentimentResult
|
|
126
|
+
ts = TrendScout()
|
|
127
|
+
result = ts.analyze_sentiment("The market is booming with record highs!")
|
|
128
|
+
assert isinstance(result, SentimentResult)
|
|
129
|
+
assert result.label in ("positive", "negative", "neutral")
|
|
130
|
+
assert 0.0 <= result.confidence <= 1.0
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def test_trendscout_analyze_dataframe():
|
|
134
|
+
from trendscout import TrendScout
|
|
135
|
+
ts = TrendScout()
|
|
136
|
+
df = pd.DataFrame({"headline": ["Great news!", "Terrible losses", "Mixed results"]})
|
|
137
|
+
result = ts.analyze_dataframe(df, "headline")
|
|
138
|
+
assert "sentiment_label" in result.columns
|
|
139
|
+
assert len(result) == 3
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def test_trendscout_backward_compat_volatility():
|
|
143
|
+
from trendscout import TrendScout
|
|
144
|
+
ts = TrendScout()
|
|
145
|
+
result = ts.get_trend_volatility("python")
|
|
146
|
+
assert "keyword" in result
|
|
147
|
+
assert "volatility" in result
|
|
148
|
+
assert "status" in result
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def test_trendscout_emerging_trends_fallback():
|
|
152
|
+
from trendscout import TrendScout
|
|
153
|
+
ts = TrendScout()
|
|
154
|
+
df = ts.get_emerging_trends(domain="technology", limit=5)
|
|
155
|
+
assert isinstance(df, pd.DataFrame)
|
|
156
|
+
assert len(df) > 0
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
# ── RSS Source (unit test — no network needed) ────────────────────────────────
|
|
160
|
+
|
|
161
|
+
def test_rss_parse_rss2():
|
|
162
|
+
from trendscout.sources.rss import RSSFeedSource
|
|
163
|
+
rss = RSSFeedSource()
|
|
164
|
+
xml = """<?xml version="1.0"?>
|
|
165
|
+
<rss version="2.0"><channel>
|
|
166
|
+
<item><title>Test Article</title><link>https://example.com/1</link>
|
|
167
|
+
<description>A test item</description><pubDate>Sat, 24 May 2026 00:00:00 GMT</pubDate></item>
|
|
168
|
+
</channel></rss>"""
|
|
169
|
+
items = rss._parse(xml, "test-feed", 10)
|
|
170
|
+
assert len(items) == 1
|
|
171
|
+
assert items[0].title == "Test Article"
|
|
172
|
+
assert items[0].url == "https://example.com/1"
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def test_rss_parse_atom():
|
|
176
|
+
from trendscout.sources.rss import RSSFeedSource
|
|
177
|
+
rss = RSSFeedSource()
|
|
178
|
+
xml = """<?xml version="1.0"?>
|
|
179
|
+
<feed xmlns="http://www.w3.org/2005/Atom">
|
|
180
|
+
<entry>
|
|
181
|
+
<title>Atom Article</title>
|
|
182
|
+
<link href="https://example.com/atom/1"/>
|
|
183
|
+
<summary>An atom entry</summary>
|
|
184
|
+
<updated>2026-05-24T00:00:00Z</updated>
|
|
185
|
+
</entry>
|
|
186
|
+
</feed>"""
|
|
187
|
+
items = rss._parse(xml, "atom-feed", 10)
|
|
188
|
+
assert len(items) == 1
|
|
189
|
+
assert items[0].title == "Atom Article"
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
# ── HackerNews Source (instantiation only — no live calls in tests) ───────────
|
|
193
|
+
|
|
194
|
+
def test_hackernews_source_instantiation():
|
|
195
|
+
from trendscout.sources.hackernews import HackerNewsSource
|
|
196
|
+
hn = HackerNewsSource()
|
|
197
|
+
assert hn is not None
|
|
198
|
+
assert hn.timeout == 10
|