Skip to content

Commit

Permalink
Update readme, remove honcho
Browse files Browse the repository at this point in the history
  • Loading branch information
richardr1126 committed Dec 14, 2024
1 parent 921a130 commit 8a865c6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 82 deletions.
2 changes: 0 additions & 2 deletions Procfile

This file was deleted.

97 changes: 30 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Cosmere ATProto Feed Generator Flask Server
# Cosmere ATProto Feed Generator PostgreSQL Server

![Docker](https://img.shields.io/docker/image-size/richardr1126/cosmere-feed-bsky/latest)
![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)
Expand All @@ -14,11 +14,11 @@
## Features

- The generator offers custom filtering using SQLite and regular expressions to identify Cosmere-related content.
- The generator offers custom filtering using PostgreSQL and regular expressions to identify Cosmere-related content.
- It integrates trending posts by calculating interaction scores and maintains the database by cleaning outdated entries with `apscheduler`.
- Deployment is streamlined with `gunicorn` and managed using `honcho` (see Procfile) to run `web` seperatly from `firehose` data stream.
- Will run on **0.5 CPU**, **0.5 GB RAM**.
> **Note:** Posts are only kept for 3 days, and trending posts are calculated based on interactions within the last 24 hours.
- Deployment is streamlined with Docker Compose to run the `web`, `firehose`, and `postgres` services.
- Uses Docker compose to run the `web`, `firehose`, and `postgres` services.
> **Note:** Posts are only kept for 30 days, and trending posts are calculated based on interactions within the last 24 hours.
## Filters

Expand All @@ -32,89 +32,53 @@ The feed generator uses the following filters to curate content:

- **Handles to Include:** `stormlightmemes.bsky.social`, `brotherwisegames.bsky.social`

## Features

The generator offers custom filtering using SQLite and regular expressions to identify Cosmere-related content. It integrates trending posts by calculating interaction scores and maintains the database by cleaning outdated entries with `apscheduler`. Deployment is streamlined with `gunicorn` and managed using `honcho`.

## Making your own Feed

1. **Update files:**
- Update `publish_feed.py` with your feed details. **(REQUIRED)**
- Modify filters in `firehose/data_filter.py`. **(OPTIONAL)**
- Change database names/routes in `firehose/database.py` and `web/database_ro.py`. **(REQUIRED (unless using Docker))**
> **Note:** Currently `/var/data/` is used for database storage in a Docker volume. Change this to a different path if needed.
- Update environment variables in `.env`. **(REQUIRED)**

2. **Publish Your Feed:** Follow the [Publishing Your Feed](#publishing-your-feed) instructions below.

## Easiest installation (Docker)

Configure the environment variables by copying and editing the example file:

```shell
cp example.env .env
```

Open `.env` in your preferred text editor and fill in the necessary variables.
> **Note:** To obtain `CHRONO_TRENDING_URI`, publish the feed first using `publish_feed.py`.
Using docker-compose:
```shell
docker compose up --build --remove-orphans
```

Build and run Docker image:
```shell
docker build --rm -t myfeed .
docker run --rm -it --env-file .env -p 8000:8000 -v feeddata:/var/data/ myfeed
```


### Manual Installation

Ensure you have **Python 3.7+** and **Conda** installed. [Download Miniconda](https://docs.conda.io/en/latest/miniconda.html) if you haven't already.

### Prerequisites
## Publishing Your Feed

Clone the repository and navigate to its directory:
Edit publish_feed.py with your feed details and run:

```shell
git clone https://github.com/yourusername/cosmere-feed-generator.git
cd cosmere-feed-generator
python publish_feed.py
```

Create and activate a Conda environment:
After successful publication, your feed will appear in the Bluesky app. Obtain the CHRONOLOGICAL_TRENDING_URI for the .env file from the output.

```shell
conda create --name cosmere-feed
conda activate cosmere-feed
```

Install the required dependencies:
## Installation with Docker Compose

1. Configure environment variables:
```shell
pip install -r requirements.txt
cp example.env .env
```

## Publishing Your Feed

Edit the `publish_feed.py` script with your specific information such as `HANDLE`, `PASSWORD`, `HOSTNAME`, `RECORD_NAME`, `DISPLAY_NAME`, `DESCRIPTION`, and `AVATAR_PATH`. Run the script to publish your feed:

```shell
python publish_feed.py
2. Edit .env with your settings:
```env
HOSTNAME=feed.yourdomain.com
HANDLE=your-handle.bsky.social
PASSWORD=your-password
CHRONOLOGICAL_TRENDING_URI=at://did:plc:abcde...
POSTGRES_USER=postgres
POSTGRES_PASSWORD=your-db-password
POSTGRES_DB=feed
```
> Note: Obtain CHRONOLOGICAL_TRENDING_URI by running publish_feed.py first.
To update your feed's display data, modify the relevant variables and rerun the script. After successful publication, access your feed via the Bluesky app and share the provided link as needed.

## Running the Server

The server operates two main processes: the web server and the firehose data stream. Use `honcho` to manage these processes as defined in the `Procfile`:

Manually run the server:
3. Start the services:
```shell
honcho start
docker compose up --build --remove-orphans
```

This command will initiate both the `gunicorn` web server and the `start_stream.py` firehose process.
This will start:
- PostgreSQL database with attached volume for database persistence
- Firehose data stream python process
- Feed generator Web server with Gunicorn (4 workers)

## Endpoints

Expand All @@ -126,13 +90,12 @@ The server provides the following endpoints:

## License

This project is licensed under the [MIT License](LICENSE).
This project is licensed under the MIT License.

## Acknowledgements

Special thanks to [@MarshalX](https://github.com/MarshalX) for the foundational work on the AT Protocol SDK for Python, [Bluesky Social](https://atproto.com/) for the AT Protocol, and Brandon Sanderson for creating the inspiring Cosmere universe.

## Banned Content
- **Handles to Exclude:** `flintds.bsky.social`

- **Exclude Tokens:** `trump`, `sylvana`, `sylvanna`, `alleria`, `uriele`, `mormon`
20 changes: 7 additions & 13 deletions example.env
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
# Set this to the hostname that you intend to run the service at
# The hostname of the server where feed server will be hosted
HOSTNAME="feed.yourdomain.com"

# You can obtain it by publishing of feed (run publish_feed.py)
CHRONOLOGICAL_TRENDING_URI="at://did:plc:abcde..."

# Only use this if you want a service did different from did:web
# SERVICE_DID="did:plc:abcde..."

# YOUR bluesky password, or preferably an App Password (found in your client settings)
HANDLE="your-handle"
PASSWORD="your-password"
HOSTNAME=feed.yourdomain.com
HANDLE=your-handle.bsky.social
PASSWORD=your-password
CHRONOLOGICAL_TRENDING_URI=at://did:plc:abcde...
POSTGRES_USER=postgres
POSTGRES_PASSWORD=your-db-password
POSTGRES_DB=feed

0 comments on commit 8a865c6

Please sign in to comment.