Runs every 1461 days
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"})
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
January 4, 2024