Here is the setup I'd run if I were you. Note: It uses my private Pinterest class, and I'm not giving it out, so unless you hire somebody to mimic the functionality it isn't going to work for you. Also, the implementation below is
very hacky. 2/10 would not suggest replicating some of my POC coding practices.
With this code (to you, pseudo code), you would structure your blog posts to have the same tag names as the boards you'd want them pinned to. From there it's pretty easy.
Code:
#Private for now. Sorry.
import Pinterest
#pip install feedparser
import feedparser
#Your RSS url - default on wordpress for RSS 2.0 is /path/to/blog/or/site/feed/ as reflected below
rss_url = "http://mysite.com/blog/feed/"
#Pinterest account information - Note: username can be username OR email
pinterest_username = ""
pinterest_password = ""
#Open and read token.txt which contains our little access token
def loadToken():
return open("token.txt","r").read()
#Save the access token to token.txt
def saveToken(accessToken):
f = open("token.txt","w")
f.write(accessToken)
f.close()
#Make sure we're in the main function because yolo
if __name__ == "__main__":
#Instantiate a new Pinterest object
pin = Pinterest()
#Check to see if the access token is valid, otherwise login to the account
token = loadToken()
if pin.isValidToken(token):
pin.setToken(token)
else:
if pin.login(pinterest_username, pinterest_password):
#Save the token for later usage so we don't keep logging in/logging out and look suspicious
saveToken(pin.accessToken)
else:
print "Could not login to account. Reason: %s" % pin.getLastError()
exit()
#Now that we're authenticated, we need to get our boards
myBoards = pin.getMyBoards() #Store them in an array - it's also accessible as a public variable within the Pinterest object (pin.myBoards)
#Fetch your RSS feed
feed = feedparser.parse(rss_url)
#Loop through posts
for item in feed['entries']:
post_url = item['link']
description = item['description'] #probably a good idea to remove the htmlentities() stuff from here.
content = item['content'] #Go ahead and parse out any images and put them in their own variable..we'll use "post_image" as the example.
post_image = someImageParseFunction(content)
#Now we loop through our boards and see if the board name matches up with any of our categories/tags for the post
postBoard = None
for board in myBoards:
if board in item['category']:
postBoard = board['id']
if postBoard == None:
print "No boards match the tags..."
exit()
else:
if pin.pinUrl(postBoard, description, post_image, post_url):
print "We successfully posted URL: %s to board %s" % post_url, postBoard
else:
print "There was an error posting the pin. Reason: %s" % pin.getLastError()
One last time to make sure it's abundantly clear. This will not work unless you have my Pinterest python class, which isn't available to the public (nor is it for sale). Sorry again.