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

Commit 0279139

Browse files
author
elpatron68
committed
Icon URL
1 parent 4ed009a commit 0279139

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

feedfetcher.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
feeds = settings.feeds
2424

2525

26-
def post_text(text, username, channel):
26+
def post_text(text, username, channel, iconurl):
2727
"""
2828
Mattermost POST method, posts text to the Mattermost incoming webhook URL
2929
"""
@@ -33,6 +33,8 @@ def post_text(text, username, channel):
3333
data['username'] = username
3434
if len(channel) > 0:
3535
data['channel'] = channel
36+
if len(iconurl) > 0:
37+
data['icon_url'] = iconurl
3638

3739
headers = {'Content-Type': 'application/json'}
3840
r = requests.post(mattermost_webhook_url, headers=headers, data=json.dumps(data), verify=verify_cert)
@@ -56,15 +58,15 @@ def post_text(text, username, channel):
5658
feed.ArticleUrl = d['entries'][0]['link']
5759
feed.Description = d['entries'][0]['description']
5860
if feed.LastTitle != feed.NewTitle:
59-
if silent_mode Is False:
61+
if not silent_mode:
6062
logging.debug('Feed url: ' + feed.Url)
6163
logging.debug('Title: ' + feed.NewTitle + '\n')
6264
logging.debug('Link: ' + feed.ArticleUrl + '\n')
6365
logging.debug('Posted text: ' + feed.jointext())
64-
post_text(feed.jointext(), feed.User, feed.Channel)
66+
post_text(feed.jointext(), feed.User, feed.Channel, feed.Iconurl)
6567
feed.LastTitle = feed.NewTitle
6668
else:
67-
if silent_mode Is False:
69+
if not silent_mode:
6870
logging.debug('Nothing new. Waiting for good news...')
6971
except:
7072
logging.critical('Error fetching feed.')

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: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,33 @@ 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
16+
1417
# Deactivate logging for debug purposes
1518
silent_mode = True
19+
1620
# Your feeds come here:
17-
# RssFeed('Feed name', 'Feed URL', 'Mattermost username', 'Mattermost channel',
21+
# RssFeed('Feed name', 'Feed URL', 'Image URL', 'Mattermost username', 'Mattermost channel',
1822
# show name, show title, show description, show url)
1923
#
2024
# show name, show title, show description, show url can be True or False; at least one of them should be True
2125
# show description (longer text or full article) seems not to work with every feed.
2226
# Set to False it if a feed doesnt´t work.
2327
# Hint: Channel overriding seems not to work with the channel 'Town Square'
24-
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', 'testing',
2530
True, True, True, True),
26-
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', 'testing',
2733
True, True, False, True),
28-
RssFeed('Toms Hardware', 'http://www.tomshardware.com/articles.xml', 'RSS-Bot', 'testing',
34+
RssFeed('Toms Hardware', 'http://www.tomshardware.com/articles.xml', '', 'RSS-Bot', 'testing',
2935
True, True, True, True),
30-
RssFeed('Mattermost Forum', 'http://forum.mattermost.org/latest.rss', 'RSS-Bot', 'testing',
36+
RssFeed('Mattermost Forum', 'http://forum.mattermost.org/latest.rss',
37+
'http://www.mattermost.org/wp-content/uploads/2015/08/logomark.png', 'RSS-Bot', 'testing',
3138
True, True, True, True))
3239

0 commit comments

Comments
 (0)