Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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
```