Back to APIs list

Arxiv API examples & templates

Use these vals as a playground to view and fork Arxiv API examples and templates on Val Town. Run any example below or find templates that can be used as a pre-built solution.
Runs every 1461 days
Fork
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import process from "node:process";
import { Client } from "npm:@notionhq/client";
import { fetch } from "npm:cross-fetch";
export default async function(interval: Interval) {
const NOTION_API_KEY = process.env.NOTION_API_KEY;
const PAPERPILE_DB_ID = "DB_ID_GOES_HERE";
if (!NOTION_API_KEY || !PAPERPILE_DB_ID) {
throw new Error("Please fill in your API key and database ID");
}
let dont_update = [];
const notion = new Client({ auth: NOTION_API_KEY });
const databaseId = PAPERPILE_DB_ID;
const queryResponse = await notion.databases.query({
database_id: databaseId,
page_size: 100,
filter: {
or: [
{
property: "Name",
rich_text: {
contains: ";",
},
},
],
},
});
const relevant_results = queryResponse.results.filter(
(i) => !dont_update.includes(i.id),
);
console.log(
`Checked database, found ${relevant_results.length} items to update.`,
);
const all_updated = [];
for (var i of relevant_results) {
let semscholar_query = i.properties.Name.title[0]
.plain_text.replace(
/[^\w\s]/gi,
" ",
); /*+ " " + i.properties["Author(s)"].multi_select.map(x => x.name).join(", ")*/
console.log(semscholar_query);
let fields = `url,title,abstract,authors,year,externalIds`;
Fork
1
2
// set at Thu Nov 30 2023 14:22:53 GMT+0000 (Coordinated Universal Time)
export let topHNThreadByHour = ["Top thread on Hackernews for 3:00 is: Vespa.ai is spinning out of Yahoo as a separate company","Top thread on Hackernews for 4:00 is: President Speaking: Spoofing Alerts in 4G LTE Networks (2019) [pdf]","Top thread on Hacke
Fork
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { fetch } from "https://esm.town/v/std/fetch";
export const searchArXiV = async ({ query = "", start = 0, max_results = 10 }) => {
const { parseStringPromise } = await import("npm:xml2js");
const url = new URL("https://export.arxiv.org/api/query");
url.searchParams.set("search_query", query);
url.searchParams.set("start", start);
url.searchParams.set("max_results", max_results);
const response = await fetch(url.toString());
const text = await response.text();
if (!response.ok) {
throw new Error(text);
}
const feed = await parseStringPromise(text);
return feed;
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { fetch } from "https://esm.town/v/std/fetch";
import { Buffer } from "node:buffer";
export const arxivSourceZip = async (id) => {
const { t } = await import("npm:tar");
const { default: Zip } = await import("npm:adm-zip");
const { iterateReader } = await import(
"https://deno.land/std@0.122.0/streams/mod.ts"
);
const url = id.replace("/abs/", "/e-print/");
const response = await fetch(url);
if (!response.ok) {
throw new Error(await response.text());
}
if (response.headers.get("content-type") !== "application/x-eprint-tar") {
throw new Error(JSON.stringify(Object.fromEntries(response.headers)));
}
return new Promise(async (resolve, reject) => {
const zip = new Zip();
const extractStream = t({
filter: (path, entry) => entry.type === "File",
}).on("entry", async (entry) => {
const buffers = [];
for await (const data of entry) {
buffers.push(data);
}
zip.add(entry.path, Buffer.concat(buffers));
}).on("error", (error) => {
reject(error);
}).on("close", () => {
resolve(
new Response(zip.toBuffer(), {
headers: {
"content-type": "application/zip",
},
}),
);
});
for await (const chunk of iterateReader(response.body.getReader())) {
await new Promise((resolve, reject) => {
extractStream.write(chunk, (error) => {
if (error) {
reject(error);
}
else {
resolve(null);
}
});
});
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { fetch } from "https://esm.town/v/std/fetch";
export const searchArXiV = async ({ query = "", start = 0, max_results = 10 }) => {
const { parseStringPromise } = await import("npm:xml2js");
const url = new URL("https://export.arxiv.org/api/query");
url.searchParams.set("search_query", query);
url.searchParams.set("start", start);
url.searchParams.set("max_results", max_results);
const response = await fetch(url.toString());
const text = await response.text();
if (!response.ok) {
throw new Error(text);
}
const feed = await parseStringPromise(text);
return feed;
};
1
Next