Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions components/parsera/actions/extract/extract.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import app from "../../parsera.app.mjs";

export default {
key: "parsera-extract",
name: "Extract",
description: "Extract data from a given URL. [See the documentation](https://docs.parsera.org/api/getting-started/)",
version: "0.0.1",
type: "action",
props: {
app,
url: {
type: "string",
label: "URL",
description: "The URL to extract information from.",
},
attributes: {
propDefinition: [
app,
"attributes",
],
},
proxyCountry: {
propDefinition: [
app,
"proxyCountry",
],
},
},
methods: {
extract(args = {}) {
return this.app.post({
path: "/extract",
...args,
});
},
},
async run({ $ }) {
const {
extract,
url,
attributes,
proxyCountry,
} = this;

const response = await extract({
$,
data: {
url,
attributes: Array.isArray(attributes) && attributes.map(JSON.parse),
proxy_country: proxyCountry,
},
});
$.export("$summary", "Successfully extracted data from url.");
return response;
},
};
50 changes: 50 additions & 0 deletions components/parsera/actions/parse/parse.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import app from "../../parsera.app.mjs";

export default {
key: "parsera-parse",
name: "Parse",
description: "Parse data using pre-defined attributes. [See the documentation](https://docs.parsera.org/api/getting-started/)",
version: "0.0.1",
type: "action",
props: {
app,
content: {
type: "string",
label: "Content",
description: "The content to parse. HTML or text content. Eg. `<h1>Hello World</h1>`.",
},
attributes: {
propDefinition: [
app,
"attributes",
],
},
},
methods: {
parse(args = {}) {
return this.app.post({
path: "/parse",
...args,
});
},
},
async run({ $ }) {
const {
parse,
content,
attributes,
} = this;

const response = await parse({
$,
data: {
content,
attributes: Array.isArray(attributes) && attributes.map(JSON.parse),
},
});

$.export("$summary", "Successfully parsed content.");

return response;
},
};
7 changes: 5 additions & 2 deletions components/parsera/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/parsera",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Parsera Components",
"main": "parsera.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "3.0.3"
}
}
}
62 changes: 57 additions & 5 deletions components/parsera/parsera.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,63 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "parsera",
propDefinitions: {},
propDefinitions: {
proxyCountry: {
type: "string",
label: "Proxy Country",
description: "Set a specific proxy country for the request.",
optional: true,
async options() {
const response = await this.listProxyCountries();
return Object.entries(response)
.map(([
value,
label,
]) => ({
label,
value,
}));
},
},
attributes: {
type: "string[]",
label: "Attributes",
description: "List of attributes to extract or parse from the content. Format each attribute as a JSON string. Eg. `{\"name\": \"Title\",\"description\": \"News title\"}`.",
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
getUrl(path) {
return `https://api.parsera.org/v1${path}`;
},
getHeaders(headers) {
return {
"Content-Type": "application/json",
...headers,
"X-API-KEY": this.$auth.api_key,
};
},
_makeRequest({
$ = this, path, headers, ...args
} = {}) {
return axios($, {
...args,
url: this.getUrl(path),
headers: this.getHeaders(headers),
});
},
post(args = {}) {
return this._makeRequest({
method: "POST",
...args,
});
},
listProxyCountries(args = {}) {
return this._makeRequest({
path: "/proxy-countries",
...args,
});
},
},
};
};
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading