Skip to content

Commit

Permalink
Optimized up.py
Browse files Browse the repository at this point in the history
+ Check whether a new post has been existed in the WordPress site. If existed, the upload would be ignored.
+ Routinely update codes
  • Loading branch information
huangwb8 committed Dec 8, 2022
1 parent 3b9bd95 commit c5e7b9a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions m2w.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
####===============================m2w path

# Absolute path of m2w
path_m2w = 'E:/Github/m2w' # /@test
path_m2w = 'E:/Github/m2w/@test' # /@test

####===============================Dependency

Expand Down Expand Up @@ -41,7 +41,7 @@
print('========Website: ' + i)
client = wp_xmlrpc(domain, username, password)

# # Gather paths of brand-new and changed legacy markdown files
# Gather paths of brand-new and changed legacy markdown files
res = md_detect(path_markdown, path_legacy_json, verbose = True)
md_upload = res['new']
md_update = res['legacy']
Expand Down
30 changes: 18 additions & 12 deletions m2w/up.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,27 @@ def up(client, md_upload, md_update, post_metadata, verbose = True):
md_cnt = 0
all_cnt = len(md_upload)
process_number = 0
failpaths = [] # 存储上传失败的文件路径
failpaths = [] # Store failed uploaded markdown files
for filepath in md_upload:
process_number = process_number + 1
post = m2w.upload.make_post(filepath, post_metadata)
if post is not None:
m2w.upload.push_post(post, client)
md_cnt = md_cnt + 1
if verbose: print('Process number: %d/%d SUCCESS: Push "%s"' % (process_number, all_cnt, filepath))
else:
failpaths.append(filepath)
if verbose:
print('Process number: %d/%d WARNING: Can\'t push "%s" because it\'s not Markdown file.' % (process_number, all_cnt, filepath))
if verbose: print('SUCCESS: %d files have been pushed to your WordPress.' % md_cnt)
post_wp = m2w.update.find_post(filepath, client) # Test whether this file had been existed in the WordPress site
if post_wp is not None:
if verbose: print('Warning: This post is existed in your WordPress site. Ignore uploading!')
else:
if verbose: print('This post is exactly a new one in your WordPress site! Try uploading...')
post = m2w.upload.make_post(filepath, post_metadata) # Upload the new markdown
if post is not None:
m2w.upload.push_post(post, client)
md_cnt = md_cnt + 1
if verbose:
print('Process number: %d/%d SUCCESS: Push "%s"' % (process_number, all_cnt, filepath))
else:
failpaths.append(filepath)
if verbose:
print('Process number: %d/%d WARNING: Can\'t push "%s" because it\'s not Markdown file.' % (process_number, all_cnt, filepath))
if verbose: print('SUCCESS: %d files have been pushed to your WordPress.' % md_cnt)

if verbose:
if verbose:
if len(failpaths) > 0:
print('WARNING: %d files haven\'t been pushed to your WordPress.' % len(failpaths))
print('\nFailure to push these file paths:')
Expand Down

0 comments on commit c5e7b9a

Please sign in to comment.