-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblogfeed.py
176 lines (148 loc) · 5.04 KB
/
blogfeed.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import feedparser
import time
from urllib.parse import urljoin
class BlogFeed:
"""Superclass"""
def __init__(self, url, name):
self.url = url
self.source = name
self.feed = []
def fetch(self):
print("GET", self.url)
rawfeed = feedparser.parse(self.url)
return rawfeed
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_parsed"),
"tags": entry.get("tags"),
"source": self.source,
}
if post["tags"] is not None:
post["tags"] = [tag.get("term") for tag in post["tags"]]
post["published"] = time.strftime("%Y-%m-%d %X", post["published"])
self.feed.append(post)
return self
class Aws(BlogFeed):
def __init__(self, topic: str):
BlogFeed.__init__(
self, url=f"https://aws.amazon.com/blogs/{topic}/feed/", name="AWS Blog"
)
self.rawfeed = self.fetch()
class Azure(BlogFeed):
def __init__(self, category=None):
BlogFeed.__init__(
self,
url="https://azure.microsoft.com",
name="Microsoft Azure",
)
if category:
self.url = urljoin(self.url, f"/en-us/blog/category/{category}/feed/")
else:
self.url = urljoin(self.url, "/en-us/blog/feed/")
self.rawfeed = self.fetch()
class Comparitech(BlogFeed):
def __init__(self, tag=None):
if tag:
tag = tag.replace(" ", "-")
url = f"https://www.comparitech.com/blog/{tag}/feed/"
else:
url = "https://www.comparitech.com/blog/feed/"
BlogFeed.__init__(self, url=url, name="Comparitech Blog")
self.rawfeed = self.fetch()
class DataHen(BlogFeed):
def __init__(self):
BlogFeed.__init__(
self,
url="https://www.datahen.com/blog/rss/",
name="DataHen Blog",
)
self.rawfeed = self.fetch()
class Devto(BlogFeed):
# not all hashtag has feed https://dev.to/tags
def __init__(self, tag: str = ""):
BlogFeed.__init__(
self,
url=f"https://dev.to/feed/{tag}",
name="Dev Community",
)
self.rawfeed = self.fetch()
class Dzone(BlogFeed):
def __init__(self, category=None):
if category:
name = f"DZone - {category.title()}"
url = f"https://feeds.dzone.com/{category}"
else:
name = "DZone"
url = f"https://feeds.dzone.com/home"
BlogFeed.__init__(self, url=url, name=name)
self.rawfeed = self.fetch()
class MachineLearningMastery(BlogFeed):
def __init__(self, category=None):
BlogFeed.__init__(
self,
url="https://machinelearningmastery.com",
name="Machine Learning Mastery",
)
if category:
self.url = urljoin(self.url, f"/category/{category}/feed/")
else:
self.url = urljoin(self.url, "/feed/")
self.rawfeed = self.fetch()
class Meta(BlogFeed):
def __init__(self, category=None):
BlogFeed.__init__(
self,
url="https://engineering.fb.com",
name="Meta Engineering",
)
if category:
self.url = urljoin(self.url, f"/category/{category}/feed/")
category = category.replace("-", " ").title()
self.source = f"{self.source} - {category}"
else:
self.url = urljoin(self.url, "/feed/")
self.rawfeed = self.fetch()
class OReilly(BlogFeed):
def __init__(self, topic=None):
if topic:
url = f"https://www.oreilly.com/radar/topics/{topic}/feed/index.xml"
topic = topic.replace("-", " ").title()
name = f"O'Reilly - {topic}"
else:
url = "https://www.oreilly.com/radar/feed/index.xml"
name = "O'Reilly"
BlogFeed.__init__(self, url=url, name=name)
self.rawfeed = self.fetch()
class Salesforce(BlogFeed):
def __init__(self):
BlogFeed.__init__(
self,
url="https://engineering.salesforce.com/feed",
name="Salesforce Engineering",
)
self.rawfeed = self.fetch()
class SoftwareEngDaily(BlogFeed):
def __init__(self, category=None):
BlogFeed.__init__(
self,
url="https://softwareengineeringdaily.com",
name="Software Engineering Daily",
)
if category:
self.url = urljoin(self.url, f"/category/{category}/feed/")
else:
self.url = urljoin(self.url, "/feed/")
self.rawfeed = self.fetch()
class Uber(BlogFeed):
def __init__(self):
BlogFeed.__init__(
self,
url="https://www.uber.com/blog/engineering/rss",
name="Uber Blog",
)
self.rawfeed = self.fetch()