From f4e78610648dd9ff9cf5f5fbc293b3d84ba9a18e Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Sun, 26 May 2024 20:15:17 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/scratch.ts | 16 +-- src/services/perigon-client.ts | 232 +++++++++++++++++---------------- src/services/searxng-client.ts | 4 + 3 files changed, 131 insertions(+), 121 deletions(-) diff --git a/bin/scratch.ts b/bin/scratch.ts index 98da7cb..2000e61 100644 --- a/bin/scratch.ts +++ b/bin/scratch.ts @@ -4,8 +4,7 @@ import 'dotenv/config' import { gracefulExit } from 'exit-hook' import restoreCursor from 'restore-cursor' -import { SearxngClient } from '../src/services/searxng-client.js' - +// import { SearxngClient } from '../src/services/searxng-client.js' // import { ClearbitClient } from '../src/index.js' // import { ProxycurlClient } from '../src/services/proxycurl-client.js' // import { WikipediaClient } from '../src/services/wikipedia-client.js' @@ -25,7 +24,6 @@ async function main() { // const proxycurl = new ProxycurlClient() // const res = await proxycurl.getLinkedInPerson({ // linkedin_profile_url: 'https://linkedin.com/in/fisch2' - // // personal_email: 'fisch0920@gmail.com' // }) // console.log(JSON.stringify(res, null, 2)) @@ -35,12 +33,12 @@ async function main() { // }) // console.log(JSON.stringify(res, null, 2)) - const searxng = new SearxngClient() - const res = await searxng.search({ - query: '4 + 2 * 10' - // engines: ['google'] - }) - console.log(JSON.stringify(res, null, 2)) + // const searxng = new SearxngClient() + // const res = await searxng.search({ + // query: 'golden gate bridge', + // engines: ['reddit'] + // }) + // console.log(JSON.stringify(res, null, 2)) return gracefulExit(0) } diff --git a/src/services/perigon-client.ts b/src/services/perigon-client.ts index a3be8e0..60d19fa 100644 --- a/src/services/perigon-client.ts +++ b/src/services/perigon-client.ts @@ -101,63 +101,66 @@ export namespace perigon { export type ArticlesResponse = { status: number numResults: number - articles: { - url: string - authorsByline: string - articleId: string - clusterId: string - source: { - domain: string - } - imageUrl: string - country: string - language: string - pubDate: string - addDate: string - refreshDate: string - score: number - title: string - description: string - content: string - medium: string - links: string[] - labels: string[] - matchedAuthors: string[] - claim: string - verdict: string - keywords: { - name: string - weight: number - }[] - topics: { - name: string - }[] - categories: { - name: string - }[] - entities: { - data: string - type: string - mentions: number - }[] - sentiment: { - positive: number - negative: number - neutral: number - } - summary: string - translation: string - locations: string[] - reprint: boolean - reprintGroupId: string - places: null + articles: Article[] + } + + export type Article = { + url: string + authorsByline: string + articleId: string + clusterId: string + source: { + domain: string + } + imageUrl: string + country: string + language: string + pubDate: string + addDate: string + refreshDate: string + score: number + title: string + description: string + content: string + medium: string + links: string[] + labels: string[] + matchedAuthors: string[] + claim: string + verdict: string + keywords: { + name: string + weight: number }[] + topics: { + name: string + }[] + categories: { + name: string + }[] + entities: { + data: string + type: string + mentions: number + }[] + sentiment: { + positive: number + negative: number + neutral: number + } + summary: string + translation: string + locations: string[] + reprint: boolean + reprintGroupId: string + places: null } export type StoriesOptions = { clusterId?: string topic?: string category?: Categories + q?: string name?: string nameExists?: boolean from?: string @@ -180,73 +183,78 @@ export namespace perigon { export type StoriesResponse = { status: number numResults: number - results: Array<{ - createdAt: string - updatedAt: string - initializedAt: string + results: Story[] + } + + export type Story = { + createdAt: string + updatedAt: string + initializedAt: string + id: string + name: string + summary: string + summaryReferences: Array + keyPoints: Array<{ + point: string + references: Array + }> + sentiment: { + positive: number + negative: number + neutral: number + } + uniqueCount: number + reprintCount: number + totalCount: number + countries: Array<{ + name: string + count: number + }> + topCountries: Array + topics: Array<{ + name: string + count: number + }> + topTopics: Array<{ name: string }> + categories: Array<{ + name: string + count: number + }> + topCategories: Array<{ name: string }> + people: Array<{ wikidataId: string; name: string; count: number }> + topPeople: Array<{ wikidataId: string; name: string }> + companies: Array<{ id: string name: string - summary: string - summaryReferences: Array - keyPoints: Array<{ - point: string - references: Array - }> - sentiment: { - positive: number - negative: number - neutral: number - } - uniqueCount: number - reprintCount: number - totalCount: number - countries: Array<{ - name: string - count: number - }> - topCountries: Array - topics: Array<{ - name: string - count: number - }> - topTopics: Array<{ name: string }> - categories: Array<{ - name: string - count: number - }> - topCategories: Array<{ name: string }> - people: Array<{ wikidataId: string; name: string; count: number }> - topPeople: Array<{ wikidataId: string; name: string }> - companies: Array<{ - id: string - name: string - domains: Array - symbols: Array - count: number - }> - topCompanies: Array<{ - id: string - name: string - domains: Array - symbols: Array - }> - locations: Array<{ - state: string - city?: string - area?: string - county?: string - count: number - }> - topLocations: Array<{ - state: string - city?: string - area?: string - county?: string - }> + domains: Array + symbols: Array + count: number + }> + topCompanies: Array<{ + id: string + name: string + domains: Array + symbols: Array + }> + locations: Array<{ + state: string + city?: string + area?: string + county?: string + count: number + }> + topLocations: Array<{ + state: string + city?: string + area?: string + county?: string }> } } +/** + * @see https://www.goperigon.com + */ export class PerigonClient { readonly ky: KyInstance readonly apiKey: string @@ -264,7 +272,7 @@ export class PerigonClient { timeoutMs?: number ky?: KyInstance } = {}) { - assert(apiKey, 'Error perigon client missing required "apiKey"') + assert(apiKey, 'Error PerigonClient missing required "apiKey"') this.apiKey = apiKey diff --git a/src/services/searxng-client.ts b/src/services/searxng-client.ts index 4d19fce..97adc00 100644 --- a/src/services/searxng-client.ts +++ b/src/services/searxng-client.ts @@ -241,6 +241,10 @@ export namespace searxng { /** * @see https://docs.searxng.org + * + * NOTE: You'll need to run a local instance of Searxng to use this client. + * + * See [perplexica](https://github.com/ItzCrazyKns/Perplexica/blob/master/docker-compose.yaml) for an example. */ export class SearxngClient { readonly ky: KyInstance