Skip to content

Commit

Permalink
更正文件命名错误及调整配置项 (#496)
Browse files Browse the repository at this point in the history
* 🔧 自动更新依赖文件

* 调整playwright默认安装的浏览器内核

新增安装playwright时需要下载的浏览器内核,默认为firefox

* 添加有关playwright的说明

* 修复文件错名及优化配置项

* 使用配置模型及修复部分错误导致的显示异常

1. 使用小派蒙配置模型
2. 修复图片生成时丢失html样式

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
nicklly and github-actions[bot] authored Jan 22, 2024
1 parent a01db7f commit aa021de
Show file tree
Hide file tree
Showing 11 changed files with 1,321 additions and 1,032 deletions.
1 change: 1 addition & 0 deletions LittlePaimon/config/config/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ConfigModel(BaseModel):
admin_theme: Literal['default', 'antd', 'ang', 'dark'] = Field('default', alias='Web端主题')

command_alias_enable: bool = Field(True, alias='启用命令别名')
browser_type: Literal['chromium', 'firefox', 'webkit'] = Field('firefox', alias='浏览器内核')

# 早报60s
morning_news: str = Field('https://api.vvhan.com/api/60s', alias='早报60s')
Expand Down
8 changes: 3 additions & 5 deletions LittlePaimon/plugins/Genshin_Calendar/generate.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from os import getcwd

import jinja2
from .event import *
from datetime import datetime, timedelta
from LittlePaimon.utils.brower import get_new_page
from LittlePaimon.utils.browser import get_new_page

body = []
weeks = []
Expand Down Expand Up @@ -48,10 +46,10 @@ async def generate_day_schedule(server='cn'):
'online': f'{datetime.strftime(event["start"], "%m-%d")} ~ {datetime.strftime(event["end"], "%m-%d")}',
'color': event['color'], 'banner': event['banner']})

content = await template.render_async(body=body, css_path=template_path, week=weeks)
content = await template.render_async(body=body, week=weeks)

async with get_new_page(viewport={'width': 600, 'height': 10}) as page:
await page.goto(f'file://{getcwd()}')
await page.goto(f'file://{template_path}/calendar.html')
await page.set_content(content, wait_until='networkidle')
await page.wait_for_timeout(0.2)
return await page.screenshot(full_page=True)
6 changes: 3 additions & 3 deletions LittlePaimon/plugins/Genshin_Calendar/template/calendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<head>
<meta charset="UTF-8">
<title>原神日历</title>
<link rel="stylesheet" href="{{ css_path }}/iview.css" />
<link rel="stylesheet" href="{{ css_path }}/index.css" />
<link rel="stylesheet" href="{{ css_path }}/normalize.css">
<link rel="stylesheet" href="iview.css" />
<link rel="stylesheet" href="index.css" />
<link rel="stylesheet" href="normalize.css">
</head>

<body>
Expand Down
2 changes: 1 addition & 1 deletion LittlePaimon/plugins/Mihoyo_bbs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from nonebot.plugin import PluginMetadata

from LittlePaimon.utils import logger
from LittlePaimon.utils.brower import screenshot
from LittlePaimon.utils.browser import screenshot

__plugin_meta__ = PluginMetadata(
name='米游社',
Expand Down
2 changes: 1 addition & 1 deletion LittlePaimon/plugins/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from LittlePaimon import SUPERUSERS
from LittlePaimon.config import config
from LittlePaimon.utils.brower import screenshot
from LittlePaimon.utils.browser import screenshot


async def permission_check(event: MessageEvent) -> bool:
Expand Down
14 changes: 11 additions & 3 deletions LittlePaimon/utils/brower.py → LittlePaimon/utils/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

from . import DRIVER
from .logger import logger
from LittlePaimon.config import config as bot_config

_playwright: Optional[Playwright] = None
_browser: Optional[Browser] = None
_browser_type = bot_config.browser_type


async def init(**kwargs) -> Browser:
Expand All @@ -27,7 +29,13 @@ async def init(**kwargs) -> Browser:

async def launch_browser(**kwargs) -> Browser:
assert _playwright is not None, "Playwright is not initialized"
return await _playwright.chromium.launch(**kwargs)

if _browser_type == 'firefox':
return await _playwright.firefox.launch(**kwargs)
elif _browser_type == 'chromium':
return await _playwright.chromium.launch(**kwargs)
elif _browser_type == 'webkit':
return await _playwright.webkit.launch(**kwargs)


async def get_browser(**kwargs) -> Browser:
Expand All @@ -40,8 +48,8 @@ async def install_browser():

from playwright.__main__ import main

logger.info('Playwright', '正在安装 chromium')
sys.argv = ["", "install", "chromium"]
logger.info('Playwright', f'正在安装 {_browser_type}')
sys.argv = ["", "install", f"{_browser_type}"]
with suppress(SystemExit):
logger.info('Playwright', '正在安装依赖')
os.system("playwright install-deps")
Expand Down
20 changes: 20 additions & 0 deletions LittlePaimon/web/pages/config_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@
value='${CookieWeb地址}',
labelRemark=Remark(shape='circle', content='只是设置对用户显示的CookieWeb地址,要填写实际的地址')
),
Select(
label='浏览器内核',
name='浏览器内核',
value='${浏览器内核}',
labelRemark=Remark(shape='circle', content='用于生成原神日历的浏览器内核'),
options=[
{
'label': '火狐FireFox',
'value': 'firefox'
},
{
'label': '谷歌Chormium',
'value': 'chromium'
},
{
'label': 'WebKit',
'value': 'webkit'
}
]
),
Switch(
label='是否启用Web端',
name='启用Web端',
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
<img src="https://s1.ax1x.com/2023/02/05/pS6fAG6.jpg" alt="map">
</details>

## | Playwright相关问题
因部分系统不适用于chromium(谷歌浏览器),故将默认内核改为FireFox
如需切换,可更改 config/paimon_config_default.yml 的默认值

## | 常见问题&致谢

详见[常见问题](https://docs.paimon.cherishmoon.fun/question.html)[致谢](https://docs.paimon.cherishmoon.fun/thanks.html)
Expand Down
7 changes: 6 additions & 1 deletion config/paimon_config_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ CookieWeb地址: http://127.0.0.1:13579/LittlePaimon/cookie
实时便签检查开关: true # 是否开启实时便签检查
实时便签检查间隔: 16 # 实时便签检查间隔,单位分钟
实时便签停止检查开始时间: 0
实时便签停止检查结束时间: 6 # 处于这个时间段的时候停止检查
实时便签停止检查结束时间: 6 # 处于这个时间段的时候停止检查

# 浏览器内核设置
# 可选 chromium, firefox, webkit
# 默认使用firefox
browser_type: ''
Loading

0 comments on commit aa021de

Please sign in to comment.