예제 #1
0
 def _render_level(subdir, path='', indent='  '):
     if subdir:
         folder_icon = "fa-plus-square-o" if path == tag_prefix else "fa-plus-square-o"
         hidden = 'style="display: none;"' if path != tag_prefix else ''
         ul = indent + '<ul>\n'
         if isinstance(subdir, dict):
             for k in sorted(subdir.keys(), key=str.lower):
                 if k:
                     v = subdir[k]
                     uk = ThreadStore.tag_unescape(k).rstrip(':')
                     count = v.pop('_count')  # TODO: handle case when no counts pulled, will have empty leafs and leaf lists
                     item = '<span tag="%s">%s</span> <span class="item-count">%s</span></span>' % (path + k, uk, count)
                     if v:
                         ul += indent + '  <li %s><span class="folder-item"><i class="tree-folder fa %s"></i>%s</span>\n' % (hidden, folder_icon, item)
                         ul += _render_level(v, path + k + ('.' if k[-1] != ':' else ''), indent + '    ')
                     else:
                         ul += indent + '  <li %s>%s\n' % (hidden, item)
                     ul += indent + '  </li>\n'
         elif isinstance(subdir, list):
             for v in sorted(subdir, key=str.lower):
                 ul += indent + '  <li %s><span tag="%s">%s</span>\n' % (hidden, path + v, ThreadStore.tag_unescape(v))
                 ul += indent + '  </li>\n'
         return ul + indent + '</ul>\n'
     else:
         return ''
예제 #2
0
 def _create_feed(self, posts, title='', subtitle='', updated=None):
     # connect to threadstore
     ts = ThreadStoreClient.instance().blocking_threadstore  # TODO: make async
     title = ThreadStore.tag_escape(title)
     if not self.collection:
         # construct feed collection name
         self.collection = 'threadreader.feeds.%s.%s' % (self.user, title)
     # construct feed tag, for now just escaped title if not supplied
     if not self.feed_tag:
         self.feed_tag = 'feed:' + title
     self.tags.append(self.feed_tag)
     # build or update feed collection
     try:
         col_id = ts.get_collection(self.collection)['_id']
         # TODO: should ensure existing collection is from same feed_url, in case titles from two feeds are the same
     except ItemNotFound:
         col_id = ts.create_collection(self.collection, user=self.user)['_id']
     ts.update_collection(dict(_id=col_id,
                               title=title,
                               subtitle=subtitle,
                               feed_tag=self.feed_tag,
                               feed_url=self.feed_url,
                               seed_url=self.seed_url,
                               updated=dateutil.parser.parse(updated) if updated else None,
                               ))
     # TODO: get & cache favicon.ico
     # add feed entry posts
     for post in posts:
         ts.create_post(col_id, user='******', body=post, tags=self.tags)
예제 #3
0
 def home_feed(self, item):
     "extract home feed"
     # strip threadreader.feeds.<user> & unescape
     return ThreadStore.tag_unescape('.'.join(item['_collection'].split('.')[3:]))