-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathgenerate_paper_html.py
More file actions
34 lines (30 loc) · 1.22 KB
/
generate_paper_html.py
File metadata and controls
34 lines (30 loc) · 1.22 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
"""
Download papers, and correctly format them as a table for our website
"""
from scholarly import scholarly
from tqdm import tqdm
import html
# Step 1: Search for the author by ID
author = scholarly.search_author_id('LAv0HTEAAAAJ')
author = scholarly.fill(author, sections=['publications'])
# Step 2: Sort publications by year (descending)
publications = sorted(author['publications'], key=lambda p: p.get('bib', {}).get('pub_year', '0'), reverse=True)
# Step 3: Write to HTML file
with open('papers_new.html', 'w', encoding='utf-8') as out_f:
for pub in tqdm(publications[:20], desc="Processing papers"): # Limit to most recent 20
pub = scholarly.fill(pub)
bib = pub.get('bib', {})
title = html.escape(bib.get('title', ''))
authors = html.escape(bib.get('author', ''))
authors = authors.replace(' and ', ', ')
year = bib.get('pub_year', '')
citations = pub.get('num_citations', 0)
paper_id = pub.get('pub_url', '') # might be None
link = pub.get('pub_url', '#')
template = f"""<li>
<h4 class="menu-item-name"><a href="{link}">{title}</a></h4>
<span class="menu-item-price">({authors}, {year})</span>
<br>
</li>
"""
out_f.write(template)