Skip to content

Instantly share code, notes, and snippets.

@paxti
Last active February 11, 2016 17:11
Show Gist options
  • Save paxti/39e936d37c629f92cbb2 to your computer and use it in GitHub Desktop.
Save paxti/39e936d37c629f92cbb2 to your computer and use it in GitHub Desktop.
Upload all images in the folder to Pintrest
import glob
import os
import base64
import requests
from PIL import Image
import io
pintrest_api = 'https://api.pinterest.com/v1/pins/'
access_token = ""
path_to_files = 'C:/Pintrest/*.jp*'
board = ''
notes = 'draft'
for path in glob.glob(path_to_files):
print("=============================================")
image = Image.open(path)
image_buffer = io.BytesIO()
image.save(image_buffer, format='JPEG')
imgStr = base64.b64encode(image_buffer.getvalue())
img = imgStr.decode('utf-8')
data = img.replace("\n", "")
output = "data:image/jpg;base64," + data
print("Converted")
#output=open("C:/Pintrest/test.txt",'w')
#output.write(output_)
#output.close()
#break
#
#output = "data:image/jpg;base64," + data
#print(output)
auth = {'access_token': access_token}
payload = {'board': board,'note': notes, 'image_base64': output}
r = requests.post(pintrest_api, params=auth, data=payload)
print(r.url)
print(r.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment