Skip to content

Commit

Permalink
update README, update genfeed, add feed_file()
Browse files Browse the repository at this point in the history
  • Loading branch information
m3taas authored and Lorenz Vader committed Jun 22, 2022
1 parent 31bdb4e commit 2e34a32
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 20 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,17 @@ Generate atom/rss files

You can easily add a cronjob on your server to update the feed.

Test your feed
## Query the feed

$ curl http://HOST_IP:5000/feed/atom
$ curl http://HOST_IP:5000/feed/rss
`ft` is an optional argument to your request and can either be `atom` or `rss` (default is `rss`)

# [Twitch Helix api reference](https://dev.twitch.tv/docs/api/reference)
To get a feed with all followed channels

$ curl 'http://HOST_IP:5000/feed'
$ curl 'http://HOST_IP:5000/feed?ft=atom'

To get a feed from a single channel

$ curl 'http://HOST_IP:5000/feed/esl_csgo?ft=atom'

### [Twitch Helix api reference](https://dev.twitch.tv/docs/api/reference)
6 changes: 3 additions & 3 deletions genfeed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

from twitchfeed import mkfeed, feed
from twitchfeed import mkfeed, TwitchFeed
import logging

# for usage without flask
Expand All @@ -9,9 +9,9 @@
mk.update()

if mk.rss_out:
feed.fg.rss_file(mk.rss_out, pretty=True)
mk.feed_file()
logging.info("Generated rss feed: '{}'".format(mk.rss_out))

if mk.atom_out:
feed.fg.atom_file(mk.atom_out, pretty=True)
mk.feed_file(feed_type="atom")
logging.info("Generated atom feed: '{}'".format(mk.atom_out))
7 changes: 2 additions & 5 deletions twitchfeed/TwitchFeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def parse_feed(self, stream, game_dict, fg):
"""
Generate a feed for a single channel
"""
def parse_feed_single(self, helix, channel, feed_type):
def parse_feed_single(self, helix, channel):

# setup feed
fg = FeedGenerator()
Expand All @@ -113,7 +113,4 @@ def parse_feed_single(self, helix, channel, feed_type):
self.parse_feed(stream, helix.game_dict, fg)
logging.debug("Stream: {}".format(stream))
finally:
if feed_type == "rss":
return fg.rss_str(pretty=True)
elif feed_type == "atom":
return fg.atom_str(pretty=True)
return fg
28 changes: 22 additions & 6 deletions twitchfeed/mkfeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,30 @@ def update(self):
self.__twitch_feed.flush()
self.__twitch_feed.parse_feed_helix(self.__helix)

def atom_str(self, channel=None):
def feed_str(self, channel=None, feed_type="rss"):
if channel is not None:
return self.__twitch_feed.parse_feed_single(self.__helix, channel, "atom")
fg = self.__twitch_feed.parse_feed_single(self.__helix, channel)

if feed_type == "rss":
return fg.rss_str(pretty=True)
elif feed_type == "atom":
return fg.atom_str(pretty=True)
else:
return self.__twitch_feed.fg.atom_str(pretty=True)
if feed_type == "rss":
return self.__twitch_feed.fg.rss_str(pretty=True)
elif feed_type == "atom":
return self.__twitch_feed.fg.atom_str(pretty=True)

def rss_str(self, channel=None):
def feed_file(self, channel=None, feed_type="rss"):
if channel is not None:
return self.__twitch_feed.parse_feed_single(self.__helix, channel, "rss")
fg = self.__twitch_feed.parse_feed_single(self.__helix, channel)

if feed_type == "rss":
return fg.rss_file(self.rss_out, pretty=True)
elif feed_type == "atom":
return fg.atom_file(self.atom_out, pretty=True)
else:
return self.__twitch_feed.fg.rss_str(pretty=True)
if feed_type == "rss":
return self.__twitch_feed.fg.rss_file(self.rss_out, pretty=True)
elif feed_type == "atom":
return self.__twitch_feed.fg.atom_file(self.atom_out, pretty=True)
4 changes: 2 additions & 2 deletions wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ def stfg(feed_type=None, channel=None, update=True):
mk.update()

if feed_type == "rss":
response = app.make_response(mk.rss_str(channel))
response = app.make_response(mk.feed_str(channel))
response.headers.set("Content-Type", "application/rss+xml")
return response
elif feed_type == "atom":
response = app.make_response(mk.atom_str(channel))
response = app.make_response(mk.feed_str(channel, "atom"))
response.headers.set("Content-Type", "application/atom+xml")
return response

Expand Down

0 comments on commit 2e34a32

Please sign in to comment.