Skip to content

Commit c72c2e0

Browse files
authored
Arxiv - new component (#18990)
* search-articles.mjs * pnpm-lock.yaml * pnpm-lock.yaml * update
1 parent 7239580 commit c72c2e0

File tree

4 files changed

+127
-25
lines changed

4 files changed

+127
-25
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import arxiv from "../../arxiv.app.mjs";
2+
import fs from "fs";
3+
4+
export default {
5+
key: "arxiv-search-articles",
6+
name: "Search Articles",
7+
description: "Search for articles on arXiv. [See the documentation](https://info.arxiv.org/help/api/user-manual.html#2-api-quickstart)",
8+
version: "0.0.1",
9+
type: "action",
10+
annotations: {
11+
destructiveHint: false,
12+
openWorldHint: true,
13+
readOnlyHint: true,
14+
},
15+
props: {
16+
arxiv,
17+
searchQuery: {
18+
type: "string",
19+
label: "Search Query",
20+
description: "The search query to use. Example: `all:electron`. [See the documentation](https://info.arxiv.org/help/api/user-manual.html#51-details-of-query-construction) for information on constructing a search query.",
21+
optional: true,
22+
},
23+
idList: {
24+
type: "string[]",
25+
label: "ID List",
26+
description: "A list of arXiv article IDs to search for. Example ID: `2505.08081v1`",
27+
optional: true,
28+
},
29+
start: {
30+
type: "integer",
31+
label: "Start",
32+
description: "The index of the first result to return. Defaults to 0.",
33+
optional: true,
34+
},
35+
maxResults: {
36+
type: "integer",
37+
label: "Max Results",
38+
description: "The maximum number of results to return. Defaults to 10.",
39+
optional: true,
40+
},
41+
filename: {
42+
type: "string",
43+
label: "Filename",
44+
description: "A filename to save the result as an xml file to the /tmp directory. Example: `arxiv-search-results.xml`",
45+
optional: true,
46+
},
47+
syncDir: {
48+
type: "dir",
49+
accessMode: "write",
50+
sync: true,
51+
},
52+
},
53+
async run({ $ }) {
54+
const response = await this.arxiv.search({
55+
$,
56+
params: {
57+
search_query: this.searchQuery,
58+
id_list: this.idList
59+
? this.idList.join(",")
60+
: undefined,
61+
start: this.start,
62+
max_results: this.maxResults,
63+
},
64+
});
65+
66+
if (!this.filename) {
67+
$.export("$summary", "Successfully searched for articles");
68+
return response;
69+
}
70+
71+
const filePath = `/tmp/${this.filename}`;
72+
fs.writeFileSync(filePath, response, "utf8");
73+
74+
$.export("$summary", `Successfully saved search results to ${filePath}`);
75+
return {
76+
filePath,
77+
fileContent: response,
78+
};
79+
},
80+
};

components/arxiv/arxiv.app.mjs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "arxiv",
46
propDefinitions: {},
57
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
8+
_baseUrl() {
9+
return "https://export.arxiv.org/api";
10+
},
11+
_makeRequest({
12+
$ = this, path, ...opts
13+
}) {
14+
return axios($, {
15+
url: `${this._baseUrl()}${path}`,
16+
...opts,
17+
});
18+
},
19+
search(opts = {}) {
20+
return this._makeRequest({
21+
path: "/query",
22+
...opts,
23+
});
924
},
1025
},
1126
};

components/arxiv/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/arxiv",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream arXiv Components",
55
"main": "arxiv.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.1"
1417
}
1518
}

pnpm-lock.yaml

Lines changed: 25 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)