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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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`;
const j = await fetch(
`https://api.semanticscholar.org/graph/v1/paper/search?query=${
encodeURIComponent(
semscholar_query,
)
}&limit=1&fields=${
encodeURIComponent(
fields,
)
}`,
).then((r) => r.json()).catch(function() {
console.log("Promise Rejected");
});
if (!(j.total > 0)) {
console.log("No results found for " + semscholar_query);
continue;
}
const paper = j.data[0];
// get bibtex
let all_external_ids = paper.externalIds;
// console.log(paper)
// console.log(all_external_ids)
let doi_to_add = null;
let bibtext_to_add = null;
if (paper.externalIds.DOI) {
doi_to_add = paper.externalIds.DOI;
}
else if (paper.externalIds.PubMed) {
doi_to_add = paper.externalIds.PubMed;
}
else if (paper.externalIds.PubMedCentral) {
doi_to_add = paper.externalIds.PubMedCentral;
}
else if (paper.externalIds.ArXiv) {
doi_to_add = "arxiv." + paper.externalIds.ArXiv;
}
if (doi_to_add) {
// const bib = await fetch('https://api.paperpile.com/api/public/convert', {
// method: 'POST',
// headers: {
// 'Accept': 'application/json, text/plain, */*',
// 'Content-Type': 'application/json'
// },
// body: JSON.stringify({fromIds: true, input: doi_to_add.replace("arxiv.",""), targetFormat: "Bibtex"})
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
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
51
52
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