Skip to content

Commit 63d3120

Browse files
committed
🚧 WIP
1 parent 5405824 commit 63d3120

File tree

3 files changed

+333
-0
lines changed

3 files changed

+333
-0
lines changed

nonebot_plugin_paper/__init__.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from nonebot import get_driver, require
2+
3+
require("nonebot_plugin_alconna")
4+
require("nonebot_plugin_htmlrender")
5+
require("nonebot_plugin_localstore")
6+
require("nonebot_plugin_uninfo")
7+
require("nonebot_plugin_apscheduler")
8+
from nonebot.plugin import PluginMetadata, inherit_supported_adapters
9+
10+
from .command import paper_cmd # noqa
11+
from .config import Config
12+
from .utils import connection_verification
13+
14+
__plugin_meta__ = PluginMetadata(
15+
name="nonebot_plugin_paper",
16+
description="Nonebot plugin for arXiv.",
17+
usage="""\
18+
""",
19+
type="application",
20+
supported_adapters=inherit_supported_adapters("nonebot_plugin_alconna"),
21+
config=Config,
22+
)
23+
24+
driver = get_driver()
25+
26+
27+
@driver.on_startup
28+
async def init():
29+
await connection_verification()

nonebot_plugin_paper/command.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from pathlib import Path
2+
3+
from aioarxiv.client.arxiv_client import ArxivClient
4+
from arclet.alconna import Alconna, Args, Subcommand
5+
from nonebot.log import logger
6+
from nonebot.typing import T_State
7+
from nonebot_plugin_alconna import Image, UniMsg, on_alconna
8+
from nonebot_plugin_htmlrender import template_to_pic
9+
from nonebot_plugin_uninfo import Uninfo
10+
11+
paper_cmd = on_alconna(
12+
Alconna(
13+
"paper",
14+
Subcommand(
15+
"-s|--search",
16+
Args["keyword", str],
17+
),
18+
Subcommand(
19+
"-id",
20+
Args["id", str],
21+
),
22+
),
23+
priority=5,
24+
block=True,
25+
)
26+
27+
28+
@paper_cmd.assign("search")
29+
async def handle_search(keyword: str, state: T_State, uninfo: Uninfo, unimsg: UniMsg):
30+
logger.debug(f"Searching for {keyword} by {uninfo.user.id}")
31+
async with ArxivClient() as client:
32+
result = await client.search(
33+
keyword,
34+
max_results=1,
35+
)
36+
await paper_cmd.send(
37+
f"Search result for {keyword} and get {result.total_result} papers"
38+
)
39+
for paper in result.papers:
40+
# await paper_cmd.send(text_paper_info(paper))
41+
await paper_cmd.send(
42+
Image(
43+
raw=(
44+
await template_to_pic(
45+
template_path=str(Path(__file__).parent / "jinja_temple"),
46+
template_name="paper.jinja2",
47+
templates={"paper": paper.model_dump()},
48+
)
49+
)
50+
)
51+
)
Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Paper Information</title>
7+
<style>
8+
body {
9+
font-family: Arial, sans-serif;
10+
line-height: 1.6;
11+
max-width: 1200px;
12+
margin: auto;
13+
padding: 20px;
14+
background-color: #ffffff;
15+
}
16+
17+
.header-info {
18+
text-align: right;
19+
color: #666;
20+
font-size: 0.9em;
21+
margin-bottom: 20px;
22+
}
23+
24+
.paper-title {
25+
border-bottom: 2px solid #ddd;
26+
padding-bottom: 10px;
27+
margin-bottom: 20px;
28+
display: flex;
29+
align-items: center;
30+
font-size: 1.5em;
31+
color: #2d3748;
32+
}
33+
34+
.grid-container {
35+
display: grid;
36+
grid-template-columns: repeat(2, 1fr);
37+
gap: 20px;
38+
}
39+
40+
.full-width {
41+
grid-column: 1 / -1;
42+
}
43+
44+
.info-block {
45+
border: 1px solid #eee;
46+
padding: 15px;
47+
border-radius: 5px;
48+
background-color: #fafafa;
49+
}
50+
51+
.info-row {
52+
display: flex;
53+
gap: 20px;
54+
margin-bottom: 10px;
55+
}
56+
57+
.info-item {
58+
flex: 1;
59+
background-color: #ffffff;
60+
border: 1px solid #e2e8f0;
61+
border-radius: 5px;
62+
padding: 10px;
63+
}
64+
65+
.icon {
66+
width: 20px;
67+
height: 20px;
68+
min-width: 20px;
69+
min-height: 20px;
70+
vertical-align: middle;
71+
margin-right: 8px;
72+
color: #4a5568;
73+
}
74+
75+
.content {
76+
margin-left: 25px;
77+
color: #4a5568;
78+
}
79+
80+
.label {
81+
font-weight: 600;
82+
margin-bottom: 8px;
83+
display: flex;
84+
align-items: center;
85+
color: #2d3748;
86+
}
87+
88+
.url-display {
89+
word-break: break-all;
90+
color: #666;
91+
font-family: monospace;
92+
font-size: 0.9em;
93+
background-color: #f7fafc;
94+
padding: 4px 8px;
95+
border-radius: 4px;
96+
}
97+
</style>
98+
</head>
99+
<body>
100+
{% if paper and paper.info %}
101+
<div class="header-info">
102+
nonebot-plugin-paper v0.1.0
103+
</div>
104+
105+
<h1 class="paper-title">
106+
{{ paper.info.title }}
107+
</h1>
108+
109+
<div class="grid-container">
110+
<div class="info-row full-width">
111+
<div class="label">
112+
<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
113+
stroke-width="1.5" stroke="currentColor" fill="none" width="20"
114+
height="20">
115+
<path stroke-linecap="round" stroke-linejoin="round"
116+
d="M15 19.128a9.38 9.38 0 0 0 2.625.372 9.337 9.337 0 0 0 4.121-.952 4.125 4.125 0 0 0-7.533-2.493M15 19.128v-.003c0-1.113-.285-2.16-.786-3.07M15 19.128v.106A12.318 12.318 0 0 1 8.624 21c-2.331 0-4.512-.645-6.374-1.766l-.001-.109a6.375 6.375 0 0 1 11.964-3.07M12 6.375a3.375 3.375 0 1 1-6.75 0 3.375 3.375 0 0 1 6.75 0Zm8.25 2.25a2.625 2.625 0 1 1-5.25 0 2.625 2.625 0 0 1 5.25 0Z"/>
117+
</svg>
118+
Authors
119+
</div>
120+
<div class="content">
121+
{% if paper.info.authors %}
122+
{% for author in paper.info.authors %}
123+
{{ author.name }}{% if not loop.last %}, {% endif %}
124+
{% endfor %}
125+
{% else %}
126+
No authors listed
127+
{% endif %}
128+
</div>
129+
</div>
130+
131+
<div class="info-row full-width">
132+
<div class="label">
133+
<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
134+
stroke-width="1.5" stroke="currentColor" fill="none" width="20"
135+
height="20">
136+
<path stroke-linecap="round" stroke-linejoin="round"
137+
d="M9.568 3H5.25A2.25 2.25 0 0 0 3 5.25v4.318c0 .597.237 1.17.659 1.591l9.581 9.581c.699.699 1.78.872 2.607.33a18.095 18.095 0 0 0 5.223-5.223c.542-.827.369-1.908-.33-2.607L11.16 3.66A2.25 2.25 0 0 0 9.568 3Z"/>
138+
<path stroke-linecap="round" stroke-linejoin="round"
139+
d="M6 6h.008v.008H6V6Z"/>
140+
</svg>
141+
Categories
142+
</div>
143+
<div class="content">
144+
{% if paper.info.categories and paper.info.categories.primary %}
145+
{{ paper.info.categories.primary.term }}
146+
{% else %}
147+
No category specified
148+
{% endif %}
149+
</div>
150+
</div>
151+
152+
<div class="info-row full-width">
153+
<div class="label">
154+
<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
155+
stroke-width="1.5" stroke="currentColor" fill="none" width="20"
156+
height="20">
157+
<path stroke-linecap="round" stroke-linejoin="round"
158+
d="M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 0 1 2.25-2.25h13.5A2.25 2.25 0 0 1 21 7.5v11.25m-18 0A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75m-18 0v-7.5A2.25 2.25 0 0 1 5.25 9h13.5A2.25 2.25 0 0 1 21 11.25v7.5"/>
159+
</svg>
160+
Published & Updated
161+
</div>
162+
<div class="content">
163+
{% if paper.info.published %}
164+
Published: {{ paper.info.published.strftime("%Y-%m-%d") }}<br>
165+
{% endif %}
166+
{% if paper.info.updated %}
167+
Updated: {{ paper.info.updated.strftime("%Y-%m-%d") }}
168+
{% endif %}
169+
</div>
170+
</div>
171+
172+
<div class="info-block full-width">
173+
<div class="label">
174+
<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
175+
stroke-width="1.5" stroke="currentColor" fill="none" width="20"
176+
height="20">
177+
<path stroke-linecap="round" stroke-linejoin="round"
178+
d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25H12"/>
179+
</svg>
180+
Summary
181+
</div>
182+
<div class="content">
183+
{% if paper.info.summary %}
184+
{% if paper.info.summary|length > 200 %}
185+
{{ paper.info.summary[:250] }}...
186+
{% else %}
187+
{{ paper.info.summary }}
188+
{% endif %}
189+
{% else %}
190+
No summary available
191+
{% endif %}
192+
</div>
193+
</div>
194+
195+
{% if paper.doi or paper.journal_ref %}
196+
{% if paper.doi %}
197+
<div class="label">
198+
<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
199+
stroke-width="1.5" stroke="currentColor" fill="none" width="20"
200+
height="20">
201+
<path stroke-linecap="round" stroke-linejoin="round"
202+
d="M13.19 8.688a4.5 4.5 0 0 1 1.242 7.244l-4.5 4.5a4.5 4.5 0 0 1-6.364-6.364l1.757-1.757m13.35-.622 1.757-1.757a4.5 4.5 0 0 0-6.364-6.364l-4.5 4.5a4.5 4.5 0 0 0 1.242 7.244"/>
203+
</svg>
204+
DOI
205+
</div>
206+
<div class="content url-display">{{ paper.doi }}</div>
207+
{% endif %}
208+
209+
{% if paper.journal_ref %}
210+
<div class="label" style="margin-top: 10px;">
211+
<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
212+
stroke-width="1.5" stroke="currentColor" fill="none" width="20"
213+
height="20">
214+
<path stroke-linecap="round" stroke-linejoin="round"
215+
d="M12 6.042A8.967 8.967 0 0 0 6 3.75c-1.052 0-2.062.18-3 .512v14.25A8.987 8.987 0 0 1 6 18c2.305 0 4.408.867 6 2.292m0-14.25a8.966 8.966 0 0 1 6-2.292c1.052 0 2.062.18 3 .512v14.25A8.987 8.987 0 0 0 18 18a8.967 8.967 0 0 0-6 2.292m0-14.25v14.25"/>
216+
</svg>
217+
Journal Reference
218+
</div>
219+
<div class="content">{{ paper.journal_ref }}</div>
220+
{% endif %}
221+
{% endif %}
222+
223+
{% if paper.pdf_url or paper.comment %}
224+
{% if paper.pdf_url %}
225+
<div class="label">
226+
<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
227+
stroke-width="1.5" stroke="currentColor" fill="none" width="20"
228+
height="20">
229+
<path stroke-linecap="round" stroke-linejoin="round"
230+
d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Z"/>
231+
</svg>
232+
PDF URL
233+
</div>
234+
<div class="content url-display">{{ paper.pdf_url }}</div>
235+
{% endif %}
236+
237+
{% if paper.comment %}
238+
<div class="label" style="margin-top: 10px;">
239+
<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
240+
stroke-width="1.5" stroke="currentColor" fill="none" width="20"
241+
height="20">
242+
<path stroke-linecap="round" stroke-linejoin="round"
243+
d="M7.5 8.25h9m-9 3H12m-9.75 1.51c0 1.6 1.123 2.994 2.707 3.227 1.129.166 2.27.293 3.423.379.35.026.67.21.865.501L12 21l2.755-4.133a1.14 1.14 0 0 1 .865-.501 48.172 48.172 0 0 0 3.423-.379c1.584-.233 2.707-1.626 2.707-3.228V6.741c0-1.602-1.123-2.995-2.707-3.228A48.394 48.394 0 0 0 12 3c-2.392 0-4.744.175-7.043.513C3.373 3.746 2.25 5.14 2.25 6.741v6.018Z"/>
244+
</svg>
245+
Comment
246+
</div>
247+
<div class="content">{{ paper.comment }}</div>
248+
{% endif %}
249+
{% endif %}
250+
<div class="content"></div>
251+
{% endif %}
252+
</body>
253+
</html>

0 commit comments

Comments
 (0)