Python Wordpress Xmlrpc 'Post_tags' not separated by comma

Viewed 91

In my task to learn python I decided to start a project that could help me in some way, by automating manual tasks that I do. I started coding a web scraper using beautifulsoup that would pull content from another website and then post it to a wordpress blog of my own. The data pulled includes Post title, tags, images.

I managed to get most of it to work (my code is probably terrible) , but ran into a snag when it came to the tags.

#Getting tags
def get_tags():

    for url in modified_lines:
        SoupRequest(url)
        global tags
        global cats
        cats = []
        tags = [tag['content'] for tag in soup("meta", attrs={"property": "article:tag"})]
        categories = soup.find('span', attrs={'class': 'cat-meta-color'}).findAll('a',limit=limiter)
        allcats = [cat.text for cat in categories]
        for singlecat in allcats:
            cats.append(singlecat)
        tags.extend(cats)
        strtag = tags
        with io.open('tags.txt', 'a', encoding='utf8') as tagfile:
            posttag ="".join(str(strtag))

            tagfile.write(posttag[1:-1].replace("'","") + '\n')
get_tags()
with open('tags.txt') as t:
    taglists = list(t.readlines())

#Posting to wordpress


def post_to_wordpress(title, allvideoLinks,alltags,images):
    filepaths = images.strip()
    filename = filepaths.split('/')[-1]
    data = {
        'name': filename,
        'type': mimetypes.MimeTypes().guess_type(filename)[0],  # mimetype
    }
    with open(filepaths, 'rb') as img:
        data['bits'] = xmlrpc_client.Binary(img.read())


    response = wp.call(media.UploadFile(data))
    attachment_id = response['id']


    wp.call(GetPosts())

    title = str(title)
    content = allvideoLinks
    post = WordPressPost()
    post.title = title
    post.thumbnail = attachment_id
    post.content = content
    post.terms_names = {
        'post_tag': [alltags],
        'category': ['Youtube'],
                      }


    post.post_type = "post"
    post.post_status = 'publish'
    post.id = wp.call(NewPost(post))
    wp.call(posts.EditPost(post.id, post))


for l,y,t,f in zip(scrubbed,scrummed,taglists,images):
    post_to_wordpress(l,y,t,f)
    time.sleep(3)

While the tags do post, they seem to come attached as a string instead of individual list items , Example enter image description here

Would appreciate any guidance on how to solve this issue

0 Answers
Related