forked from hezhen/python-goose
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoose_api.py
More file actions
48 lines (43 loc) · 1.46 KB
/
Copy pathgoose_api.py
File metadata and controls
48 lines (43 loc) · 1.46 KB
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
from goose import Goose
class GooseAPI:
def __init__(self, url):
self.url = url
self.goose = Goose()
self.article = None
def extract(self):
self.article = self.goose.extract(url=self.url)
return {
'title': self.article.title,
'summary': self.article.meta_description,
'content': self.article.cleaned_text,
'published_at': self.article.publish_date,
'opengraph': self.article.opengraph,
'authors': self.article.authors,
'links': self.article.links,
'image': self.images(),
'movies': self.movies(),
'tweets': self.article.tweets,
'tags': list(self.article.tags),
}
def movies(self):
movies = []
for movie in self.article.movies:
movies.append({
'embed_type': movie.embed_type,
'provider': movie.embed_type,
'width': movie.width,
'height': movie.height,
'embed_code': movie.embed_code,
'src': movie.src,
})
return movies
def images(self):
images = []
if self.article.top_image:
images.append({
'url': self.article.top_image.src,
'width': self.article.top_image.width,
'height': self.article.top_image.height,
'type': 'image'
})
return images