Skip to content

Commit

Permalink
🔧 添加配置加载
Browse files Browse the repository at this point in the history
  • Loading branch information
BalconyJH committed Jan 23, 2024
1 parent b3ccffb commit b85315b
Show file tree
Hide file tree
Showing 8 changed files with 416 additions and 302 deletions.
5 changes: 5 additions & 0 deletions nonebot_plugin_literature/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from nonebot import require

require("nonebot_plugin_saa")
require("nonebot_plugin_htmlrender")
require("nonebot_plugin_localstore")
29 changes: 29 additions & 0 deletions nonebot_plugin_literature/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import re

from nonebot import get_driver
from nonebot_plugin_localstore import get_data_dir
from pydantic import Extra, Field, HttpUrl, BaseModel, validator

DATA_DIR = get_data_dir("nonebot_plugin_literature")


class Config(BaseModel, extra=Extra.ignore):
proxy: HttpUrl = Field(None, description="HTTP proxy to use for requests.")
timeout: int = Field(30, description="Timeout for web requests in seconds.")
literature_render: str = Field("htmlrender", description="Render type for literature.")

@validator("literature_render")
def check_literature_render(cls, values):
if values["literature_render"] not in ["htmlrender", "PIL"]:
raise ValueError("literature_render must be one of 'htmlrender' or 'PIL'")
return values

@validator("proxy")
def check_proxy(cls, values):
if not re.match(r"^http://[^\s:]+:[0-9]+$", values):
raise ValueError("proxy 必须是 http://xxx:xxx 格式")
return {"http": values, "https": values}


global_config = get_driver().config
plugin_config = Config.parse_obj(global_config)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import requests

from nonebot_plugin_prxiv.model import Feed, Entry, Author
from nonebot_plugin_literature.model import Feed, Entry, Author

response = requests.get("http://example.com/api/some_atom_feed")
path = Path(__file__).parent / "response.xml"
Expand Down
610 changes: 315 additions & 295 deletions pdm.lock

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies = [
"nonebot-plugin-localstore>=0.5.1",
"nonebot-plugin-apscheduler>=0.3.0",
"nonebot-plugin-htmlrender>=0.2.3",
"niquests>=3.4.4",
]
requires-python = ">=3.8.1"
readme = "README.md"
Expand All @@ -30,10 +31,12 @@ adapters = [
{ name = "OneBot V12", module_name = "nonebot.adapters.onebot.v12", project_link = "nonebot-adapter-onebot", desc = "OneBot V12 协议" },
{ name = "OneBot V11", module_name = "nonebot.adapters.onebot.v11", project_link = "nonebot-adapter-onebot", desc = "OneBot V11 协议" },
]
plugins = ["nonebot_plugin_htmlrender", "nonebot_plugin_saa", "nonebot_plugin_localstore"]
plugin_dirs = ["src"]
plugins = ["nonebot_plugin_literature"]
plugin_dirs = []
builtin_plugins = []

[tool.pdm]
distribution = true
[tool.pdm.dev-dependencies]
test = [
"nonebug>=0.3.5",
Expand All @@ -43,14 +46,10 @@ test = [
"pre-commit>=3.3.3",
"flake8>=6.1.0",
"nonebug-saa>=0.3.1",
"nb-cli>=1.2.8",
"pytest-cov>=4.1.0",
"pytest-xdist>=3.5.0",
]

[tool.pdm]
package-type = "library"

[tool.black]
line-length = 120
target-version = ["py38", "py39", "py310", "py311"]
Expand Down
Empty file.
61 changes: 61 additions & 0 deletions tests/response.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<link href="http://arxiv.org/api/query?search_query%3Dall%3Aelectron%26id_list%3D%26start%3D0%26max_results%3D1" rel="self" type="application/atom+xml"/>
<title type="html">ArXiv Query: search_query=all:electron&amp;id_list=&amp;start=0&amp;max_results=1</title>
<id>http://arxiv.org/api/cHxbiOdZaP56ODnBPIenZhzg5f8</id>
<updated>2024-01-07T00:00:00-05:00</updated>
<opensearch:totalResults xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">204910</opensearch:totalResults>
<opensearch:startIndex xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">0</opensearch:startIndex>
<opensearch:itemsPerPage xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">1</opensearch:itemsPerPage>
<entry>
<id>http://arxiv.org/abs/cond-mat/0102536v1</id>
<updated>2001-02-28T20:12:09Z</updated>
<published>2001-02-28T20:12:09Z</published>
<title>Impact of Electron-Electron Cusp on Configuration Interaction Energies</title>
<summary> The effect of the electron-electron cusp on the convergence of configuration
interaction (CI) wave functions is examined. By analogy with the
pseudopotential approach for electron-ion interactions, an effective
electron-electron interaction is developed which closely reproduces the
scattering of the Coulomb interaction but is smooth and finite at zero
electron-electron separation. The exact many-electron wave function for this
smooth effective interaction has no cusp at zero electron-electron separation.
We perform CI and quantum Monte Carlo calculations for He and Be atoms, both
with the Coulomb electron-electron interaction and with the smooth effective
electron-electron interaction. We find that convergence of the CI expansion of
the wave function for the smooth electron-electron interaction is not
significantly improved compared with that for the divergent Coulomb interaction
for energy differences on the order of 1 mHartree. This shows that, contrary to
popular belief, description of the electron-electron cusp is not a limiting
factor, to within chemical accuracy, for CI calculations.
</summary>
<author>
<name>David Prendergast</name>
<arxiv:affiliation xmlns:arxiv="http://arxiv.org/schemas/atom">Department of Physics</arxiv:affiliation>
</author>
<author>
<name>M. Nolan</name>
<arxiv:affiliation xmlns:arxiv="http://arxiv.org/schemas/atom">NMRC, University College, Cork, Ireland</arxiv:affiliation>
</author>
<author>
<name>Claudia Filippi</name>
<arxiv:affiliation xmlns:arxiv="http://arxiv.org/schemas/atom">Department of Physics</arxiv:affiliation>
</author>
<author>
<name>Stephen Fahy</name>
<arxiv:affiliation xmlns:arxiv="http://arxiv.org/schemas/atom">Department of Physics</arxiv:affiliation>
</author>
<author>
<name>J. C. Greer</name>
<arxiv:affiliation xmlns:arxiv="http://arxiv.org/schemas/atom">NMRC, University College, Cork, Ireland</arxiv:affiliation>
</author>
<arxiv:doi xmlns:arxiv="http://arxiv.org/schemas/atom">10.1063/1.1383585</arxiv:doi>
<link title="doi" href="http://dx.doi.org/10.1063/1.1383585" rel="related"/>
<arxiv:comment xmlns:arxiv="http://arxiv.org/schemas/atom">11 pages, 6 figures, 3 tables, LaTeX209, submitted to The Journal of
Chemical Physics</arxiv:comment>
<arxiv:journal_ref xmlns:arxiv="http://arxiv.org/schemas/atom">J. Chem. Phys. 115, 1626 (2001)</arxiv:journal_ref>
<link href="http://arxiv.org/abs/cond-mat/0102536v1" rel="alternate" type="text/html"/>
<link title="pdf" href="http://arxiv.org/pdf/cond-mat/0102536v1" rel="related" type="application/pdf"/>
<arxiv:primary_category xmlns:arxiv="http://arxiv.org/schemas/atom" term="cond-mat.str-el" scheme="http://arxiv.org/schemas/atom"/>
<category term="cond-mat.str-el" scheme="http://arxiv.org/schemas/atom"/>
</entry>
</feed>

0 comments on commit b85315b

Please sign in to comment.