Skip to content

Commit 0a3a362

Browse files
authored
Add "getDescription" and "getPhotos" methods
"getDescription" obtains the item description as is or translated, and returns it as string. "getPhotos" obtains the links for the full size version of the item photos and returns them in a set. Both return "None" in case of exception.
1 parent 0df59f3 commit 0a3a362

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/pyVinted/items/item.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from datetime import datetime, timezone
22
from pyVinted.requester import requester
3-
3+
from urllib.parse import urlparse
4+
from pyVinted.settings import Urls
45

56
class Item:
67
def __init__(self, data):
@@ -31,3 +32,25 @@ def isNewItem(self, minutes=3):
3132
delta = datetime.now(timezone.utc) - self.created_at_ts
3233
return delta.total_seconds() < minutes * 60
3334

35+
def getDescription(self, translated=True):
36+
locale = urlparse(self.url).netloc
37+
requester.setLocale(locale)
38+
try:
39+
response = requester.get(url=f"https://{locale}{Urls.VINTED_API_URL}/items/{self.id}/plugins/translatable?localize={translated}")
40+
response = response.json()
41+
return response["plugins"][1]["data"]["description"]
42+
except:
43+
return None
44+
45+
def getPhotos(self):
46+
locale = urlparse(self.url).netloc
47+
requester.setLocale(locale)
48+
try:
49+
response = requester.get(url=f"https://{locale}{Urls.VINTED_API_URL}/items/{self.id}")
50+
response = response.json()
51+
urls = set()
52+
for photo in response["item"]["photos"]:
53+
urls.add(photo["full_size_url"])
54+
return urls
55+
except:
56+
return None

0 commit comments

Comments
 (0)