Skip to content

Commit

Permalink
address change in pinterest api that prevented loading the pin info (#98
Browse files Browse the repository at this point in the history
)

Co-authored-by: b.stoilov <[email protected]>
  • Loading branch information
bstoilov and b.stoilov authored Nov 27, 2020
1 parent 52feece commit 358f90c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions py3pin/Pinterest.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,12 @@ def load_pin(self, pin_id):
scripts = soup.findAll('script')
pin_data = {}
for s in scripts:
if 'pins' in s.text and 'aggregated_pin_data' in s.text:
pin_data = json.loads(s.text)
return pin_data['pins'][str(pin_id)]
if 'id' in s.attrs and s.attrs['id'] == 'initial-state':
pinJsonData = json.loads(s.contents[0])['resources']['data']['PinResource']
pinJsonData = pinJsonData[list(pinJsonData.keys())[0]]['data']
return pinJsonData

raise Exception("Pin data not found. Probably pintereset chagned their API")

def get_comments(self, pin_id, page_size=50):
"""
Expand Down

0 comments on commit 358f90c

Please sign in to comment.