Skip to content

Commit

Permalink
Merge pull request #999 from priyankeshh/pinterestPy
Browse files Browse the repository at this point in the history
#951 Added 2 new features
  • Loading branch information
nikhil25803 authored May 18, 2024
2 parents 85df308 + 0d92a28 commit bb810bf
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 21 deletions.
17 changes: 17 additions & 0 deletions dev-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
3 changes: 1 addition & 2 deletions src/scrape_up/atcoder/atcoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Atcoder:
| Methods | Details |
| ----------------- | ---------------------------------------------------------------------------------- |
| `.get_profile()` | Returns the user data in json format. |
Response
```json
{
Expand All @@ -36,7 +36,6 @@ class Atcoder:
```
"""


def __init__(self, user):
self.user = user

Expand Down
43 changes: 24 additions & 19 deletions src/scrape_up/pinterest/pinterest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
"""
Expand All @@ -28,15 +28,16 @@ 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/",
"title":"How To Style A Shawl This Winter",
"subtitle":"Perfect Winter Companion",
"image":"https://i.pinimg.com/736x/10/46/c8/1046c8dc21138326568405a24f871e17.jpg"
},
]
```
"""
try:
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit bb810bf

Please sign in to comment.