Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/seanvelasco/bsky-trends
Trending Bluesky hashtags over a 24-hour period
https://github.com/seanvelasco/bsky-trends
atproto bsky deno mongodb
Last synced: about 1 month ago
JSON representation
Trending Bluesky hashtags over a 24-hour period
- Host: GitHub
- URL: https://github.com/seanvelasco/bsky-trends
- Owner: seanvelasco
- Created: 2024-05-11T18:48:55.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-10-29T13:24:33.000Z (2 months ago)
- Last Synced: 2024-10-29T16:04:09.846Z (2 months ago)
- Topics: atproto, bsky, deno, mongodb
- Language: TypeScript
- Homepage: https://trends.usky.app
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# bsky-trends
This API powers [usky.app/trends](https://usky.app/trends) to display most frequently used #hashtags in Bluesky in the last 48 hours.
## How it works
Hashtag keywords are inserted to MongoDB as time-series data. Documents in the collection have a set time to live (TTL). When TTL is reached, the documents are removed from the collection.
```javascript
await collection.insertMany([
{
hashtag: feature.tag,
path: op.path.toString(),
createdAt: new Date(message.createdAt)
}
])
```To retrieve the trending hashtags, a two-part MongoDB pipeline is used to count each instances of the hashtags and sort them by the highest count.
Coung
```javascript
{
// group documents by hashtag
// each unique hashtag is its own group
$group: {
_id: "$hashtag", // $group requires _id, set _id to the hashtag value
count: { $sum: 1 }, // count is calculated by adding 1 each occurence
}
}
``````javascript
// reshape the output so we have hashtag instead of _id
{
$project: {
_id: 0, // exclude _id
hashtag: "$_id", // include hashtag with _id as its value
count: 1, // include count
},
}
``````javascript
{
$sort: { count: -1 }, // sort by descending order, 1 is ascending and -1 is descending
},
{
$limit: limit, // number of results to return
}```
## Usage
Use this in your own web app or service!
```
https://trends.usky.app?limit=100
```