Skip to content

Commit ae7d178

Browse files
authored
Create update_citations.py
1 parent 5e35b60 commit ae7d178

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

scripts/update_citations.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import json
4+
import requests
5+
from bs4 import BeautifulSoup
6+
7+
# === CONFIG ===
8+
SCHOLAR_USER_ID = "8-IhrB0AAAAJ" # your Google Scholar user ID
9+
OUT_PATH = "assets/json/citations.json"
10+
11+
def fetch_total_citations():
12+
url = f"https://scholar.google.com/citations?user={SCHOLAR_USER_ID}&hl=en"
13+
headers = {
14+
"User-Agent": (
15+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
16+
"AppleWebKit/537.36 (KHTML, like Gecko) "
17+
"Chrome/124.0 Safari/537.36"
18+
)
19+
}
20+
r = requests.get(url, headers=headers, timeout=30)
21+
r.raise_for_status()
22+
23+
soup = BeautifulSoup(r.text, "html.parser")
24+
25+
# On Scholar, the total citations is in the first cell of this table
26+
table = soup.find("table", id="gsc_rsb_st")
27+
if not table:
28+
raise RuntimeError("Could not find citation stats table on Google Scholar page.")
29+
30+
cells = table.find_all("td", class_="gsc_rsb_std")
31+
if not cells:
32+
raise RuntimeError("Could not find citation value cell on Google Scholar page.")
33+
34+
total_citations = cells[0].get_text(strip=True)
35+
return total_citations
36+
37+
def main():
38+
citations = fetch_total_citations()
39+
print(f"Total citations: {citations}")
40+
41+
data = {
42+
"schemaVersion": 1,
43+
"label": "citations",
44+
"message": citations,
45+
"color": "9cf"
46+
}
47+
48+
os.makedirs(os.path.dirname(OUT_PATH), exist_ok=True)
49+
with open(OUT_PATH, "w", encoding="utf-8") as f:
50+
json.dump(data, f, ensure_ascii=False)
51+
52+
print(f"Wrote {OUT_PATH}")
53+
54+
if __name__ == "__main__":
55+
main()

0 commit comments

Comments
 (0)