diff --git a/dev-documentation.md b/dev-documentation.md index 296eb212..4eae3a01 100644 --- a/dev-documentation.md +++ b/dev-documentation.md @@ -1745,3 +1745,20 @@ atcode.get_profile() | `.get_profile()` | Returns the user data in json format. | --- + +## Pinterest + +First create an object of class `Pinterest`. + +```python +from scrap_up import Pinterest + +pinterest = Pinterest() +``` + +| Methods | Details | +| --------------------------- | ------------------------------------------------------------ | +| `.get_today()` | Returns the list of today's topics | +| `.get_photo(your_url)` | Returns the link to the image (so you don't need an account) | +| `.search_pins(keyword)` | Search for pins containing a specific keyword on Pinterest | +| `.get_pin_details(pin_url)` | Fetch details about a specific pin on Pinterest | diff --git a/src/scrape_up/atcoder/atcoder.py b/src/scrape_up/atcoder/atcoder.py index cec07e25..243028e1 100644 --- a/src/scrape_up/atcoder/atcoder.py +++ b/src/scrape_up/atcoder/atcoder.py @@ -12,7 +12,7 @@ class Atcoder: | Methods | Details | | ----------------- | ---------------------------------------------------------------------------------- | | `.get_profile()` | Returns the user data in json format. | - + Response ```json { @@ -36,7 +36,6 @@ class Atcoder: ``` """ - def __init__(self, user): self.user = user diff --git a/src/scrape_up/pinterest/pinterest.py b/src/scrape_up/pinterest/pinterest.py index aab61228..dbab28b1 100644 --- a/src/scrape_up/pinterest/pinterest.py +++ b/src/scrape_up/pinterest/pinterest.py @@ -6,13 +6,13 @@ class Pinterest: """ Create an instance of `Pinterest` class. - ```python - pinterest = Pinterest() - ``` - | Methods | Details | + ```python + pinterest = Pinterest() + ``` + | Methods | Details | | ---------------------- | ------------------------------------------------------------------ | - | `.get_today()` | Returns the list of todays topics | - | `.get_photo(your url)` | Returns the link to the image (so you dont need an account) | + | `.get_today()` | Returns the list of today's topics | + | `.get_photo(your_url)` | Returns the link to the image (so you don't need an account) | | `.search_pins(keyword)`| Search for pins containing a specific keyword on Pinterest | | `.get_pin_details(pin_url)`| Fetch details about a specific pin on Pinterest | """ @@ -28,8 +28,8 @@ def get_today(self): pinterest = Pinterest() today = pinterest.get_today() ``` - Output - ```js + Output: + ```json [ { "link":"/today/best/how-to-style-a-shawl-this-winter/116286/", @@ -37,6 +37,7 @@ def get_today(self): "subtitle":"Perfect Winter Companion", "image":"https://i.pinimg.com/736x/10/46/c8/1046c8dc21138326568405a24f871e17.jpg" }, + ] ``` """ try: @@ -62,18 +63,18 @@ def get_today(self): {"link": link, "title": title, "subtitle": subtitle, "image": image} for (link, title, subtitle, image) in unique_items ] - except: + except Exception as e: return None def get_photo(self, url: str): """ - Class - `Pinterest` - Example: + Class - `Pinterest` + Example: ```python pinterestphoto = Pinterest() - photo = pinterestphoto.get_photo(your pinterest url) + photo = pinterestphoto.get_photo(your_pinterest_url) ``` - Returns: Photo Image URL | None + Returns: Photo Image URL | None """ try: page = get(url, self.config) @@ -122,12 +123,16 @@ def get_pin_details(self, pin_url: str): try: page = get(pin_url, self.config) soup = bs(page.content, "html.parser") - title = soup.find("meta", property="og:title").get("content") - description = soup.find("meta", property="og:description").get("content") - saves = soup.find("meta", property="pinterestapp:saves").get("content") - comments = soup.find("meta", property="pinterestapp:comments").get( - "content" - ) + title_meta = soup.find("meta", property="og:title") + description_meta = soup.find("meta", property="og:description") + saves_meta = soup.find("meta", property="pinterestapp:saves") + comments_meta = soup.find("meta", property="pinterestapp:comments") + + title = title_meta.get("content") if title_meta else None + description = description_meta.get("content") if description_meta else None + saves = saves_meta.get("content") if saves_meta else None + comments = comments_meta.get("content") if comments_meta else None + return { "title": title, "description": description,