-
Notifications
You must be signed in to change notification settings - Fork 844
/
Copy pathgoodreads_activity.py
63 lines (48 loc) · 1.83 KB
/
goodreads_activity.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
# -*- coding: utf-8 -*-
"""
Goodreads Activity
==================
A Pelican plugin to lists books from your Goodreads shelves.
Copyright (c) Talha Mansoor
"""
from __future__ import unicode_literals
import logging
logger = logging.getLogger(__name__)
from pelican import signals
class GoodreadsActivity():
def __init__(self, generator):
import feedparser
self.activities = feedparser.parse(
generator.settings['GOODREADS_ACTIVITY_FEED'])
def fetch(self):
goodreads_activity = {
'shelf_title': self.activities.feed.title,
'books': []
}
for entry in self.activities['entries']:
book = {
'title': entry.title,
'author': entry.author_name,
'link': entry.link,
'l_cover': entry.book_large_image_url,
'm_cover': entry.book_medium_image_url,
's_cover': entry.book_small_image_url,
'description': entry.book_description,
'rating': entry.user_rating,
'review': entry.user_review,
'tags': entry.user_shelves
}
goodreads_activity['books'].append(book)
return goodreads_activity
def fetch_goodreads_activity(gen, metadata):
if 'GOODREADS_ACTIVITY_FEED' in gen.settings:
gen.context['goodreads_activity'] = gen.goodreads.fetch()
def initialize_feedparser(generator):
generator.goodreads = GoodreadsActivity(generator)
def register():
try:
signals.article_generator_init.connect(initialize_feedparser)
signals.article_generator_context.connect(fetch_goodreads_activity)
except ImportError:
logger.warning('`goodreads_activity` failed to load dependency `feedparser`.'
'`goodreads_activity` plugin not loaded.')