City Trends Pulse is a small Python script that answers "what is trending on Twitter where, right now". For a list of places it pulls the current X trends, fetches the top posts for the leading trends, and writes a snapshot of which trends are shared across places and which are local.
The problem
Trend lists are easy to see one place at a time, but comparing several cities or countries is manual work. A trend name alone also says little: you need the top posts to know what it is about and whether those posts are fresh and on topic.
What the app does
- Takes a list of places by WOEID (worldwide, countries, cities).
- Pulls up to 30 current trends per place.
- Fetches top posts from the last day for the leading trends and keeps the 3 most engaged.
- Pulls replies for the top post of each place.
- Shows shared vs local trends, relevance and freshness checks.
- Writes a Markdown snapshot, CSVs and a heatmap chart.
How it works
- Trends.
GET /twitter/trendsper place, through thedesearch-pySDK. - Top posts.
GET /twitterwithsort=Topand a start date of yesterday for each trend. - Replies.
GET /twitter/replies/postfor the top post per place. - Compare. Overlap between places, relevance of each post to its trend, post age and language mix.
- Write the snapshot, CSVs, chart and a cost log from the
X-Desearch-Cost-Usdheader.
The code
import asyncio, os
from desearch_py import Desearch
async def main():
async with Desearch(api_key=os.environ["DESEARCH_API_KEY"]) as d:
trends = await d.x_trends(woeid=2459115, count=30, include_metadata=True) # New York
print(trends)
asyncio.run(main())
The folder has one script, trends.py, a sample report in sample-output.md and the chart from that run.
Example output
From a run on 2026-10-04 across worldwide, the US, the UK, New York, London and Istanbul:
| Check | Result |
|---|---|
| Trends in 3 or more places | 9 |
| Trends only in Istanbul | 29 of 29 |
| Trends only in the UK | 0 of 30 (same list as London) |
| Kept posts that mention their trend | 98% |
| Median age of kept posts | 4.2 hours |
Run it yourself
git clone https://github.com/Desearch-ai/desearch-py-examples && cd desearch-py-examples/city-trends-pulse
pip install -r requirements.txt
export DESEARCH_API_KEY=... # from console.desearch.ai
python trends.py
Useful flags: --top (trends per place to search posts for, default 4), --posts (posts per trend, default 20), --no-replies, --from-raw FILE (re-run the analysis with no API calls). Edit LOCATIONS in trends.py to change places.
What it costs
One run with the defaults on 2026-10-04 made 32 calls, took about 100 seconds and cost $0.0975, summed from the X-Desearch-Cost-Usd headers. See pricing.
Ideas to extend it
- Run it hourly and keep a history of when a trend reaches each city.
- Alert when a trend in your niche appears in a city you care about.
- Add more cities for a regional newsroom view.