-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharxiv_tool.py
More file actions
63 lines (52 loc) · 1.86 KB
/
Copy patharxiv_tool.py
File metadata and controls
63 lines (52 loc) · 1.86 KB
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
"""
arxiv_tool.py
-------------
Fetches recent papers from ArXiv API.
Completely free — no API key needed.
"""
import arxiv
from datetime import datetime, timedelta
from config import ARXIV_CATEGORIES, MAX_PAPERS_PER_CATEGORY
def fetch_recent_papers(days_back: int = 1) -> list[dict]:
"""
Fetch papers published in the last N days across all configured categories.
Returns list of dicts:
{
"title": str,
"authors": list,
"abstract": str,
"url": str,
"published": str,
"category": str,
}
"""
papers = []
seen_ids = set() # avoid duplicates across categories
client = arxiv.Client()
for category in ARXIV_CATEGORIES:
search = arxiv.Search(
query=f"cat:{category}",
max_results=MAX_PAPERS_PER_CATEGORY,
sort_by=arxiv.SortCriterion.SubmittedDate,
sort_order=arxiv.SortOrder.Descending,
)
try:
results = list(client.results(search))
for paper in results:
paper_id = paper.entry_id
if paper_id in seen_ids:
continue
seen_ids.add(paper_id)
papers.append({
"title": paper.title.strip(),
"authors": [a.name for a in paper.authors[:3]], # top 3 authors
"abstract": paper.summary.strip()[:1000], # first 1000 chars
"url": paper.entry_id,
"published": paper.published.strftime("%Y-%m-%d"),
"category": category,
})
except Exception as e:
print(f"[ArXiv] Error fetching {category}: {e}")
continue
print(f"[ArXiv] Fetched {len(papers)} papers across {len(ARXIV_CATEGORIES)} categories")
return papers