-
Notifications
You must be signed in to change notification settings - Fork 846
/
github_activity.py
72 lines (54 loc) · 1.88 KB
/
github_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
64
65
66
67
68
69
70
71
72
# -*- coding: utf-8 -*-
# NEEDS WORK
"""
Copyright (c) Marco Milanesi <[email protected]>
Github Activity
---------------
A plugin to list your Github Activity
"""
from __future__ import unicode_literals, print_function
import logging
logger = logging.getLogger(__name__)
from pelican import signals
class GitHubActivity():
"""
A class created to fetch github activity with feedparser
"""
def __init__(self, generator):
import feedparser
self.activities = feedparser.parse(
generator.settings['GITHUB_ACTIVITY_FEED'])
self.max_entries = generator.settings['GITHUB_ACTIVITY_MAX_ENTRIES']
def fetch(self):
"""
returns a list of html snippets fetched from github actitivy feed
"""
entries = []
for activity in self.activities['entries']:
entries.append(
[element for element in [activity['title'],
activity['content'][0]['value']]])
return entries[0:self.max_entries]
def fetch_github_activity(gen, metadata):
"""
registered handler for the github activity plugin
it puts in generator.context the html needed to be displayed on a
template
"""
if 'GITHUB_ACTIVITY_FEED' in gen.settings.keys():
gen.context['github_activity'] = gen.plugin_instance.fetch()
def feed_parser_initialization(generator):
"""
Initialization of feed parser
"""
generator.plugin_instance = GitHubActivity(generator)
def register():
"""
Plugin registration
"""
try:
signals.article_generator_init.connect(feed_parser_initialization)
signals.article_generator_context.connect(fetch_github_activity)
except ImportError:
logger.warning('`github_activity` failed to load dependency `feedparser`.'
'`github_activity` plugin not loaded.')