Skip to content

Commit

Permalink
[Actions & Sources] World news api (PipedreamHQ#5938)
Browse files Browse the repository at this point in the history
* Remove TS setup

* Search News

* Extract News

* Get Geo Coordinates

* Source

* Pipelines

* Bad keys

* CR

* CR

* Fix manual dedupe

* Update action to use undefined if string is null

* CR

* Fix publish date and add new param to source

* fix pagination loop

* Fetch 20 news in the first execution

* Update Max Value

* Removing source because api is not ordering correctly

* Remake source
  • Loading branch information
vellames authored Apr 17, 2023
1 parent 18436e6 commit a9d73ad
Show file tree
Hide file tree
Showing 13 changed files with 1,782 additions and 21 deletions.
3 changes: 0 additions & 3 deletions components/world_news_api/.gitignore

This file was deleted.

31 changes: 31 additions & 0 deletions components/world_news_api/actions/extract-news/extract-news.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import app from "../../world_news_api.app.mjs";

export default {
name: "Extract News",
description: "Extract a news article from a website to a well structure JSON object. [See the docs here](https://worldnewsapi.com/docs/#Extract-News). **Calling this endpoint requires 1 point, plus 2 points if analyze is true.**",
key: "world_news_api-extract-news",
version: "0.0.1",
type: "action",
props: {
app,
url: {
type: "string",
label: "URL",
description: "The URL of the news article to extract.",
},
analyze: {
type: "boolean",
label: "Analyze",
description: "Whether to analyze the news.",
},
},
async run({ $ }) {
const params = {
url: this.url,
analyze: this.analyze,
};
const res = await this.app.extractNews(params, $);
$.export("$summary", res.title);
return res;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import app from "../../world_news_api.app.mjs";

export default {
name: "Get Geo Coordinates",
description: "Retrieve the latitude and longitude of a location name. [See the docs here](https://worldnewsapi.com/docs/#Get-Geo-Coordinates). **Calling this endpoint requires 1 point.**",
key: "world_news_api-get-geo-coordinates",
version: "0.0.1",
type: "action",
props: {
app,
location: {
type: "string",
label: "Location",
description: "The address or name of the location.",
},
},
async run({ $ }) {
const params = {
location: this.location,
};
const res = await this.app.getGeoCoordinates(params, $);
$.export("$summary", `Geo coordinates for ${this.location} successfully retrieved`);
return res;
},
};
125 changes: 125 additions & 0 deletions components/world_news_api/actions/search-news/search-news.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import app from "../../world_news_api.app.mjs";
import { getCommaSeparatedListFromArray } from "../../common/helpers.mjs";

export default {
name: "Search News",
description: "Search and filter news. [See the docs here](https://worldnewsapi.com/docs/#Search-News). **Calling this endpoint requires 1 point**",
key: "world_news_api-search-news",
version: "0.0.1",
type: "action",
props: {
app,
text: {
propDefinition: [
app,
"text",
],
},
sourceCountries: {
propDefinition: [
app,
"sourceCountries",
],
},
language: {
propDefinition: [
app,
"language",
],
},
minSentiment: {
propDefinition: [
app,
"minSentiment",
],
},
maxSentiment: {
propDefinition: [
app,
"maxSentiment",
],
},
earliestPublishedDate: {
propDefinition: [
app,
"earliestPublishedDate",
],
},
latestPublishedDate: {
propDefinition: [
app,
"latestPublishedDate",
],
},
newsSources: {
propDefinition: [
app,
"newsSources",
],
},
authors: {
propDefinition: [
app,
"authors",
],
},
entities: {
propDefinition: [
app,
"entities",
],
},
locationFilter: {
propDefinition: [
app,
"locationFilter",
],
},
sort: {
propDefinition: [
app,
"sort",
],
},
sortDirection: {
propDefinition: [
app,
"sortDirection",
],
},
offset: {
propDefinition: [
app,
"offset",
],
},
number: {
propDefinition: [
app,
"number",
],
},
},
async run({ $ }) {
const params = {
"text": this.text || undefined,
"source-countries": getCommaSeparatedListFromArray(this.sourceCountries),
"language": this.language || undefined,
"min-sentiment": this.minSentiment || undefined,
"max-sentiment": this.maxSentiment || undefined,
"earliest-publish-date": this.earliestPublishedDate || undefined,
"latest-publish-date": this.latestPublishedDate || undefined,
"news-sources": getCommaSeparatedListFromArray(this.newsSources),
"authors": getCommaSeparatedListFromArray(this.authors),
"entities": getCommaSeparatedListFromArray(this.entities),
"location-filter": this.locationFilter || undefined,
"sort": this.sort || undefined,
"sort-direction": this.sortDirection || undefined,
"offset": this.offset || undefined,
"number": this.number || undefined,
};
const res = await this.app.searchNews(params, $);
$.export("$summary", `Found ${res.available} news`);
return res;
},
};
13 changes: 0 additions & 13 deletions components/world_news_api/app/world_news_api.app.ts

This file was deleted.

Loading

0 comments on commit a9d73ad

Please sign in to comment.