From f68450553d872279559797a78019346e280c722b Mon Sep 17 00:00:00 2001 From: Priyankesh Date: Fri, 17 May 2024 16:39:17 +0530 Subject: [PATCH 1/4] #951 Added 2 new features in pinterest.py --- src/scrape_up/pinterest/pinterest.py | 49 +++++++++++++++++++--------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/src/scrape_up/pinterest/pinterest.py b/src/scrape_up/pinterest/pinterest.py index 894425e3..20c8ea4f 100644 --- a/src/scrape_up/pinterest/pinterest.py +++ b/src/scrape_up/pinterest/pinterest.py @@ -65,22 +65,31 @@ def get_today(self): return None def get_photo(self, url): - """ - Class - `Pinterest` - Example: - ```python - pinterestphoto = Pinterest() - photo = pinterestphoto.get_photo(your pinterest url) - ``` + + """ + Class - `Pinterest` + Example: + ```python + pinterestphoto = Pinterest() + photo = pinterestphoto.get_photo(your pinterest url) + ``` Returns: Photo Image URL | None """ - try: - page = requests.get(url) - soup = bs(page.content, "html.parser") - image = soup.find("img", class_="hCL") + try: + page = requests.get(url) + soup = bs(page.content, "html.parser") + image = soup.find("img", class_="hCL") + print("Image tag:", image) # Add this line + if image: return {"alt": image.get("alt"), "image": image.get("src")} - except: + else: + print("No image found") # Add this line return None + except Exception as e: + print("Error:", e) + return None + + def search_pins(self, keyword): """ @@ -119,11 +128,19 @@ def get_pin_details(self, pin_url): try: page = requests.get(pin_url) 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, "saves": saves, "comments": comments} except Exception as e: print("Error:", e) return None + From 15166922520a895a8917f08992dab53f4207a651 Mon Sep 17 00:00:00 2001 From: Priyankesh Date: Fri, 17 May 2024 21:52:40 +0530 Subject: [PATCH 2/4] #951 Added 2 new features --- src/scrape_up/pinterest/pinterest.py | 43 ++++++++++++++-------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/scrape_up/pinterest/pinterest.py b/src/scrape_up/pinterest/pinterest.py index 14ae7c64..de30e771 100644 --- a/src/scrape_up/pinterest/pinterest.py +++ b/src/scrape_up/pinterest/pinterest.py @@ -10,8 +10,8 @@ class 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 | """ @@ -27,8 +27,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/", @@ -36,6 +36,7 @@ def get_today(self): "subtitle":"Perfect Winter Companion", "image":"https://i.pinimg.com/736x/10/46/c8/1046c8dc21138326568405a24f871e17.jpg" }, + ] ``` """ try: @@ -61,18 +62,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): """ - 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 = requests.get(url) @@ -121,17 +122,17 @@ def get_pin_details(self, pin_url): try: page = requests.get(pin_url) 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" - ) - return { - "title": title, - "description": description, - "saves": saves, - "comments": comments, - } + + 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, "saves": saves, "comments": comments} except Exception as e: return None From 08d6350e24169ff6904ab059764a29fcf745fd85 Mon Sep 17 00:00:00 2001 From: Nikhil Raj Date: Fri, 17 May 2024 22:24:36 +0530 Subject: [PATCH 3/4] Check --- src/scrape_up/atcoder/atcoder.py | 3 +-- src/scrape_up/pinterest/pinterest.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) 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 f376e745..45d06639 100644 --- a/src/scrape_up/pinterest/pinterest.py +++ b/src/scrape_up/pinterest/pinterest.py @@ -126,13 +126,17 @@ def get_pin_details(self, pin_url): 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, "saves": saves, "comments": comments} + + return { + "title": title, + "description": description, + "saves": saves, + "comments": comments, + } except Exception as e: return None - From 0d92a289b3586dd9aa4135248c2a56e8b0c5e049 Mon Sep 17 00:00:00 2001 From: Nikhil Raj Date: Sat, 18 May 2024 10:30:34 +0530 Subject: [PATCH 4/4] Updated documentation --- dev-documentation.md | 17 +++++++++++++++++ src/scrape_up/pinterest/pinterest.py | 8 ++++---- 2 files changed, 21 insertions(+), 4 deletions(-) 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/pinterest/pinterest.py b/src/scrape_up/pinterest/pinterest.py index 45d06639..ac54ffba 100644 --- a/src/scrape_up/pinterest/pinterest.py +++ b/src/scrape_up/pinterest/pinterest.py @@ -5,10 +5,10 @@ class Pinterest: """ Create an instance of `Pinterest` class. - ```python - pinterest = Pinterest() - ``` - | Methods | Details | + ```python + 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) |