From 35b5b67b52a6f577a7556787c82ab0c0980e89fc Mon Sep 17 00:00:00 2001 From: Jonas Haraldsson Date: Sun, 28 Sep 2014 11:24:34 +0200 Subject: [PATCH] p firehose Example custom feed for reading https://ofirehose.com/feed.json https://github.com/xray7224/PyPump/issues/113 --- p | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/p b/p index 8de57ef..48167d6 100755 --- a/p +++ b/p @@ -718,7 +718,55 @@ def p_favorites(p, webfinger, number): if limit <= 0: return - +@cli.command('firehose') +@pass_p +@click.option('--number', '-n', default=20, help='Number of items to show.') +def p_firehose(p, number): + """ Display items in the public firehose (https://ofirehose.com) + """ + from pypump.models import Feed + import requests + + class Firehose(Feed): + """ Firehose feed """ + + def _request(self, url, offset=None, since=None, before=None): + """ Basic http GET request instead of the OAuth Feed._request. + offset, since, before params are ignored by ofirehose so we + dont include them in request + """ + data = requests.request("GET", url).json() + self.unserialize(data) + return data + + firehose = Firehose(url='https://ofirehose.com/feed.json', pypump=p.pump) + + + limit = number + + for activity in firehose: + if activity.obj.deleted: + #skip deleted objects + continue + + p.output.log(click.style(u"{0}".format(activity), fg="green")) + + item = activity.obj + + p._display_object(item, indent=2) + if hasattr(item, 'comments'): + comments = list(item.comments) + for comment in comments[::-1]: + p._display_object(comment, indent=4) + + p.output.log("") + + limit -= 1 + + if limit <= 0: + return + + @cli.command('lists') @pass_p def p_lists(p):