Skip to content

Commit

Permalink
Update upload.py
Browse files Browse the repository at this point in the history
+ Extract wp_xmlrpc as an internal function of m2w module
+ Update upload.py
  • Loading branch information
huangwb8 committed Dec 2, 2022
1 parent 05bc7de commit 96bd6f1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
19 changes: 19 additions & 0 deletions m2w/wp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

import sys
from wordpress_xmlrpc import Client

def wp_xmlrpc(domain,username, password):
"""
错误控制相关的Client函数
:param domain: 网站域名
:param username: 帐号
:param password: 该帐号的密码
"""
try:
client = Client(domain + '/xmlrpc.php', username, password) # 客户端
print('SUCCESS to connect to your WordPress website: ' + domain)
return client
except Exception as e:
print('FAILED to connect to your WordPress website: ' + str(e))
# 正常退出
sys.exit(0)
15 changes: 2 additions & 13 deletions update.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from wordpress_xmlrpc.methods.posts import GetPosts, EditPost
import m2w.md5
import m2w.json2
import m2w.wp


####===============================软件绝对路径===============================####
Expand Down Expand Up @@ -110,18 +111,6 @@ def get_file_list(file_path):
# print(dir_list)
return dir_list

def wp_xmlrpc(domain,username, password):
"""
错误控制相关的Client函数
"""
try:
client = Client(domain + '/xmlrpc.php', username, password) # 客户端
print('SUCCESS to connect to your WordPress website: ' + domain)
return client
except Exception as e:
print('FAILED to connect to your WordPress website: ' + str(e))
# 正常退出
sys.exit(0)

if __name__ == '__main__':

Expand All @@ -131,7 +120,7 @@ def wp_xmlrpc(domain,username, password):
# sys.exit(1)

# 访问WordPress xmlrpc.php
client = wp_xmlrpc(domain,username, password)
client = m2w.wp.wp_xmlrpc(domain,username, password)

# 新旧文件对比
if os.path.isfile(path_legacy_json):
Expand Down
8 changes: 5 additions & 3 deletions upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from wordpress_xmlrpc.methods.posts import NewPost
import m2w.md5
import m2w.json2
import m2w.wp

####===============================软件绝对路径===============================####

Expand Down Expand Up @@ -126,13 +127,14 @@ def get_filepaths(path):
if __name__ == '__main__':

# Start Work
print('----------------------------------------------START----------------------------------------------')
# print('----------------------------------------------START----------------------------------------------')
filepaths = get_filepaths(path)
if filepaths is None:
print('FAILURE: wrong path')
sys.exit(1)

client = Client(domain + '/xmlrpc.php', username, password) # 客户端
# client = Client(domain + '/xmlrpc.php', username, password) # 客户端
client = m2w.wp.wp_xmlrpc(domain, username, password)

md_cnt = 0
all_cnt = len(filepaths)
Expand All @@ -150,7 +152,7 @@ def get_filepaths(path):
else:
failpaths.append(filepath)
print('Process number: %d/%d WARNING: Can\'t push "%s" because it\'s not Markdown file.' % (process_number, all_cnt, filename))
print('-----------------------------------------------END-----------------------------------------------')
# print('-----------------------------------------------END-----------------------------------------------')
print('SUCCESS: %d files have been pushed to your WordPress.' % md_cnt)

if len(failpaths) > 0:
Expand Down

0 comments on commit 96bd6f1

Please sign in to comment.