Skip to content

Instantly share code, notes, and snippets.

@third774
Created January 24, 2024 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save third774/cc637739fb0ee73ba8c5ea115ce07cf3 to your computer and use it in GitHub Desktop.
Save third774/cc637739fb0ee73ba8c5ea115ce07cf3 to your computer and use it in GitHub Desktop.
// Name: Feedbin Unread
// Author: Kevin Kipp
// Email: kevin.kipp@gmail.com
// Twitter: https://twitter.com/kevin_kipp
// Github: https://github.com/third774
import '@johnlindquist/kit';
const feedbinUsername = await env('FEEDBIN_USERNAME');
const feedbinPassword = await env('FEEDBIN_PASSWORD', () =>
arg({
placeholder: 'Feedbin Password',
secret: true,
}),
);
const headers = {
Authorization: `Basic ${btoa(`${feedbinUsername}:${feedbinPassword}`)}`,
};
type Entries = EntriesItem[];
interface EntriesItem {
author: null;
content: string;
created_at: string;
extracted_content_url: string;
feed_id: number;
id: number;
published: string;
summary: string;
title: string;
url: string;
}
const { data } = await get<Entries>(
`https://api.feedbin.com/v2/entries.json?read=false`,
{ headers },
);
const selection = await arg<EntriesItem>(
{
name: data.length > 0 ? 'Article Title' : 'No unread articles',
actions: [
{
name: 'Open',
onAction: async (_, state) => {
open(state.focused.value.url);
finishScript();
},
shortcut: 'o',
},
{
name: 'Mark as read',
onAction: async (_, state) => {
await post(
`https://api.feedbin.com/v2/unread_entries/delete.json`,
{ unread_entries: [state.focused.value.id] },
{ headers },
);
},
shortcut: 'm',
},
],
},
data.map((item: any) => ({
name: item.title,
description: item.url,
value: item,
})),
);
await open(selection.url);
await post(
`https://api.feedbin.com/v2/unread_entries/delete.json`,
{ unread_entries: [selection.id] },
{ headers },
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment