#!/usr/bin/env python
import glob
import os
import markdown
import pelican
import requests
import pprint
import json
import html

from peliword_config import pelican_blog_dir, wp_client_secret

wp_api_base = 'https://public-api.wordpress.com/rest/v1.1/sites/feohorg.wordpress.com'

settings = pelican.settings.read_settings()
mdr = pelican.readers.MarkdownReader(settings)

wp_posts_response = requests.get(wp_api_base + "/posts" )
wp_posts_json = wp_posts_response.text
wp_resp = json.loads(wp_posts_json)

wp_posts = wp_resp['posts']

wp_titles = [ html.unescape(wp_post['title']) for wp_post in wp_posts ]

print(wp_titles)
# pprint.pprint(wp_posts)


if not os.path.exists(pelican_blog_dir):
    print("Not a valid Pelican blog directory: {}".format(pelican_blog_dir))

glob_path = pelican_blog_dir + "/content/*.md"
for post in glob.glob(glob_path):
    mda = mdr.read(post)
    headers = mda[1]
    title = headers['title']
    if title not in wp_titles:
        print("title: {}".format(title))

@@ -121,16 +121,55 @@
 ort html
+%0Afrom pelican.utils import SafeDatetime
 %0A%0Afrom p
@@ -405,24 +405,28 @@
 ttings)%0A%0Awp_
+get_
 posts_respon
@@ -467,24 +467,28 @@
 posts%22 )%0Awp_
+get_
 posts_json =
@@ -487,24 +487,28 @@
 s_json = wp_
+get_
 posts_respon
@@ -518,16 +518,20 @@
 text%0Awp_
+get_
 resp = j
@@ -539,24 +539,28 @@
 on.loads(wp_
+get_
 posts_json)%0A
@@ -563,16 +563,20 @@
 on)%0A%0Awp_
+get_
 posts = 
@@ -578,16 +578,20 @@
 ts = wp_
+get_
 resp%5B'po
@@ -665,60 +665,19 @@
  wp_
-posts %5D%0A%0Aprint(wp_titles)%0A# pprint.pprint(wp
+get
 _posts
-)%0A
+ %5D
 %0A%0Aif
@@ -903,16 +903,24 @@
 st)%0A    
+pelican_
 headers 
@@ -936,45 +936,261 @@
     
-title = headers%5B'title'%5D%0A    if 
+pprint.pprint(pelican_headers)    %0A    pelican_tag_list = pelican_headers%5B'tags'%5D%0A    pelican_tags = %5B tag.name for tag in pelican_tag_list %5D.%0A    print(%22tags: %7B%7D%22.format(pelican_tags))%0A%0A    next%0A    pelican_body = mda%5B0%5D%0A    if pelican_headers%5B'
 title
+'%5D
  not
@@ -1219,16 +1219,24 @@
  print(%22
+Posting 
 title: %7B
@@ -1249,12 +1249,1430 @@
 mat(
+pelican_headers%5B'
 title
+'%5D
 ))%0A
+        headers = %7B 'authorization', 'Bearer %7B%7D'.format(wp_client_secret)%7D%0A%0A        test_post = %22Date: %7B%7D%5CnTitle: %7B%7D%5CnAuthor: %7B%7D%5Cntags: %7B%7D%5Cncategory: %7B%7D%5Cn%22.format(pelican_headers%5B'date'%5D,%0A                                                                                       pelican_headers%5B'title'%5D,%0A                                                                                       pelican_headers%5B'author'%5D,%0A                                                                                       pelican_headers%5B'tags'%5D,%0A                                                                                       pelican_headers%5B'category'%5D)%0A        print(test_post)%0A%0A        %0A        # wp_post_response = requests.post(wp_api_base + %22/posts/new%22, data = %7B'title': pelican_headers%5B'title'%5D,%0A        #                                                                      'author': pelican_headers%5B'author'%5D,%0A        #                                                                      'tags': pelican_headers%5B'tags'%5D,%0A        #                                                                      'date': pelican_headers%5B'date'%5D,%0A        #                                                                      'category': pelican_headers%5B'category'%5D,%0A        #                                                                      'content' : pelican_body%7D)%0A        #pprint.pprint(wp_post_response)%0A

Add parsing the tags