Skip to content

Commit

Permalink
p firehose
Browse files Browse the repository at this point in the history
  • Loading branch information
kabniel committed Sep 28, 2014
1 parent e60566b commit 35b5b67
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion p
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 35b5b67

Please sign in to comment.