Beispiel #1
0
 def get_items(self):
     yield node(
         'Submissions',
         children=[
             node(  # TODO can also be iterable?
                 dt_heading(s.created, link(title=s.title, url=s.url)),
                 body=s.text,
             ) for s in submissions()
         ])
     yield node(
         'Comments',  # TODO parent thread??
         children=[
             node(
                 dt_heading(c.created, link(title=c.url, url=c.url)),
                 body=c.text,
             ) for c in comments()
         ],
     )
     yield node('Upvoted',
                children=[
                    node(
                        dt_heading(u.created, link(title=u.title,
                                                   url=u.url)),
                        body=u.text,
                    ) for u in upvoted()
                ])
Beispiel #2
0
def index() -> Results:
    from . import hpi
    from my.reddit import submissions, comments, saved, upvoted
    # TODO should probably use markdown parser here?

    logger.info('processing saves')
    for s in saved():
        try:
            yield from _from_save(s)
        except Exception as e:
            yield e

    logger.info('processing comments')
    for c in comments():
        try:
            yield from _from_comment(c)
        except Exception as e:
            yield e

    logger.info('processing submissions')
    for sub in submissions():
        try:
            yield from _from_submission(sub)
        except Exception as e:
            yield e

    logger.info('processing upvotes')
    for u in upvoted():
        try:
            yield from _from_upvote(u)
        except Exception as e:
            yield e
Beispiel #3
0
def index(*,
          render_markdown: bool = False,
          renderer: Optional['RedditRenderer'] = None) -> Results:
    from . import hpi
    from my.reddit import submissions, comments, saved, upvoted

    if renderer is not None:
        assert callable(
            renderer
        ), f"{renderer} is not a callable (should be a subclass of RedditRenderer)"
        r = renderer(render_markdown=render_markdown)
    else:
        r = RedditRenderer(render_markdown=render_markdown)

    logger.info('processing saves')
    for s in saved():
        try:
            yield from r._from_save(s)
        except Exception as e:
            yield e

    logger.info('processing comments')
    for c in comments():
        try:
            yield from r._from_comment(c)
        except Exception as e:
            yield e

    logger.info('processing submissions')
    for sub in submissions():
        try:
            yield from r._from_submission(sub)
        except Exception as e:
            yield e

    logger.info('processing upvotes')
    for u in upvoted():
        try:
            yield from r._from_upvote(u)
        except Exception as e:
            yield e