-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhashnode.py
33 lines (29 loc) · 1.1 KB
/
hashnode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from datetime import datetime
import feedparser
class Hashnode:
def __init__(self, tag: str = "web scraping"):
self.tags = tag.replace(" ", "-")
self.url = "https://hashnode.com/n/{}/rss".format(self.tags)
self.source = "Hasnode Dev - {}".format(self.tags.replace("-", " ").title())
self.feed = []
self.fetch()
def fetch(self):
self.rawfeed = feedparser.parse(self.url)
def parse(self):
entries = self.rawfeed.get("entries")
for entry in entries:
post = {
"title": entry.get("title"),
"author": entry.get("author"),
"link": entry.get("link"),
"published": entry.get("published"),
"tags": self.tags.replace("-", " "),
"source": self.source,
}
str_datefm = "%a, %d %b %Y %X GMT"
str_dateto = "%Y-%m-%d %X"
post["published"] = datetime.strftime(
datetime.strptime(post["published"], str_datefm), str_dateto
)
self.feed.append(post)
return self