/
index.qmd
67 lines (57 loc) · 2.15 KB
/
index.qmd
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
---
title: "Rogue Scholar Digest February 7, 2024"
description: |
This is a summary of the Rogue Scholar blog posts published January 31 - February 6, 2024.
date: 2024-02-07
categories: ["digest"]
image: "/images/Preprint-Review-Advantages-Infographic-1024x538.png"
---
```{python}
import requests
import locale
import re
from typing import Optional
import datetime
from IPython.display import Markdown
locale.setlocale(locale.LC_ALL, "en_US")
baseUrl = "https://api.rogue-scholar.org/"
published_since = "2024-01-31"
published_until = "2024-02-06"
feature_image = 0
include_fields = "title,authors,published_at,summary,blog_name,blog_slug,doi,url,image"
url = (
baseUrl
+ f"posts?&published_since={published_since}&published_until={published_until}&language=en&sort=published_at&order=asc&per_page=50&include_fields={include_fields}"
)
response = requests.get(url)
result = response.json()
def get_post(post):
return post["document"]
def format_post(post):
doi = post.get("doi", None)
url = f"[{doi}]({doi})\n<br />" if doi else ""
title = f"[{post['title']}]({doi})" if doi else f"[{post['title']}]({post['url']})"
published_at = datetime.datetime.utcfromtimestamp(post["published_at"]).strftime(
"%B %-d, %Y"
)
blog = f"[{post['blog_name']}](https://rogue-scholar.org/blogs/{post['blog_slug']})"
author = ", ".join([f"{x['name']}" for x in post.get("authors", None) or []])
summary = post["summary"]
return f"### {title}\n{url}Published {published_at} in {blog}<br />{author}<br />{summary}\n"
posts = [get_post(x) for i, x in enumerate(result["hits"])]
posts_as_string = "\n\n".join([format_post(x) for x in posts])
def doi_from_url(url: str) -> Optional[str]:
"""Return a DOI from a URL"""
match = re.search(
r"\A(?:(http|https)://(dx\.)?(doi\.org|handle\.stage\.datacite\.org|handle\.test\.datacite\.org)/)?(doi:)?(10\.\d{4,5}/.+)\Z",
url,
)
if match is None:
return None
return match.group(5).lower()
images = [x["image"] for x in posts if x.get("image", None) is not None]
image = images[feature_image]
markdown = f"![]({image})\n\n"
markdown += posts_as_string
Markdown(markdown)
```