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

Commit

Permalink
Merge pull request #3 from bitbackofen/testing
Browse files Browse the repository at this point in the history
Testing
  • Loading branch information
Markus Busche committed Nov 15, 2015
2 parents 03e418d + 78cd779 commit ab92686
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
19 changes: 12 additions & 7 deletions feedfetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
mattermost_webhook_url = settings.mattermost_webhook_url
delay_between_pulls = settings.delay_between_pulls
verify_cert = settings.verify_cert
silent_mode = settings.silent_mode
feeds = settings.feeds


def post_text(text, username, channel):
def post_text(text, username, channel, iconurl):
"""
Mattermost POST method, posts text to the Mattermost incoming webhook URL
"""
Expand All @@ -32,6 +33,8 @@ def post_text(text, username, channel):
data['username'] = username
if len(channel) > 0:
data['channel'] = channel
if len(iconurl) > 0:
data['icon_url'] = iconurl

headers = {'Content-Type': 'application/json'}
r = requests.post(mattermost_webhook_url, headers=headers, data=json.dumps(data), verify=verify_cert)
Expand All @@ -55,14 +58,16 @@ def post_text(text, username, channel):
feed.ArticleUrl = d['entries'][0]['link']
feed.Description = d['entries'][0]['description']
if feed.LastTitle != feed.NewTitle:
logging.debug('Feed url: ' + feed.Url)
logging.debug('Title: ' + feed.NewTitle + '\n')
logging.debug('Link: ' + feed.ArticleUrl + '\n')
logging.debug('Posted text: ' + feed.jointext())
post_text(feed.jointext(), feed.User, feed.Channel)
if not silent_mode:
logging.debug('Feed url: ' + feed.Url)
logging.debug('Title: ' + feed.NewTitle + '\n')
logging.debug('Link: ' + feed.ArticleUrl + '\n')
logging.debug('Posted text: ' + feed.jointext())
post_text(feed.jointext(), feed.User, feed.Channel, feed.Iconurl)
feed.LastTitle = feed.NewTitle
else:
logging.debug('Nothing new. Waiting for good news...')
if not silent_mode:
logging.debug('Nothing new. Waiting for good news...')
except:
logging.critical('Error fetching feed.')
continue
Expand Down
5 changes: 3 additions & 2 deletions rssfeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
import html2text
except ImportError as exc:
print('Error: failed to import module. ({}). \nInstall missing modules using '
'"sudo pip install -r requirements.txt"'.format(exc))
'"sudo pip install -r requirements.txt"'.format(exc))
sys.exit(0)


class RssFeed:
def __init__(self, name, url, user, channel, showname, showtitle, showdescription, showurl):
def __init__(self, name, url, iconurl, user, channel, showname, showtitle, showdescription, showurl):
self.Name = name
self.Url = url
self.Iconurl = iconurl
self.User = user
self.Channel = channel
self.ShowName = showname
Expand Down
21 changes: 15 additions & 6 deletions settings.py.sample
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,34 @@ from rssfeed import RssFeed
# Paste the Mattermost webhook URL you created here
# See also: https://github.com/mattermost/platform/blob/master/doc/integrations/webhooks/Incoming-Webhooks.md
mattermost_webhook_url = 'https://<your-mattermost-webhook-URL>'

# Set the delay between feed pulls to your needs. 5 minutes should be okay.
delay_between_pulls = 60 * 5

# Trust only signed SSL certificate?
verify_cert = False

# Deactivate logging for debug purposes
silent_mode = True

# Your feeds come here:
# RssFeed('Feed name', 'Feed URL', 'Mattermost username', 'Mattermost channel',
# RssFeed('Feed name', 'Feed URL', 'Image URL', 'Mattermost username', 'Mattermost channel',
# show name, show title, show description, show url)
#
# show name, show title, show description, show url can be True or False; at least one of them should be True
# show description (longer text or full article) seems not to work with every feed.
# Set to False it if a feed doesnt´t work.
# Hint: Channel overriding seems not to work with the channel 'Town Square'
feeds = (RssFeed('Heise News', 'http://heise.de.feedsportal.com/c/35207/f/653902/index.rss', 'RSS-Bot', 'testing',
feeds = (RssFeed('Heise News', 'http://heise.de.feedsportal.com/c/35207/f/653902/index.rss',
'http://elpatron.cepheus.uberspace.de/rss/rss3.png', 'RSS-Bot', 'rss-test',
True, True, True, True),
RssFeed('t3n', 'https://feeds2.feedburner.com/aktuell/feeds/rss/', 'RSS-Bot', 'testing',
RssFeed('t3n', 'https://feeds2.feedburner.com/aktuell/feeds/rss/',
'http://elpatron.cepheus.uberspace.de/rss/rss3.png', 'RSS-Bot', 'rss-test',
True, True, False, True),
RssFeed('Toms Hardware', 'http://www.tomshardware.com/articles.xml', 'RSS-Bot', 'testing',
RssFeed('Toms Hardware', 'http://www.tomshardware.com/articles.xml', '', 'RSS-Bot', 'rss-test',
True, True, True, True),
RssFeed('Mattermost Forum', 'http://forum.mattermost.org/latest.rss', 'RSS-Bot', 'testing',
True, True, True, True))
RssFeed('Mattermost Forum', 'http://forum.mattermost.org/latest.rss',
'http://www.mattermost.org/wp-content/uploads/2015/08/logomark.png', 'RSS-Bot', 'rss-test',
True, True, True, True)
)

0 comments on commit ab92686

Please sign in to comment.