Skip to content

Commit

Permalink
增加邮件相关secrets,优化Actions实现
Browse files Browse the repository at this point in the history
  • Loading branch information
hect0x7 committed Oct 29, 2023
1 parent a292340 commit a3120a7
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 22 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/download.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,18 @@ jobs:
crawler:
runs-on: ubuntu-latest
env:
# 登录相关secrets
JM_USERNAME: ${{ secrets.JM_USERNAME }}
JM_PASSWORD: ${{ secrets.JM_PASSWORD }}

# 邮件相关secrets
EMAIL_FROM: ${{ secrets.EMAIL_FROM }}
EMAIL_TO: ${{ secrets.EMAIL_TO }}
EMAIL_PASS: ${{ secrets.EMAIL_PASS }}
EMAIL_TITLE: ${{ secrets.EMAIL_TITLE }}
EMAIL_CONTENT: ${{ secrets.EMAIL_CONTENT }}

# 固定值
JM_DOWNLOAD_DIR: /home/runner/work/jmcomic/download/
ZIP_NAME: '本子.tar.gz'
UPLOAD_NAME: '下载完成的本子'
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/download_dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,18 @@ jobs:
ZIP_NAME: ${{ github.event.inputs.ZIP_NAME }}
UPLOAD_NAME: ${{ github.event.inputs.UPLOAD_NAME }}
IMAGE_SUFFIX: ${{ github.event.inputs.IMAGE_SUFFIX }}
# secrets

# 登录相关secrets
JM_USERNAME: ${{ secrets.JM_USERNAME }}
JM_PASSWORD: ${{ secrets.JM_PASSWORD }}

# 邮件相关secrets
EMAIL_FROM: ${{ secrets.EMAIL_FROM }}
EMAIL_TO: ${{ secrets.EMAIL_TO }}
EMAIL_PASS: ${{ secrets.EMAIL_PASS }}
EMAIL_TITLE: ${{ secrets.EMAIL_TITLE }}
EMAIL_CONTENT: ${{ secrets.EMAIL_CONTENT }}

# 固定值
JM_DOWNLOAD_DIR: /home/runner/work/jmcomic/download/

Expand Down
20 changes: 17 additions & 3 deletions assets/option/option_workflow_download.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dir_rule:

client:
domain:
html: [jmcomic1.me, jmcomic.me]
html: [ jmcomic1.me, jmcomic.me ]

# 插件配置
plugins:
Expand All @@ -15,7 +15,21 @@ plugins:
interval: 0.5 # 间隔时间
enable_warning: false # 不告警

- plugin: client_proxy
- plugin: client_proxy # 提高移动端的请求效率的插件
kwargs:
proxy_client_key: cl_proxy_future
whitelist: [ api, ]
whitelist: [ api, ]

- plugin: login # 登录插件
kwargs:
username: ${JM_USERNAME}
password: ${JM_PASSWORD}

after_album: # 下载完成以后
- plugin: send_qq_email # 发送邮件,如果未配置下面的前3个环境变量则不会发送。
kwargs:
msg_from: ${EMAIL_FROM}
msg_to: ${EMAIL_TO}
password: ${EMAIL_PASS}
title: ${EMAIL_TITLE}
content: ${EMAIL_CONTENT}
12 changes: 9 additions & 3 deletions src/jmcomic/jm_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ class JmLoginPlugin(JmOptionPlugin):
"""
plugin_key = 'login'

def invoke(self, username, password) -> None:
assert isinstance(username, str), '用户名必须是str'
assert isinstance(password, str), '密码必须是str'
def invoke(self,
username: str,
password: str,
) -> None:
if not (username and password):
return

client = self.option.new_jm_client()
client.login(username, password)
Expand Down Expand Up @@ -400,6 +403,9 @@ def invoke(self,
album=None,
downloader=None,
) -> None:
if not (msg_from and msg_to and password):
self.debug('发送邮件的相关参数为空,不处理')
return
from common import EmailConfig
econfig = EmailConfig(msg_from, msg_to, password)
epostman = econfig.create_email_postman()
Expand Down
2 changes: 1 addition & 1 deletion src/jmcomic/jm_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def match_os_env(cls, match: Match) -> str:
name = match[1]
value = os.getenv(name, None)
assert value is not None, f"未配置环境变量: {name}"
return os.path.abspath(value)
return value

dsl_replacer = DSLReplacer()

Expand Down
14 changes: 0 additions & 14 deletions usage/workflow_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,6 @@ def cover_option_config(option: JmOption):
option.download.image.suffix = fix_suffix(suffix)


def login_if_configured(option):
# 检查环境变量中是否有禁漫的用户名和密码,如果有则登录
# 禁漫的大部分本子,下载是不需要登录的,少部分敏感题材需要登录
# 如果你希望以登录状态下载本子,你需要自己配置一下GitHub Actions的 `secrets`
# 配置的方式很简单,网页上点一点就可以了
# 具体做法请去看官方教程:https://docs.github.com/en/actions/security-guides/encrypted-secrets
# 萌新注意!!!如果你想 `开源` 你的禁漫帐号,你也可以直接把账号密码写到下面的代码😅
username = get_env('JM_USERNAME', None)
password = get_env('JM_PASSWORD', None)
if username is not None and password is not None:
# 调用login插件
JmLoginPlugin(option).invoke(username, password)


def log_before_raise():
jm_download_dir = get_env('JM_DOWNLOAD_DIR', workspace())
mkdir_if_not_exists(jm_download_dir)
Expand Down

0 comments on commit a3120a7

Please sign in to comment.