MCPcopy Create free account
hub / github.com/MoMingRose/QLAutomateTasks / bark

Function bark

notify.py:133–171  ·  view source on GitHub ↗

使用 bark 推送消息。

(title: str, content: str)

Source from the content-addressed store, hash-verified

131
132
133def bark(title: str, content: str) -> None:
134 """
135 使用 bark 推送消息。
136 """
137 if not push_config.get("BARK_PUSH"):
138 print("bark 服务的 BARK_PUSH 未设置!!\n取消推送")
139 return
140 print("bark 服务启动")
141
142 if push_config.get("BARK_PUSH").startswith("http"):
143 url = f'{push_config.get("BARK_PUSH")}/{urllib.parse.quote_plus(title)}/{urllib.parse.quote_plus(content)}'
144 else:
145 url = f'https://api.day.app/{push_config.get("BARK_PUSH")}/{urllib.parse.quote_plus(title)}/{urllib.parse.quote_plus(content)}'
146
147 bark_params = {
148 "BARK_ARCHIVE": "isArchive",
149 "BARK_GROUP": "group",
150 "BARK_SOUND": "sound",
151 "BARK_ICON": "icon",
152 "BARK_LEVEL": "level",
153 "BARK_URL": "url",
154 }
155 params = ""
156 for pair in filter(
157 lambda pairs: pairs[0].startswith("BARK_")
158 and pairs[0] != "BARK_PUSH"
159 and pairs[1]
160 and bark_params.get(pairs[0]),
161 push_config.items(),
162 ):
163 params += f"{bark_params.get(pair[0])}={pair[1]}&"
164 if params:
165 url = url + "?" + params.rstrip("&")
166 response = requests.get(url).json()
167
168 if response["code"] == 200:
169 print("bark 推送成功!")
170 else:
171 print("bark 推送失败!")
172
173
174def console(title: str, content: str) -> None:

Callers

nothing calls this directly

Calls 1

printFunction · 0.85

Tested by

no test coverage detected