Skip to content

Commit a7c26b6

Browse files
committed
sns 배포 로직 수정
1 parent 9c3e129 commit a7c26b6

2 files changed

Lines changed: 15 additions & 16 deletions

File tree

.github/scripts/notify_new_posts.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
"""Notify upload-post.com about newly added blog posts.
22
33
Reads a newline-separated list of added markdown paths from the env var
4-
ADDED_FILES, parses Hugo front matter, and POSTs a formatted message per file
5-
to the upload-post.com text endpoint.
4+
ADDED_FILES, parses Hugo front matter, and posts a formatted message per file
5+
via the official upload-post Python SDK.
66
"""
77

88
import os
99
import sys
1010
from pathlib import Path
1111

12-
import requests
1312
import yaml
13+
from upload_post import UploadPostClient
1414

15-
API_URL = "https://api.upload-post.com/api/upload_text"
1615
SITE_BASE = "https://2rebcat.github.io"
1716
BLOG_ROOT = Path("content/blog")
1817
INDEX_NAME = "_index.md"
@@ -43,15 +42,6 @@ def post_url_for(path: Path) -> str:
4342
return f"{SITE_BASE}/blog/{topic}/{slug}/"
4443

4544

46-
def upload(message: str, api_key: str, user: str, platforms: list[str]) -> None:
47-
headers = {"Authorization": f"Apikey {api_key}"}
48-
fields = [("user", user), ("title", message)]
49-
fields.extend(("platform[]", p) for p in platforms)
50-
resp = requests.post(API_URL, headers=headers, files=fields, timeout=30)
51-
print(f" status={resp.status_code} body={resp.text[:500]}")
52-
resp.raise_for_status()
53-
54-
5545
def main() -> int:
5646
api_key = os.environ["UPLOAD_POST_API_KEY"].strip()
5747
user = os.environ["UPLOAD_POST_USER"].strip()
@@ -61,12 +51,14 @@ def main() -> int:
6151
if not user:
6252
print("UPLOAD_POST_USER is empty.", file=sys.stderr)
6353
return 1
64-
print(f"Using upload-post user='{user}' (length={len(user)})")
54+
6555
platforms = [
6656
p.strip()
6757
for p in os.environ.get("UPLOAD_POST_PLATFORMS", "x").split(",")
6858
if p.strip()
6959
]
60+
print(f"user={user!r} platforms={platforms}")
61+
7062
added = [
7163
line.strip()
7264
for line in os.environ.get("ADDED_FILES", "").splitlines()
@@ -91,6 +83,8 @@ def main() -> int:
9183
return 0
9284

9385
print(f"Found {len(targets)} new post(s): {[str(p) for p in targets]}")
86+
87+
client = UploadPostClient(api_key)
9488
failures = 0
9589
for path in targets:
9690
try:
@@ -103,7 +97,12 @@ def main() -> int:
10397
url = post_url_for(path)
10498
message = build_message(title, summary, url)
10599
print(f"Posting for {path}:")
106-
upload(message, api_key, user, platforms)
100+
response = client.upload_text(
101+
title=message,
102+
user=user,
103+
platforms=platforms,
104+
)
105+
print(f" response={response}")
107106
except Exception as e:
108107
failures += 1
109108
print(f" ERROR for {path}: {e}", file=sys.stderr)

.github/workflows/notify-new-posts.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555

5656
- name: Install dependencies
5757
if: steps.diff.outputs.added != ''
58-
run: pip install requests pyyaml
58+
run: pip install upload-post pyyaml
5959

6060
- name: Notify upload-post.com
6161
if: steps.diff.outputs.added != ''

0 commit comments

Comments
 (0)