GitHub Action
commited on
Commit
·
121c381
1
Parent(s):
4e2f2a8
Sync from GitHub with Git LFS
Browse files
scripts/publish_to_blogger.py
CHANGED
|
@@ -56,7 +56,6 @@ def get_existing_posts(service):
|
|
| 56 |
try:
|
| 57 |
response = service.posts().list(blogId=BLOG_ID, maxResults=500, pageToken=nextPageToken).execute()
|
| 58 |
for post in response.get("items", []):
|
| 59 |
-
# Проверяем наличие доступа на редактирование
|
| 60 |
post_id = post["id"]
|
| 61 |
title = post["title"]
|
| 62 |
existing[title] = post_id
|
|
@@ -88,11 +87,6 @@ def main(force: bool = False):
|
|
| 88 |
name = md_file.stem
|
| 89 |
h = file_hash(md_file)
|
| 90 |
|
| 91 |
-
if not force and name in published and published[name]["hash"] == h:
|
| 92 |
-
continue # ничего не изменилось
|
| 93 |
-
|
| 94 |
-
print(f"📝 {'Форс-обновление' if force else 'Новый или изменённый'} пост: {name}")
|
| 95 |
-
|
| 96 |
md_text = md_file.read_text(encoding="utf-8")
|
| 97 |
source_link = f"Источник: [ {md_file.name} ](https://github.com/kagvi13/HMP/blob/main/docs/{md_file.name})\n\n"
|
| 98 |
md_text = source_link + md_text
|
|
@@ -119,17 +113,21 @@ def main(force: bool = False):
|
|
| 119 |
}
|
| 120 |
|
| 121 |
try:
|
| 122 |
-
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
try:
|
| 125 |
-
post_id = existing_posts[name]
|
| 126 |
post = service.posts().update(blogId=BLOG_ID, postId=post_id, body=body).execute()
|
| 127 |
print(f"♻ Обновлён пост: {post['url']}")
|
| 128 |
except HttpError as e:
|
| 129 |
if e.resp.status == 403:
|
| 130 |
-
# Нет прав на обновление → создаём новый пост
|
| 131 |
post = service.posts().insert(blogId=BLOG_ID, body=body).execute()
|
| 132 |
-
print(f"⚠ Пост существовал, но
|
| 133 |
post_id = post["id"]
|
| 134 |
else:
|
| 135 |
raise e
|
|
|
|
| 56 |
try:
|
| 57 |
response = service.posts().list(blogId=BLOG_ID, maxResults=500, pageToken=nextPageToken).execute()
|
| 58 |
for post in response.get("items", []):
|
|
|
|
| 59 |
post_id = post["id"]
|
| 60 |
title = post["title"]
|
| 61 |
existing[title] = post_id
|
|
|
|
| 87 |
name = md_file.stem
|
| 88 |
h = file_hash(md_file)
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
md_text = md_file.read_text(encoding="utf-8")
|
| 91 |
source_link = f"Источник: [ {md_file.name} ](https://github.com/kagvi13/HMP/blob/main/docs/{md_file.name})\n\n"
|
| 92 |
md_text = source_link + md_text
|
|
|
|
| 113 |
}
|
| 114 |
|
| 115 |
try:
|
| 116 |
+
post_id = existing_posts.get(name)
|
| 117 |
+
|
| 118 |
+
if post_id:
|
| 119 |
+
# Есть существующий пост, проверяем хэш
|
| 120 |
+
if not force and name in published and published[name]["hash"] == h:
|
| 121 |
+
print(f"✅ Пост '{name}' без изменений — пропускаем.")
|
| 122 |
+
continue
|
| 123 |
+
|
| 124 |
try:
|
|
|
|
| 125 |
post = service.posts().update(blogId=BLOG_ID, postId=post_id, body=body).execute()
|
| 126 |
print(f"♻ Обновлён пост: {post['url']}")
|
| 127 |
except HttpError as e:
|
| 128 |
if e.resp.status == 403:
|
|
|
|
| 129 |
post = service.posts().insert(blogId=BLOG_ID, body=body).execute()
|
| 130 |
+
print(f"⚠ Пост существовал, но прав нет. Создан новый: {post['url']}")
|
| 131 |
post_id = post["id"]
|
| 132 |
else:
|
| 133 |
raise e
|