diff --git a/scripts/publishFeedGen.ts b/scripts/publishFeedGen.ts index 95df0b9f..cfc0fe2a 100644 --- a/scripts/publishFeedGen.ts +++ b/scripts/publishFeedGen.ts @@ -1,102 +1,60 @@ -import dotenv from 'dotenv' -import inquirer from 'inquirer' -import { AtpAgent, BlobRef } from '@atproto/api' -import fs from 'fs/promises' -import { ids } from '../src/lexicon/lexicons' - -const run = async () => { - dotenv.config() - - if (!process.env.FEEDGEN_SERVICE_DID && !process.env.FEEDGEN_HOSTNAME) { - throw new Error('Please provide a hostname in the .env file') - } +import { subscribeToFirehose } from './firehose'; + +export async function indexPosts() { + const subscription = await subscribeToFirehose(); + subscription.on('post', (post) => { + const text = post.text.toLowerCase(); + if ( + text.includes('california native plants') || + text.includes('ceanothus') || + text.includes('manzanita') || + text.includes('#californianatives') || + text.includes('#nativeplants') + ) { + saveToDatabase(post); // Save posts matching criteria + } + }); +} - const answers = await inquirer - .prompt([ - { - type: 'input', - name: 'handle', - message: 'Enter your Bluesky handle:', - required: true, - }, - { - type: 'password', - name: 'password', - message: 'Enter your Bluesky password (preferably an App Password):', - }, - { - type: 'input', - name: 'service', - message: 'Optionally, enter a custom PDS service to sign in with:', - default: 'https://bsky.social', - required: false, - }, - { - type: 'input', - name: 'recordName', - message: 'Enter a short name or the record. This will be shown in the feed\'s URL:', - required: true, - }, - { - type: 'input', - name: 'displayName', - message: 'Enter a display name for your feed:', - required: true, - }, - { - type: 'input', - name: 'description', - message: 'Optionally, enter a brief description of your feed:', - required: false, - }, - { - type: 'input', - name: 'avatar', - message: 'Optionally, enter a local path to an avatar that will be used for the feed:', - required: false, - }, - ]) +import { SkeletonFeedPost } from '../types'; +import { getIndexedPosts } from '../database'; // Replace with your actual database utility + +export async function californiaNativePlantsFeed(): Promise { + const posts = await getIndexedPosts(); // Fetch posts from the database + const filteredPosts = posts.filter(post => { + const text = post.text.toLowerCase(); + return ( + text.includes('california native plants') || + text.includes('ceanothus') || + text.includes('manzanita') || + text.includes('#californianatives') || + text.includes('#nativeplants') + ); + }); + + return filteredPosts.map(post => ({ post: post.uri })); +} - const { handle, password, recordName, displayName, description, avatar, service } = answers +import { californiaNativePlantsFeed } from './algos/californiaNativePlants'; - const feedGenDid = - process.env.FEEDGEN_SERVICE_DID ?? `did:web:${process.env.FEEDGEN_HOSTNAME}` +feeds['at://did:your-did/app.bsky.feed.generator/California-native-plants'] = CaliforniaNativePlantsFeed; - // only update this if in a test environment - const agent = new AtpAgent({ service: service ? service : 'https://bsky.social' }) - await agent.login({ identifier: handle, password}) +const feedMetadata = { + name: 'California Native Plants', + avatar: 'https://example.com/path-to-avatar.png', // Optional avatar URL + description: 'A feed featuring posts about California native plants.', + feedUri: 'at://did:your-did/app.bsky.feed.generator/california-native-plants', + serviceDid: 'did:web:your-domain.com' +}; - let avatarRef: BlobRef | undefined - if (avatar) { - let encoding: string - if (avatar.endsWith('png')) { - encoding = 'image/png' - } else if (avatar.endsWith('jpg') || avatar.endsWith('jpeg')) { - encoding = 'image/jpeg' - } else { - throw new Error('expected png or jpeg') - } - const img = await fs.readFile(avatar) - const blobRes = await agent.api.com.atproto.repo.uploadBlob(img, { - encoding, - }) - avatarRef = blobRes.data.blob - } +const feedMetadata = { + name: 'California Native Plants', + avatar: 'https://example.com/path-to-avatar.png', // Optional avatar URL + description: 'A feed featuring posts about California native plants.', + feedUri: 'at://did:your-did/app.bsky.feed.generator/california-native-plants', + serviceDid: 'did:web:your-domain.com' +}; - await agent.api.com.atproto.repo.putRecord({ - repo: agent.session?.did ?? '', - collection: ids.AppBskyFeedGenerator, - rkey: recordName, - record: { - did: feedGenDid, - displayName: displayName, - description: description, - avatar: avatarRef, - createdAt: new Date().toISOString(), - }, - }) - console.log('All done 🎉') -} run()