[pinterest] tests + fix error message
This commit is contained in:
parent
a849d8f2f7
commit
a8d716c043
@ -38,11 +38,16 @@ class PinterestPinExtractor(PinterestExtractor):
|
||||
"""Extractor for images from a single pin from pinterest.com"""
|
||||
subcategory = "pin"
|
||||
pattern = [r"(?:https?://)?(?:[^./]+\.)?pinterest\.com/pin/([^/]+)"]
|
||||
test = [("https://www.pinterest.com/pin/858146903966145189/", {
|
||||
"url": "7abf2be76bf03d452feacf6e000b040fc2706b80",
|
||||
"keyword": "e1a2ce625ece86f0b31f0ae94a3af3d72e6454b9",
|
||||
"content": "d3e24bc9f7af585e8c23b9136956bd45a4d9b947",
|
||||
})]
|
||||
test = [
|
||||
("https://www.pinterest.com/pin/858146903966145189/", {
|
||||
"url": "7abf2be76bf03d452feacf6e000b040fc2706b80",
|
||||
"keyword": "e1a2ce625ece86f0b31f0ae94a3af3d72e6454b9",
|
||||
"content": "d3e24bc9f7af585e8c23b9136956bd45a4d9b947",
|
||||
}),
|
||||
("https://www.pinterest.com/pin/858146903966145188/", {
|
||||
"exception": exception.NotFoundError,
|
||||
}),
|
||||
]
|
||||
|
||||
def __init__(self, match):
|
||||
PinterestExtractor.__init__(self)
|
||||
@ -62,11 +67,16 @@ class PinterestBoardExtractor(PinterestExtractor):
|
||||
subcategory = "board"
|
||||
directory_fmt = ["{category}", "{user}", "{board}"]
|
||||
pattern = [r"(?:https?://)?(?:[^./]+\.)?pinterest\.com/(?!pin/)([^/]+)/([^/]+)"]
|
||||
test = [("https://www.pinterest.com/g1952849/test-/", {
|
||||
"url": "705ee521630a5d613b0449d694a5345e684572a9",
|
||||
"keyword": "2815716747f84fa0a4047d29d71df8ae96a0e177",
|
||||
"content": "30897fb5d5616765bb2c9c26cb84f54499424fb4",
|
||||
})]
|
||||
test = [
|
||||
("https://www.pinterest.com/g1952849/test-/", {
|
||||
"url": "705ee521630a5d613b0449d694a5345e684572a9",
|
||||
"keyword": "2815716747f84fa0a4047d29d71df8ae96a0e177",
|
||||
"content": "30897fb5d5616765bb2c9c26cb84f54499424fb4",
|
||||
}),
|
||||
("https://www.pinterest.com/g1952848/test/", {
|
||||
"exception": exception.NotFoundError,
|
||||
}),
|
||||
]
|
||||
|
||||
def __init__(self, match):
|
||||
PinterestExtractor.__init__(self)
|
||||
@ -139,7 +149,10 @@ class PinterestAPI():
|
||||
def _parse(response):
|
||||
"""Parse an API response"""
|
||||
data = response.json()
|
||||
if "data" not in data and data.get("type") == "api":
|
||||
msg = data.get("message", "").split(maxsplit=1)[0].lower()
|
||||
if "data" not in data or data["data"] is None:
|
||||
try:
|
||||
msg = data["message"].split(maxsplit=1)[0].lower()
|
||||
except KeyError:
|
||||
msg = ""
|
||||
raise exception.NotFoundError(msg)
|
||||
return data
|
||||
|
Loading…
x
Reference in New Issue
Block a user