├── Screenshot.png ├── Screenshot2.png ├── Selection_002.png ├── README.md └── pinterest_gallery.py /Screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzhaninan/Gallery-With-Pinterest-Pins/HEAD/Screenshot.png -------------------------------------------------------------------------------- /Screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzhaninan/Gallery-With-Pinterest-Pins/HEAD/Screenshot2.png -------------------------------------------------------------------------------- /Selection_002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzhaninan/Gallery-With-Pinterest-Pins/HEAD/Selection_002.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Gallery-With-Pinterest-Pins 2 | Gallery With Pinterest Pins 3 | 4 | ##Installation and Run 5 | ``` 6 | $ git clone https://github.com/oguzhaninan/Gallery-With-Pinterest-Pins.git ~/Gallery-Pinterest 7 | $ cd ~/Gallery-Pinterest 8 | $ python3 pinterest_gallery.py -i 1 -d 0 -l 10 -o example 9 | ``` 10 | 11 | ### Requirements 12 | 13 | Need access token pinterest 14 | 15 | Libraries: 16 | 17 | 1. Requests 18 | 2. Argparse 19 | 20 | 21 | ![View Screen Shot](https://github.com/oguzhaninan/Gallery-With-Pinterest-Pins/blob/master/Selection_002.png) 22 | 23 | ![View Screen Shot](https://github.com/oguzhaninan/Gallery-With-Pinterest-Pins/blob/master/Screenshot2.png) 24 | 25 | ![View Screen Shot](https://github.com/oguzhaninan/Gallery-With-Pinterest-Pins/blob/master/Screenshot.png) 26 | 27 | -------------------------------------------------------------------------------- /pinterest_gallery.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | import json 3 | import requests 4 | import sys 5 | import argparse 6 | import os 7 | 8 | class colors: 9 | OKGREEN = '\033[92m' 10 | WARNING = '\033[93m' 11 | ENDC = '\033[0m' 12 | 13 | parser = argparse.ArgumentParser() 14 | parser.add_argument("-d", dest = "d", help="Description [0|1]", default=0, type=int) 15 | parser.add_argument("-i", dest = "i", help="Images Download [0|1]", default=0, type=int) 16 | parser.add_argument("-l", dest = "l", help="Number of pins", default=10, type=int) 17 | parser.add_argument("-o", dest = "o", help="Html file name", default="index", type=str) 18 | args = parser.parse_args() 19 | 20 | token = "" 21 | 22 | username = str(input("User Name: ")) 23 | board = str(input("Board Name: ")) 24 | 25 | url = "https://api.pinterest.com/v1/boards/%s/%s/pins/" % (username,board) 26 | 27 | response = requests.get(url,params={"access_token": token, "limit": args.l, "fields":"note,image"}) 28 | data = json.loads(response.text) 29 | 30 | html = """ 31 | 32 | 33 | 105 | 106 | 107 |
108 |
109 | {} 110 |
111 |
112 | 113 | 114 | """ 115 | 116 | 117 | images, c = "", 0 118 | if args.i == 1: 119 | for im in data["data"]: 120 | link = im["image"]["original"]["url"] 121 | fname = "image{}.jpg".format(c) 122 | if not os.path.exists(args.o): 123 | os.makedirs(args.o) 124 | with open(args.o+"/"+fname, "wb") as f: 125 | res = requests.get(link,stream=True) 126 | f.write(res.content) 127 | c+=1 128 | print("%s %s" % (colors.OKGREEN + "Downloading... " + colors.ENDC, colors.WARNING + fname + colors.ENDC)) 129 | 130 | for i in range(0,c): 131 | images += """ 132 |
133 | 134 | {1} 135 |
136 | """.format("image"+str(i)+".jpg","") 137 | else: 138 | for dat in data["data"]: 139 | img = str(dat["image"]["original"]["url"]) 140 | desc = "

"+str(dat["note"].encode("utf8"))+"

" if args.d == 0 else "" 141 | images += """ 142 |
143 | 144 | {1} 145 |
146 | """.format(img, desc) 147 | 148 | html = html.format(images) 149 | 150 | path = "%s/%s.html" % (args.o,args.o) 151 | with open(path, "wb") as f: 152 | f.write(html.encode("utf-16")) 153 | 154 | print("\nGallery created with %s pictures" % len(data["data"])) 155 | --------------------------------------------------------------------------------