概述
服务器崩溃于2024-06-23。存活时间半年。格式化服务器。
安装1panel,MySql,wordpress,OpenResty,配置域名和 SSL 证书略
安装 WP Githuber MD 作为 MD 编辑器插件
然后开始搞主题
主题设置
主题github: https://github.com/solstice23/argon-theme
主题文档: https://argon-docs.solstice23.top/
图标库链接: https://fontawesome.com/v4/icons/
背景图片获取: https://wallhaven.cc/
主题json配置存档
{"argon_theme_color":"#3f51b5","argon_theme_color_hex_preview":"#3f51b5","argon_show_customize_theme_color_picker":true,"argon_enable_immersion_color":"false","argon_darkmode_autoswitch":"time","argon_enable_amoled_dark":"false","argon_card_radius":"15","argon_card_shadow":"default","argon_page_layout":"double","argon_article_list_waterflow":"1","argon_article_list_layout":"3","argon_font":"sans-serif","argon_assets_path":"jsdelivr_fastly","argon_custom_assets_path":"","argon_wp_path":"/","argon_dateformat":"YMD","argon_enable_headroom":"true","argon_toolbar_title":"归零码记","argon_toolbar_icon":"","argon_toolbar_icon_link":" ","argon_toolbar_blur":"true","argon_banner_title":"归零码记","argon_banner_subtitle":"「愿母神三度为你阖眼,令你的血脉永远鼓动,旅途永远坦然,诡计永不败露。」","argon_banner_size":"full","argon_page_background_banner_style":"transparent","argon_show_toolbar_mask":true,"argon_banner_background_url":"","argon_banner_background_color_type":"bg-gradient-danger","argon_banner_background_hide_shapes":true,"argon_enable_banner_title_typing_effect":"true","argon_banner_typing_effect_interval":"100","argon_page_background_url":"https://www.cwlgame.cn/wp-content/uploads/2024/06/wallhaven-x6yrez-scaled.jpg","argon_page_background_dark_url":"https://www.cwlgame.cn/wp-content/uploads/2024/06/min-wallhaven-83dpp1-scaled.jpg","argon_page_background_opacity":"1","argon_sidebar_banner_title":"","argon_sidebar_banner_subtitle":"--hitokoto--","argon_sidebar_auther_name":"cwl","argon_sidebar_auther_image":"https://www.cwlgame.cn/wp-content/uploads/2024/06/head.jpg","argon_sidebar_author_description":"一个游戏开发者","argon_sidebar_announcement":"欢迎来到cwl的小破站~<br>\n服务器刚崩,博客内容恢复中","argon_fab_show_settings_button":"true","argon_fab_show_darkmode_button":"true","argon_fab_show_gotocomment_button":"false","argon_seo_description":"一个记录个人技术文档的博客,归零码记","argon_seo_keywords":"博客,Unreal Engine,游戏开发,归零码记","argon_article_meta":"time|categories|views","argon_show_readingtime":"true","argon_reading_speed":"580","argon_reading_speed_en":"80","argon_reading_speed_code":"10","argon_show_thumbnail_in_banner_in_content_page":"false","argon_first_image_as_thumbnail_by_default":"false","argon_reference_list_title":"参考","argon_show_sharebtn":"false","argon_show_headindex_number":"false","argon_donate_qrcode_url":"","argon_additional_content_after_post":"","argon_related_post":"category,tag","argon_related_post_sort_orderby":"rand","argon_related_post_sort_order":"DESC","argon_related_post_limit":"10","argon_article_header_style":"article-header-style-2","argon_outdated_info_time_type":"createdtime","argon_outdated_info_days":"-1","argon_outdated_info_tip_type":"inpost","argon_outdated_info_tip_content":"本文最后更新于%modify_date_delta% 天前,其中的信息可能已经过时,如有错误请发送邮件到big_fw@foxmail.com","argon_archives_timeline_show_month":"true","argon_archives_timeline_url":"/archives","argon_footer_html":"<style>\n/* 核心样式 */\n.github-badge {\ndisplay: inline-block;\nborder-radius: 4px;\ntext-shadow: none;\nfont-size: 13.1px;\ncolor: #fff;\nline-height: 15px;\nmargin-bottom: 5px;\nfont-family: \"Open Sans\", sans-serif;\n}\n.github-badge .badge-subject {\ndisplay: inline-block;\nbackground-color: #4d4d4d;\npadding: 4px 4px 4px 6px;\nborder-top-left-radius: 4px;\nborder-bottom-left-radius: 4px;\nfont-family: \"Open Sans\", sans-serif;\n}\n.github-badge .badge-value {\ndisplay: inline-block;\npadding: 4px 6px 4px 4px;\nborder-top-right-radius: 4px;\nborder-bottom-right-radius: 4px;\nfont-family: \"Open Sans\", sans-serif;\n}\n.github-badge-big {\ndisplay: inline-block;\nborder-radius: 6px;\ntext-shadow: none;\nfont-size: 14.1px;\ncolor: #fff;\nline-height: 18px;\nmargin-bottom: 7px;\n}\n.github-badge-big .badge-subject {\ndisplay: inline-block;\nbackground-color: #4d4d4d;\npadding: 4px 4px 4px 6px;\nborder-top-left-radius: 4px;\nborder-bottom-left-radius: 4px;\n}\n.github-badge-big .badge-value {\ndisplay: inline-block;\npadding: 4px 6px 4px 4px;\nborder-top-right-radius: 4px;\nborder-bottom-right-radius: 4px;\n}\n.bg-orange {\nbackground-color: #ec8a64 !important;\n}\n.bg-red {\nbackground-color: #cb7574 !important;\n}\n.bg-apricots {\nbackground-color: #f7c280 !important;\n}\n.bg-casein {\nbackground-color: #dfe291 !important;\n}\n.bg-shallots {\nbackground-color: #97c3c6 !important;\n}\n.bg-ogling {\nbackground-color: #95c7e0 !important;\n}\n.bg-haze {\nbackground-color: #9aaec7 !important;\n}\n.bg-mountain-terrier {\nbackground-color: #99a5cd !important;\n}\n</style>\n \n<div class=\"github-badge-big\">\n<span class=\"badge-subject\"><i class=\"fa fa-id-card\"></i> 备案号 </span\n><span class=\"badge-value bg-orange\">\n<a href=\"https://beian.miit.gov.cn/\" target=\"_blank\" one-link-mark=\"yes\"\n>闽ICP备2024029622号-1</a>\n|\n<a\nhref=\"http://www.beian.gov.cn/portal/registerSystemInfo?recordcode= 44010602012333\"\ntarget=\"_blank\"\none-link-mark=\"yes\"\n>粤公网安备44010602012333号</a\n></span\n>\n</div>\n\n\n<div class=\"github-badge-big\">\n<span class=\"badge-subject\">Copyright </span\n><span class=\"badge-value bg-red\">\n2023-现在\n<i class=\"fa fa-copyright\"></i> CWL</span\n>\n</script>\n</div>\n<div class=\"github-badge-big\">\n<span class=\"badge-subject\"><i class=\"fa fa-clock-o\"></i> Running Time</span\n><span class=\"badge-value bg-apricots\"\n><span id=\"blog_running_days\" class=\"odometer odometer-auto-theme\"></span>\ndays\n<span id=\"blog_running_hours\" class=\"odometer odometer-auto-theme\"></span> H\n<span id=\"blog_running_mins\" class=\"odometer odometer-auto-theme\"></span> M\n<span id=\"blog_running_secs\" class=\"odometer odometer-auto-theme\"></span>\nS</span\n>\n <script no-pjax=\"\">\nvar blog_running_days = document.getElementById(\"blog_running_days\");\nvar blog_running_hours = document.getElementById(\"blog_running_hours\");\nvar blog_running_mins = document.getElementById(\"blog_running_mins\");\nvar blog_running_secs = document.getElementById(\"blog_running_secs\");\nfunction refresh_blog_running_time() {\nvar time = new Date() - new Date(2023, 11, 30, 0, 0, 0);\nvar d = parseInt(time / 24 / 60 / 60 / 1000);\nvar h = parseInt((time % (24 * 60 * 60 * 1000)) / 60 / 60 / 1000);\nvar m = parseInt((time % (60 * 60 * 1000)) / 60 / 1000);\nvar s = parseInt((time % (60 * 1000)) / 1000);\nblog_running_days.innerHTML = d;\nblog_running_hours.innerHTML = h;\nblog_running_mins.innerHTML = m;\nblog_running_secs.innerHTML = s;\n}\nrefresh_blog_running_time();\nif (typeof bottomTimeIntervalHasSet == \"undefined\") {\nvar bottomTimeIntervalHasSet = true;\nsetInterval(function () {\nrefresh_blog_running_time();\n}, 500);\n}\n</script>\n","argon_enable_code_highlight":"true","argon_code_theme":"onedark","argon_code_highlight_hide_linenumber":"false","argon_code_highlight_break_line":"false","argon_code_highlight_transparent_linenumber":"false","argon_math_render":"none","argon_mathjax_cdn_url":"//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js","argon_mathjax_v2_cdn_url":"//cdn.jsdelivr.net/npm/mathjax@2.7.5/MathJax.js?config=TeX-AMS_HTML","argon_katex_cdn_url":"//cdn.jsdelivr.net/npm/katex@0.11.1/dist/","argon_enable_lazyload":"true","argon_lazyload_threshold":"800","argon_lazyload_effect":"fadeIn","argon_lazyload_loading_style":"1","argon_enable_fancybox":"true","argon_enable_zoomify":"false","argon_zoomify_duration":"200","argon_zoomify_easing":"cubic-bezier(0.4,0,0,1)","argon_zoomify_scale":"0.9","argon_enable_pangu":"article","argon_custom_html_head":"<!--滚动模糊--><script>\nwindow.addEventListener(\"scroll\", function (e) {\n if (window.scrollY > window.innerHeight * 0.3) {\n document.querySelector(\"#content\").classList.add(\"scrolled\");\n } else {\n document.querySelector(\"#content\").classList.remove(\"scrolled\");\n }\n});</script>\n<style>\n#content.scrolled::before {\n filter: blur(13px);\n transform: scale(1.02);\n}\n#content::before {\n transition: filter .3s ease, transform .3s ease !important;\n filter: blur(0px);\n transform: scale(1.02);\n}</style>","argon_custom_html_foot":"<link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css\">\n<script src=\"https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js\"></script>\n<script src=\"https://cdn.jsdelivr.net/npm/meting@2.0.1/dist/Meting.min.js\"></script>\n \n<meting-js \n server=\"netease\" \n type=\"playlist\" \n id=\"9108810331\"\n fixed=\"true\" \n mini=\"true\"\n order=\"list\"\n loop=\"all\"\n preload=\"auto\"\n list-folded=\"true\"\n lrc-type=\"0\"\n>\n</meting-js>\n","argon_enable_smoothscroll_type":"1_pulse","argon_enable_into_article_animation":"true","argon_disable_pjax_animation":"false","argon_comment_pagination_type":"page","argon_comment_emotion_keyboard":"true","argon_hide_name_email_site_input":"false","argon_comment_need_captcha":"false","argon_get_captcha_by_ajax":"false","argon_comment_allow_markdown":"true","argon_comment_allow_editing":"true","argon_comment_allow_privatemode":"true","argon_comment_allow_mailnotice":"true","argon_comment_mailnotice_checkbox_checked":true,"argon_comment_enable_qq_avatar":"true","argon_comment_avatar_vcenter":"false","argon_who_can_visit_comment_edit_history":"commentsender","argon_enable_comment_pinning":"true","argon_enable_comment_upvote":"true","argon_comment_ua":"platform,browser","argon_show_comment_parent_info":"true","argon_fold_long_comments":"true","argon_gravatar_cdn":"dn-qiniu-avatar.qbox.me/avatar/","argon_text_gravatar":"true","argon_enable_search_filters":"true","argon_search_filters_type":"*post,*page,shuoshuo","argon_pjax_disabled":"false","argon_hide_categories":"","argon_enable_login_css":"true","argon_home_show_shuoshuo":"false","argon_fold_long_shuoshuo":"true","argon_enable_timezone_fix":"false","argon_hide_shortcode_in_preview":"true","argon_trim_words_count":"200","argon_enable_mobile_scale":"false","argon_disable_googlefont":"false","argon_disable_codeblock_style":"false","argon_update_source":"github","argon_hide_footer_author":"true"}
额外的CSS
/* 白云效果 */
.banner-title::before {
content: '';
position: absolute;
top: 0;
left: 50%;
bottom: 0;
right: 0;
transform:translatex(-50%);
max-width:500px;
z-index: -100;
background:white;
filter: blur(30px);
opacity: 0.5;
}
/* 标题加粗 */
.banner-title .banner-title-inner{
font-size: 35px;
position:relative;
background:inherit;
}
.banner-title{
position: absolute;
background: #FFF;
background-size:200%;
animation: ColdLight 3s linear infinite;
color:transparent !important;
-webkit-background-clip: text;
font-weight: bold; /* 添加字体加粗属性 */
}
/* 副标题彩虹效果 */
.banner-subtitle{
font-size: 20px;
-webkit-text-fill-color: transparent;
background: #FFF;
-webkit-background-clip: text;
}
/* 作者名称 */
#leftbar_overview_author_name {
margin-top: 15px;
font-size: 18px;align-content;
color:#FFA500;
/* color:#FA92B5; */
}
/* 简介 */
#leftbar_overview_author_description {
font-size: 14px;
margin-top: -4px;
opacity: 0.8;
color:#7E79E2;
}
/*站点概览分隔线颜色修改*/
.site-state-item{
border-left: 1px solid #aaa;
}
.site-friend-links-title {
border-top: 1px dotted #aaa;
}
#leftbar_tab_tools ul li {
padding-top: 3px;
padding-bottom: 3px;
border-bottom:none;
}
html.darkmode #leftbar_tab_tools ul li {
border-bottom:none;
}
图片压缩
# encoding=utf-8
import cv2
def compress_image(input_path, output_path, quality):
image = cv2.imread(input_path)
cv2.imwrite(output_path, image, [int(cv2.IMWRITE_JPEG_QUALITY), quality])
def LoadImgAndResize(szImgUrl):
# png图片转jpg
if szImgUrl.endswith('.png'):
img = cv2.imread(szImgUrl)
szImgUrl = szImgUrl.replace('.png', '.jpg')
cv2.imwrite(szImgUrl, img, [int(cv2.IMWRITE_JPEG_QUALITY), 100])
# 压缩图片
compress_image(szImgUrl, "min-{}".format(szImgUrl), 20)
def main():
LoadImgAndResize("wallhaven-x6yrez.jpg")
if __name__ == '__main__':
main()
上传媒体库之前,我一般会把图片用opencv 有损的压缩一下。
把py文件和要压缩的图片在同一目录,然后在代码里面填一下图片名字
语雀笔记导入WP
语雀的文档导出md后,图片链接连的是语雀的。直接粘贴到wp图片会挂。
所以我写了个脚本
把脚本和导出的md放在同一目录。每个md需要改一下 IMG_TAG。IP自己看着办。
会下载图片到本地img目录,并压缩,并按IMG_TAG重命名好。同时生成新md文件。把md和图片上传即完成一篇文章的导入
# encoding=utf-8
import os
import sys
import requests
import datetime
# from PIL import Image # pip install pillow
import cv2 # pip install opencv-python
IMG_TAG = "ue_input"
IP = "www.cwlgame.cn"
def LoadMarkdownCurDir():
# 获取当前目录下的所有markdown文件
for _, _, listFiles in os.walk('.'):
for szFile in listFiles:
if szFile.endswith('.md'):
return szFile
return None
def compress_image(input_path, output_path, quality):
image = cv2.imread(input_path)
cv2.imwrite(output_path, image, [int(cv2.IMWRITE_JPEG_QUALITY), quality])
def main():
# python Blog.py gas_doc
# [1] 获取参数
szImgSign = IMG_TAG
print('img sign: ' + szImgSign)
# [2] 获取当前目录下的markdown文件
szMDFile = LoadMarkdownCurDir()
if szMDFile is None:
print('No markdown file found!')
return
print('markdown file: ' + szMDFile)
szContent = ''
with open(szMDFile, 'r', encoding='utf-8') as f:
szContent = f.read()
szContent = szContent.replace("
", "\n")
with open(szMDFile, 'w', encoding='utf-8') as f:
f.write(szContent)
# [3] 创建一个img文件夹,如果有则不创建
if not os.path.exists('img'):
os.mkdir('img')
# [4] 读取markdown文件,获取所有图片链接
listImg = []
with open(szMDFile, 'r', encoding='utf-8') as f:
for szLine in f.readlines():
if szLine.startswith('!['):
listImg.append(szLine)
# [5] 将所有图片链接中的图片下载到img文件夹中
print('Total img: ' + str(len(listImg)))
for nIndex, szImg in enumerate(listImg):
szImgUrl = szImg.split('(')[1].split(')')[0]
szImgName = "blog_{}_{}.jpg".format(szImgSign, nIndex)
if os.path.exists('img/' + szImgName):
print('({}/{})Skip img: {}'.format(nIndex + 1, len(listImg), szImgName))
continue
# 下载图片
res = requests.get(szImgUrl)
with open('img/' + szImgName, 'wb') as f:
f.write(res.content)
# 压缩图片
compress_image('img/' + szImgName, 'img/' + szImgName, 50)
# 打印进度
print('({}/{})Download img: {}'.format(nIndex + 1, len(listImg), szImgName))
# [6] 将所有图片链接替换为本地图片链接
NowData = datetime.datetime.now()
szYear = NowData.strftime('%Y')
szMonth = NowData.strftime('%m')
# szFormat = 'http://{}/wp-content/uploads/{}/{}/{}'.format(szIpAndPort, szYear, szMonth, '{}')
listNewImg = []
for nIndex, szImg in enumerate(listImg):
szImgName = "blog_{}_{}.jpg".format(szImgSign, nIndex)
szTarget = 'http://{}/wp-content/uploads/{}/{}/{}'.format(IP, szYear, szMonth, szImgName)
listNewImg.append('\n'.format(szTarget))
# [7] 将markdown文件中的图片链接替换为listNewImg中的图片链接
with open(szMDFile, 'r', encoding='utf-8') as f:
szContent = f.read()
for szImg in listImg:
szContent = szContent.replace(szImg, listNewImg[0])
listNewImg.pop(0)
with open("new" + szMDFile, 'w', encoding='utf-8') as f:
f.write(szContent)
if __name__ == '__main__':
main()
自动上传文章到WP
使用 wordpress_xmlrpc 把导出的语雀笔记一键上传到WP博客
需要把当前脚本放在某个文件夹,当前目录创建一个upload目录。里面的md都会被自动上传。并且里面的图片会被自动下载,重命名压缩,然后上床。
可能需要改下 RANDOM_IMAGE_KEY 和 QUALITY
代码也不多自己看吧
# encoding=utf-8
import os
import datetime
import cv2
import requests
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import NewPost
from wordpress_xmlrpc.methods.media import UploadFile
from wordpress_xmlrpc import xmlrpc_client
WP_URL = 'http://www.cwlgame.cn:8090/xmlrpc.php'
URL = 'http://www.cwlgame.cn'
RANDOM_IMAGE_KEY = "yhgfd"
QUALITY = 50
with open("wp_key.txt", "r") as f:
WP_USERNAME, WP_PASSWORD = [sz.strip() for sz in f.readlines()]
# print(f"username: {WP_USERNAME}, password: {WP_PASSWORD}")
def TestAddMD():
ClientObj = Client(WP_URL, WP_USERNAME, WP_PASSWORD)
PostObj = WordPressPost()
PostObj.title = 'Python Test'
PostObj.content = \
"""
# 测试Python提交Markdown文件
这是一个测试文件,用于测试Python提交Markdown文件到WordPress博客。
## 代码
```python
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import NewPost
```
"""
PostObj.post_status = 'publish'
PostObj = NewPost(PostObj)
szPostID = ClientObj.call(PostObj)
print(f"Succeed to add post, post id: {szPostID}")
def TestAddImage():
ClientObj = Client(WP_URL, WP_USERNAME, WP_PASSWORD)
# prepare metadata
dictData = {
'name': 'picture.jpg',
'type': 'image/jpeg', # mimetype
}
# read the binary file and let the XMLRPC library encode it into base64
with open('test.png', 'rb') as img:
dictData['bits'] = xmlrpc_client.Binary(img.read())
response = ClientObj.call(UploadFile(dictData))
print(f"Image uploaded, id: {response['id']} {response['file']}")
# 最后文件为 https://www.cwlgame.cn/wp-content/uploads/2024/06/picture.jpg
g_ImageIndex = 0
def GetImageIndex():
global g_ImageIndex
g_ImageIndex += 1
return g_ImageIndex
def CompressImage(input_path, output_path, quality):
image = cv2.imread(input_path)
cv2.imwrite(output_path, image, [int(cv2.IMWRITE_JPEG_QUALITY), quality])
def TryParseImage(szLine):
listResult = []
# 截取所有 ![]() 的内容, 中括号里面有内容
nIndex = 0
while nIndex < len(szLine):
nIndex = szLine.find('![', nIndex)
if nIndex == -1:
break
nIndexEnd = szLine.find(')', nIndex)
if nIndexEnd == -1:
break
listResult.append(szLine[nIndex:nIndexEnd + 1])
nIndex = nIndexEnd + 1
return listResult
class MarkdownParser(object):
def __init__(self, szFilePath, szFileName):
self.m_szContent = None
self.m_szFilePath = szFilePath
self.m_szFileName = szFileName
self.m_listImageWaitCommit = []
self.m_listSourceImage = []
def Init(self):
with open(self.m_szFilePath, 'r', encoding='utf-8') as _f:
self.m_szContent = _f.read()
self.m_szContent = self.m_szContent.replace("<br />", "\n")
if not self.m_szContent:
raise ValueError(f"Failed to read markdown file: {self.m_szFilePath}")
if not os.path.exists('img'):
os.mkdir('img')
self.DownloadImage()
self.ReplaceImage()
def DownloadImage(self):
listLines = self.m_szContent.split('\n')
listImg = []
for szLine in listLines:
listImg.extend(TryParseImage(szLine))
print(f"File:{self.m_szFileName} Total img: {len(listImg)}")
for nIndex, szImg in enumerate(listImg):
nNameIndex = GetImageIndex()
szImgUrl = szImg.split('(')[1].split(')')[0]
szImgName = "blog_{}_{}.jpg".format(RANDOM_IMAGE_KEY, nNameIndex)
if os.path.exists('img/' + szImgName):
print(f'File:{self.m_szFileName} ({nIndex + 1}/{len(listImg)})Skip img: {szImgName}')
self.m_listImageWaitCommit.append(f"./img/{szImgName}")
continue
# 下载图片
res = requests.get(szImgUrl)
self.m_listSourceImage.append(szImgUrl)
with open('img/' + szImgName, 'wb') as _f:
_f.write(res.content)
# 压缩图片
CompressImage('img/' + szImgName, 'img/' + szImgName, QUALITY)
print(f'File:{self.m_szFileName} ({nIndex + 1}/{len(listImg)})Download img: {szImgName}')
self.m_listImageWaitCommit.append(f"./img/{szImgName}")
def ReplaceImage(self):
NowData = datetime.datetime.now()
szYear = NowData.strftime('%Y')
szMonth = NowData.strftime('%m')
listNewImg = []
for szImgPath in self.m_listImageWaitCommit:
szImgName = szImgPath.split('/')[-1]
listNewImg.append(f"{URL}/wp-content/uploads/{szYear}/{szMonth}/{szImgName}")
for szSource, szTarget in zip(self.m_listSourceImage, listNewImg):
self.m_szContent = self.m_szContent.replace(szSource, szTarget)
with open(self.m_szFilePath, 'w', encoding='utf-8') as _f:
_f.write(self.m_szContent)
class AutoWPCommit(object):
def __init__(self):
self.m_WPClient = Client(WP_URL, WP_USERNAME, WP_PASSWORD)
self.m_listMarkdown = []
def LoadMarkdownWaitCommit(self):
for _, _, listFiles in os.walk('./upload'):
for szFile in listFiles:
if szFile.endswith('.md'):
szPath = os.path.join('./upload', szFile)
MD = MarkdownParser(szPath, szFile)
MD.Init()
self.m_listMarkdown.append(MD)
return len(self.m_listMarkdown) > 0
def CommitMarkdown(self, MD):
PostObj = WordPressPost()
PostObj.title = MD.m_szFileName.replace('.md', '')
PostObj.content = MD.m_szContent
PostObj.post_status = 'publish'
PostObj = NewPost(PostObj)
szPostID = self.m_WPClient.call(PostObj)
print(f"Succeed to add post, post id: {szPostID}")
for szImgPath in MD.m_listImageWaitCommit:
dictData = {
'name': szImgPath.split('/')[-1],
'type': 'image/jpeg',
}
with open(szImgPath, 'rb') as img:
dictData['bits'] = xmlrpc_client.Binary(img.read())
response = self.m_WPClient.call(UploadFile(dictData))
print(f"Image uploaded, id: {response['id']} {response['file']}")
def Run(self):
if not self.LoadMarkdownWaitCommit():
print('No markdown file found!')
return
print(f"Total markdown file: {len(self.m_listMarkdown)}")
for MD in self.m_listMarkdown:
print(f"Commit markdown: {MD.m_szFileName}")
self.CommitMarkdown(MD)
def RunAutoWPCommit():
App = AutoWPCommit()
App.Run()
def main():
RunAutoWPCommit()
# szTest = " aaa "
# print(TryParseImage(szTest))
if __name__ == '__main__':
main()