Skip to content
This repository was archived by the owner on Mar 11, 2019. It is now read-only.

Commit ab92686

Browse files
author
Markus Busche
committed
Merge pull request #3 from bitbackofen/testing
Testing
2 parents 03e418d + 78cd779 commit ab92686

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

feedfetcher.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
mattermost_webhook_url = settings.mattermost_webhook_url
2020
delay_between_pulls = settings.delay_between_pulls
2121
verify_cert = settings.verify_cert
22+
silent_mode = settings.silent_mode
2223
feeds = settings.feeds
2324

2425

25-
def post_text(text, username, channel):
26+
def post_text(text, username, channel, iconurl):
2627
"""
2728
Mattermost POST method, posts text to the Mattermost incoming webhook URL
2829
"""
@@ -32,6 +33,8 @@ def post_text(text, username, channel):
3233
data['username'] = username
3334
if len(channel) > 0:
3435
data['channel'] = channel
36+
if len(iconurl) > 0:
37+
data['icon_url'] = iconurl
3538

3639
headers = {'Content-Type': 'application/json'}
3740
r = requests.post(mattermost_webhook_url, headers=headers, data=json.dumps(data), verify=verify_cert)
@@ -55,14 +58,16 @@ def post_text(text, username, channel):
5558
feed.ArticleUrl = d['entries'][0]['link']
5659
feed.Description = d['entries'][0]['description']
5760
if feed.LastTitle != feed.NewTitle:
58-
logging.debug('Feed url: ' + feed.Url)
59-
logging.debug('Title: ' + feed.NewTitle + '\n')
60-
logging.debug('Link: ' + feed.ArticleUrl + '\n')
61-
logging.debug('Posted text: ' + feed.jointext())
62-
post_text(feed.jointext(), feed.User, feed.Channel)
61+
if not silent_mode:
62+
logging.debug('Feed url: ' + feed.Url)
63+
logging.debug('Title: ' + feed.NewTitle + '\n')
64+
logging.debug('Link: ' + feed.ArticleUrl + '\n')
65+
logging.debug('Posted text: ' + feed.jointext())
66+
post_text(feed.jointext(), feed.User, feed.Channel, feed.Iconurl)
6367
feed.LastTitle = feed.NewTitle
6468
else:
65-
logging.debug('Nothing new. Waiting for good news...')
69+
if not silent_mode:
70+
logging.debug('Nothing new. Waiting for good news...')
6671
except:
6772
logging.critical('Error fetching feed.')
6873
continue

rssfeed.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
import html2text
88
except ImportError as exc:
99
print('Error: failed to import module. ({}). \nInstall missing modules using '
10-
'"sudo pip install -r requirements.txt"'.format(exc))
10+
'"sudo pip install -r requirements.txt"'.format(exc))
1111
sys.exit(0)
1212

1313

1414
class RssFeed:
15-
def __init__(self, name, url, user, channel, showname, showtitle, showdescription, showurl):
15+
def __init__(self, name, url, iconurl, user, channel, showname, showtitle, showdescription, showurl):
1616
self.Name = name
1717
self.Url = url
18+
self.Iconurl = iconurl
1819
self.User = user
1920
self.Channel = channel
2021
self.ShowName = showname

settings.py.sample

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,34 @@ from rssfeed import RssFeed
77
# Paste the Mattermost webhook URL you created here
88
# See also: https://github.com/mattermost/platform/blob/master/doc/integrations/webhooks/Incoming-Webhooks.md
99
mattermost_webhook_url = 'https://<your-mattermost-webhook-URL>'
10+
1011
# Set the delay between feed pulls to your needs. 5 minutes should be okay.
1112
delay_between_pulls = 60 * 5
13+
1214
# Trust only signed SSL certificate?
1315
verify_cert = False
1416

17+
# Deactivate logging for debug purposes
18+
silent_mode = True
19+
1520
# Your feeds come here:
16-
# RssFeed('Feed name', 'Feed URL', 'Mattermost username', 'Mattermost channel',
21+
# RssFeed('Feed name', 'Feed URL', 'Image URL', 'Mattermost username', 'Mattermost channel',
1722
# show name, show title, show description, show url)
1823
#
1924
# show name, show title, show description, show url can be True or False; at least one of them should be True
2025
# show description (longer text or full article) seems not to work with every feed.
2126
# Set to False it if a feed doesnt´t work.
2227
# Hint: Channel overriding seems not to work with the channel 'Town Square'
23-
feeds = (RssFeed('Heise News', 'http://heise.de.feedsportal.com/c/35207/f/653902/index.rss', 'RSS-Bot', 'testing',
28+
feeds = (RssFeed('Heise News', 'http://heise.de.feedsportal.com/c/35207/f/653902/index.rss',
29+
'http://elpatron.cepheus.uberspace.de/rss/rss3.png', 'RSS-Bot', 'rss-test',
2430
True, True, True, True),
25-
RssFeed('t3n', 'https://feeds2.feedburner.com/aktuell/feeds/rss/', 'RSS-Bot', 'testing',
31+
RssFeed('t3n', 'https://feeds2.feedburner.com/aktuell/feeds/rss/',
32+
'http://elpatron.cepheus.uberspace.de/rss/rss3.png', 'RSS-Bot', 'rss-test',
2633
True, True, False, True),
27-
RssFeed('Toms Hardware', 'http://www.tomshardware.com/articles.xml', 'RSS-Bot', 'testing',
34+
RssFeed('Toms Hardware', 'http://www.tomshardware.com/articles.xml', '', 'RSS-Bot', 'rss-test',
2835
True, True, True, True),
29-
RssFeed('Mattermost Forum', 'http://forum.mattermost.org/latest.rss', 'RSS-Bot', 'testing',
30-
True, True, True, True))
36+
RssFeed('Mattermost Forum', 'http://forum.mattermost.org/latest.rss',
37+
'http://www.mattermost.org/wp-content/uploads/2015/08/logomark.png', 'RSS-Bot', 'rss-test',
38+
True, True, True, True)
39+
)
3140

0 commit comments

Comments
 (0)