Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 通知的内容包含无意义的前导和尾随空格 #520

Merged
merged 1 commit into from
Oct 5, 2023

Conversation

KuroiCc
Copy link
Contributor

@KuroiCc KuroiCc commented Oct 5, 2023

问题

通知的内容包含无意义的前导和尾随空格

现在通知信息内容生成的实现为

def gen_message(notify: Notification) -> str:
text = f"""
番剧名称:{notify.official_title}\n季度: 第{notify.season}\n更新集数: 第{notify.episode}\n{notify.poster_path}\n
"""
return text

此实现会导致实际的推送信息为
"\n\s\s\s\s\s\s\s\s番剧名称:{notify.official_title}\n季度: 第{notify.season}季\n更新集数: 第{notify.episode}集\n{notify.poster_path}\n\n\s\s\s\s\s\s\s\s"

整个通知模块正在被重构(#513), 重构后可能就不会有这个问题, 但是作为临时的解决方案我提交了这个pr

测试

  • 仅测试了bark
  • 把整个项目在本地跑起来太麻烦了使用以下代码进行的测试
import requests
import time

poster_path = "https://test.poster_path.com/1.jpg"


class Notify:
    def __init__(self, official_title, season, episode, poster_path):
        self.official_title = official_title
        self.season = season
        self.episode = episode
        self.poster_path = poster_path


def notify(notify: Notify):
    token = "*******************"
    notification_url = "https://api.day.app/push"

    text = f"""
    番剧名称:{notify.official_title}\n季度: 第{notify.season}\n更新集数: 第{notify.episode}\n{notify.poster_path}\n
    """
    data1 = {"title": notify.official_title, "body": text, "device_key": token}
    data2 = {"title": notify.official_title, "body": text.strip(), "device_key": token}

    res = requests.post(notification_url, data1)
    print(
        f"已发送第一条通知, staute_code: {res.status_code}, text: {res.text}, reason: {res.reason}"
    )
    time.sleep(5)
    res = requests.post(notification_url, data2)
    print(
        f"已发送第二条通知, staute_code: {res.status_code}, text: {res.text}, reason: {res.reason}"
    )


notify_instance = Notify("Test_初音ミクの消失", 39, 39, poster_path)
notify(notify_instance)

测试结果

@vercel
Copy link

vercel bot commented Oct 5, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
auto-bangumi ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 5, 2023 2:41am

Copy link
Contributor

@100gle 100gle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@KuroiCc
Copy link
Contributor Author

KuroiCc commented Oct 5, 2023

BTW, TG没有这个bug, 因为TG会自动去除每个信息前导和尾随空格

@EstrellaXD
Copy link
Owner

Approved.

@EstrellaXD EstrellaXD merged commit 1205afb into EstrellaXD:main Oct 5, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants