Example #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()
                ])
Example #2
0
 def get_items(self) -> Mirror.Results:
     for a in articles():
         yield node(
             heading=dt_heading(
                 a.added,
                 link(title='pocket', url=a.pocket_link)  + ' ยท ' + link(title=a.title, url=a.url)
             ),
             children=[node(
                 heading=dt_heading(hl.created, hl.text)
             ) for hl in a.highlights]
         )
Example #3
0
 def get_items(self):
     for page in get_pages():
         yield node(heading=dt_heading(
             page.dt, link(title=page.title, url=page.link)),
                    children=[
                        node(heading=dt_heading(
                            hl.dt, link(title='context', url=hl.hyp_link)),
                             tags=hl.tags,
                             body=hl.highlight,
                             children=[] if hl.annotation is None else
                             [node(heading=hl.annotation, )])
                        for hl in page.highlights
                    ])
Example #4
0
 def get_items(self):
     for pdf in sorted(
             pdfs.get_annotated_pdfs(),
             key=lambda p: datetime.min
             if p.date is None else p.date.replace(tzinfo=None),
     ):
         yield node(dt_heading(pdf.date, str(pdf.path)),
                    children=[
                        node(
                            dt_heading(
                                a.date,
                                f'page {a.page} {a.highlight or ""}'),
                            body=a.comment,
                        ) for a in pdf.annotations
                    ])
Example #5
0
 def make_item(res: polar.Result):
     if isinstance(res, polar.Error):
         return node(heading='ERROR ' + str(res))  # TODO priority A?
     else:
         b = res
         return node(
             heading=dt_heading(b.created, f'{b.title} {b.filename}'),
             # tags=b.tags, # TODO?
             children=[
                 node(heading=dt_heading(hl.created, hl.selection),
                      children=[
                          node(heading=dt_heading(c.created, c.text))
                          for c in hl.comments
                      ]) for hl in b.items
             ])
Example #6
0
 def get_items(self):
     for page in get_pages():
         yield node(
             heading=dt_heading(
                 page.dt,
                 f'{link(title="ip", url=page.bookmark.instapaper_link)}   {link(title=page.title, url=page.url)}',
             ),
             children=[node(
                 heading=dt_heading(hl.dt, link(title="ip", url=page.bookmark.instapaper_link)),
                 body=hl.text,
                 children=[] if hl.note is None else [
                     node(heading=hl.note),
                 ],
             ) for hl in page.highlights]
         )
Example #7
0
    def get_items(self) -> Mirror.Results:
        # TODO just use events? but need to sort first..
        for e in github.get_events():
            if isinstance(e, Exception):
                yield error(e)
                continue
            # TODO filter only events that have body? e.g. not sure if much point emitting pull requests here
            summary = e.summary
            body = e.body
            if body is None:
                lines = summary.splitlines(keepends=True)
                if len(lines) > 1:
                    summary = lines[0].strip()
                body = ''.join(
                    lines[1:]
                )  # todo meh. hacky, better to extract bodies in the provider properly
            if body.strip() == '':
                body = None

            yield node(
                dt_heading(
                    e.dt,
                    link(url=e.link, title=summary)
                    if e.link is not None else summary),
                body=None if body is None else pandoc.to_org(
                    body, from_='gfm'),  # github flavored markdown
            )
Example #8
0
 def make_comment(c: polar.Comment) -> OrgNode:
     text = pandoc.to_org(data=c.text, from_='html', logger=self.logger)
     return node(
         heading=dt_heading(c.created,
                            text.splitlines()[0]),
         body=text,
     )
Example #9
0
 def get_items(self):
     for t in get_active_tasks():
         yield t.uid, node(
             dt_heading(t.time, t.title),
             tags=t.tags,
             body='\n'.join(t.notes),
         )
Example #10
0
 def get_items(self):
     movies = get_movies()
     for m in movies:
         yield m.title, node(
             dt_heading(m.created, m.title),
             body=f'rating: {m.rating}',
         )
Example #11
0
 def get_items(self):
     for page in get_pages():
         # TODO would be nice to signal error upwards? Maybe just yield Exception, rener it in Orger and allow setting error status?
         if isinstance(page, Exception):
             yield error(page)
             continue
         yield node(
             heading=dt_heading(page.created, link(title=page.title, url=page.url)),
             children=[node(
                 heading=dt_heading(hl.created, link(title='context', url=hl.hyp_link)),
                 tags=hl.tags,
                 body=hl.highlight,
                 children=[] if hl.annotation is None else [node(
                     heading=hl.annotation,
                 )]
             ) for hl in page.highlights]
         )
Example #12
0
 def get_items(self):
     """
     get_items returns a sequence/iterator of nodes
     see orger.inorganic.OrgNode to find out about attributes you can use
     """
     export_file = self.cmdline_args.file  # see setup_parser
     for a in get_articles(export_file):
         yield node(
             heading=dt_heading(a.added, link(title=a.title, url=a.url)),
             body=link(
                 title='Pocket link', url=a.pocket_link
             ),  # permalink is pretty convenient to jump straight into Pocket app
             children=[
                 node(  # comments are displayed as org-mode child entries
                     heading=dt_heading(hl.created, hl.text))
                 for hl in a.highlights
             ])
Example #13
0
 def render_highlight(h: Highlight) -> OrgNode:
     # TODO FIXME could use bookmark page??
     heading = 'bookmark' if h.kind == 'bookmark' else (h.text or '')
     body = h.annotation  # TODO check if empty
     return node(
         heading=dt_heading(h.dt, heading),
         body=body,
     )
Example #14
0
 def get_items(self):
     for s in get_saves():
         yield s.sid, node(
             # need to make heading lazy due to is_alive
             heading=lambda s=s: dt_heading(s.created, (
                 '[#A] *DEAD*' if self.is_dead_url(s.url) else '') + link(
                     title=s.title, url=s.url) + f' /r/{s.subreddit}'),
             body=s.text,
         )
Example #15
0
 def get_items(self):
     for s in saves():
         yield s.uid, node(
             heading=dt_heading(
                 s.when,
                 link(title=s.title, url=s.hackernews_link),
             ),
             body=s.url,
         )
Example #16
0
 def get_items(self):
     # TODO adapt for other stackexchange items
     se_data = se.get_data()
     for q in se_data.questions:
         # TODO could emit items along with level, then it would look a bit more natural
         yield node(
             dt_heading(q.creation_date, link(url=q.link, title=q.title)),
             tags=q.tags,
             body=q.
             body_markdown,  # TODO eh, would be useful to have md2org perhaps?
         )
Example #17
0
 def get_items(self):
     for s in saved():
         yield s.sid, node(
             # need to make heading lazy due to is_alive
             # eh, can't guess the type of lambda??
             heading=lambda s=s: dt_heading( # type: ignore[misc]
                 s.created,
                 ('[#A] *DEAD*' if self.is_dead_url(s.url) else '') + link(title=s.title, url=s.url) + f' /r/{s.subreddit}'
             ),
             body=s.text,
         )
Example #18
0
 def get_items(self) -> Mirror.Results:
     # TODO adapt for other stackexchange items
     se_data = se.site('stackoverflow')
     for q in se_data.questions:
         # TODO could emit items along with level, then it would look a bit more natural
         yield node(
             dt_heading(q.creation_date, link(url=q.link, title=q.title)),
             tags=q.tags,
             body=Quoted(q.body_markdown),
             # todo eh, would be useful to have md2org perhaps?
         )
Example #19
0
 def get_items(self):
     for e in gh.get_events():
         # TODO filter only events that have body? e.g. not sure if much point emitting pull requests here
         yield node(
             dt_heading(
                 e.dt,
                 link(url=e.link, title=e.summary)
                 if e.link is not None else e.summary),
             # TODO would be nice to convert from markdown to org here
             body=e.body,
         )
Example #20
0
 def get_items(self) -> Mirror.Results:
     for f in favorites():
         if isinstance(f, Favorite):
             yield node(
                 heading=dt_heading(
                     f.dt,
                     f.title if f.url is None else link(url=f.url,
                                                        title=f.title),
                 ),
                 body=Quoted(f.text),
             )
         else:  # Exception
             yield error(f)
Example #21
0
 def make_item(res: polar.Result):
     if isinstance(res, polar.Error):
         # TODO could create error heading from exception automatically? take first line as heading and rest + traceback as the body
         return node(heading='ERROR ' + str(res))  # TODO priority A?
     else:
         book = res
         return node(
             heading=dt_heading(
                 book.created,
                 # TODO apparently file: is not necessary if the path is absolute?
                 link(url=str(book.path), title=book.title),
             ),
             tags=book.tags,
             children=[
                 node(
                     heading=dt_heading(hl.created, hl.selection),
                     tags=hl.tags,
                     properties=None if hl.color is None else
                     {'POLAR_COLOR': hex2name(hl.color)},
                     children=[make_comment(c) for c in hl.comments],
                 ) for hl in book.items
             ])
Example #22
0
            def chit():
                for a in file_annotations:
                    parts = []
                    text = a.text
                    if text is not None:
                        # todo not sure about it here... maybe should rely on softwrap in emacs instead?
                        text = '\n'.join(
                            wrap(text, width=config.MAX_LINE_WIDTH))
                        text = literal(text)
                        parts.append(text)
                    comment = a.comment
                    if comment is not None:
                        parts.append(comment)
                    page1 = a.page + 1  # NOTE: zotero using 0-indexing, pdfview using 1-indexing
                    body = '\n'.join(parts)

                    color = a.color_human
                    tags = list(a.tags)
                    # todo not sure which is best?
                    tags.append(color)
                    properties = {
                        'ZOTERO_COLOR': color,
                    }
                    if len(a.tags) > 0:
                        # zotero tags cal be multi-word? guess worth adding just in case
                        properties['ZOTERO_TAGS'] = ', '.join(
                            a.tags)  # not sure what's the best separator...

                    # todo not sure about it...
                    mtodo: Optional[str] = None
                    if 'todo' in {t.lower() for t in tags}:
                        mtodo = 'TODO'

                    heading = docview_link(path=item.file,
                                           title=f'page {page1}',
                                           page1=page1)
                    if comment is not None:
                        # try to display first few words?
                        cline = wrap(comment, width=config.MAX_LINE_WIDTH)[0]
                        heading = heading + ' ' + cline
                    # todo would be nice to align tags, maybe...
                    yield node(
                        todo=mtodo,
                        heading=dt_heading(
                            a.added,
                            heading,
                        ),
                        tags=tags,
                        properties=properties,
                        body=body,
                    )
Example #23
0
 def get_items(self) -> Mirror.Results:
     by_url = lambda w: w.url
     by_when = lambda w: w.when
     items = [
         max(group, key=by_when)
         for _, group in groupby(sorted(watched(), key=by_url), key=by_url)
     ]
     items = sorted(items, key=by_when)
     # TODO for each url only take latest?
     for item in items:
         deleted = item.url == item.title  # todo move to HPI?
         l = link(title=item.title + (' (DELETED)' if deleted else ''),
                  url=item.url)
         yield (item.url, node(heading=dt_heading(item.when, l), ))
Example #24
0
 def get_items(self):
     watched = get_watched()
     by_url  = lambda w: w.url
     by_when = lambda w: w.when
     items = [
         max(group, key=by_when)
         for _, group in groupby(sorted(watched, key=by_url), key=by_url)
     ]
     items = sorted(items, key=by_when)
     # TODO for each url only take latest?
     for item in items:
         yield (item.url, node(
             heading=dt_heading(item.when, link(title=item.title, url=item.url)),
         ))
Example #25
0
def roam_note_to_org(node: roamresearch.Node, top=False) -> Iterable[OrgNode]:
    """
    Converts Roam node into Org-mode representation
    """
    children = list(chain.from_iterable(map(roam_note_to_org, node.children)))

    empty = len(node.body or '') == 0 and len(children) == 0
    if empty:
        # sometimes nodes are empty. two cases:
        # - no heading -- child notes, like accidental enter presses I guess
        # - heading    -- notes that haven't been created yet
        # just don't do anything in this case
        # todo make this logic conditional?
        return

    title = node.title
    # org-mode target allows jumping straight into
    # conveniently, links in Roam are already represented as [[link]] !
    target = '' if title is None else f'<<{title}>> '
    heading = target + link(title='x', url=node.permalink)

    todo = None
    body = node.body
    if body is not None:
        for t in ('TODO', 'DONE'):
            ts = '{{[[' + t + ']]}}'
            if body.startswith(ts):
                todo = t
                body = body[len(ts):]

        body = roam_text_to_org(body)

        lines = body.splitlines(keepends=True)
        # display first link of the body as the heading
        if len(lines) > 0:
            heading = heading + ' ' + lines[0]
            body = ''.join(lines[1:])
            if len(body) == 0:
                body = None

    if top:
        heading = dt_heading(node.created, heading)

    yield OrgNode(
        todo=todo,
        heading=heading,
        body=body,
        children=children,
    )
Example #26
0
    def get_items(self) -> Mirror.Results:
        def render_highlight(h: Highlight) -> OrgNode:
            # TODO FIXME could use bookmark page??
            heading = 'bookmark' if h.kind == 'bookmark' else (h.text or '')
            body = h.annotation  # TODO check if empty
            return node(
                heading=dt_heading(h.dt, heading),
                body=body,
            )

        for page in get_books_with_highlights():
            yield str(page.book), node(
                heading=dt_heading(page.dt, str(page.book)),
                children=[render_highlight(h) for h in page.highlights],
            )
Example #27
0
 def _render(self, t: Tweet) -> OrgNode:
     dtime = t.created_at
     text = t.text
     url = t.permalink
     if self.mode == 'all':
         return node(
             heading=dt_heading(dtime, link(title=text, url=url)),
             tags=['tweet'],
         )
     else:
         dd = dtime.replace(year=today.year)
         text = '  ' + text if text.startswith('@') else text # pad replies a bit
         return node(
             heading=timestamp(dd.date(), active=True) + ' ' + f"{link(title='TW', url=url)} at {timestamp(dtime, inactive=True)} {text}",
             tags=['ttweet'],
         )
Example #28
0
 def get_items(self):
     for f in favorites():
         if isinstance(f, Favorite):
             yield node(
                 heading=dt_heading(
                     f.dt,
                     f.title if f.url is None else link(url=f.url,
                                                        title=f.title),
                 ),
                 body=f.text,
             )
         else:  # error
             yield node(
                 heading=f'ERROR!',
                 body='\n'.join(
                     traceback.format_exception(Exception, f, None)),
             )
Example #29
0
 def chit(pdf: pdfs.Pdf):
     for a in pdf.annotations:
         parts = []
         highlight = (a.highlight or '').strip()
         author = (a.author or '').strip()
         comment = (a.comment or '').strip()
         if highlight:
             parts.append(literal(highlight))
         if author:
             parts.append(f'by {author}')
         if comment:
             parts.append(comment)
         body = '\n'.join(parts)
         page1 = a.page + 1
         page_link = docview_link(path=pdf.path,
                                  title=f'page {page1}',
                                  page1=page1)
         yield node(
             dt_heading(a.created, page_link),
             body=body,
         )
Example #30
0
    def get_items(self) -> Mirror.Results:
        import my.pdfs as pdfs

        for pdf in sorted(
                pdfs.annotated_pdfs(),
                key=lambda p: datetime.min if isinstance(p, Exception) or p.
                created is None else p.created.replace(tzinfo=None),
        ):
            if isinstance(pdf, Exception):
                yield error(pdf)
                continue

            def chit(pdf: pdfs.Pdf):
                for a in pdf.annotations:
                    parts = []
                    highlight = (a.highlight or '').strip()
                    author = (a.author or '').strip()
                    comment = (a.comment or '').strip()
                    if highlight:
                        parts.append(literal(highlight))
                    if author:
                        parts.append(f'by {author}')
                    if comment:
                        parts.append(comment)
                    body = '\n'.join(parts)
                    page1 = a.page + 1
                    page_link = docview_link(path=pdf.path,
                                             title=f'page {page1}',
                                             page1=page1)
                    yield node(
                        dt_heading(a.created, page_link),
                        body=body,
                    )

            pdf_link = docview_link(path=pdf.path, title=str(
                pdf.path))  # todo would be nice to extract metadata for title
            yield node(dt_heading(pdf.created, pdf_link),
                       children=list(chit(pdf)))