获取专栏的所有文章.

        :return: 专栏所有文章，返回生成器
        :rtype: Post.Iterable
974399
def posts(self):
        
        origin_host = self._session.headers.get('Host')
        for offset in range(0, (self.post_num - 1) // 10 + 1):
            self._session.headers.update(Host='zhuanlan.zhihu.com')
            res = self._session.get(
                Column_Posts_Data.format(self._in_name, offset * 10))
            soup = res.json()
            self._session.headers.update(Host=origin_host)
            for post in soup:
                yield self._parse_post_data(post)
639000
def contents(self):
        
        if not hasattr(self, "_content"):
            self._content = self.get_content()
        return self._content
975692
def getSRTemplates(self):
        
        this_dir = os.path.dirname(os.path.abspath(__file__))
        templates_dir = os.path.join(this_dir, self._TEMPLATES_DIR)
        tempath = '%s/%s' % (templates_dir, '*.pt')
        templates = [t.split('/')[-1] for t in glob.glob(tempath)]
        out = []
        for template in templates:
            out.append({'id': template, 'title': template[:-3]})
        for templates_resource in iterDirectoriesOfType(self._TEMPLATES_ADDON_DIR):
            prefix = templates_resource.__name__
            templates = [
                tpl for tpl in templates_resource.listDirectory()
                if tpl.endswith('.pt')
                ]
            for template in templates:
                out.append({
                    'id': '{0}:{1}'.format(prefix, template),
                    'title': '{0} ({1})'.format(template[:-3], prefix),
                })
        return out
1142592
def find(self):
        
        content = self._do_request(self.dump())

        objs = []
        for result in content['results']:
            obj = self._new_object()
            obj._update_data(self._process_result(result))
            objs.append(obj)

        return objs
121279
def retrieve_posts(dir)
      return if outside_configured_directory?(dir)

      site.posts.docs.concat(post_reader.read_posts(dir))
      site.posts.docs.concat(post_reader.read_drafts(dir)) if site.show_drafts
    end
1338395
def views(self):
        
        if self._views:
            return self._views
        elif not self.abstract:
            return self.read_meta()._views

        raise EmptyDocumentException()
1204848
def get_posts(self, include_draft=False, filter_functions=None):
        

        def posts_generator(path):
            """Loads valid posts one by one in the given path."""
            if os.path.isdir(path):
                for file in os.listdir(path):
                    filename, ext = os.path.splitext(file)
                    format_name = get_standard_format_name(ext[1:])
                    if format_name is not None and re.match(
                            r'\d{4}-\d{2}-\d{2}-.+', filename):
                        # the format is supported and the filename is valid,
                        # so load this post
                        post = Post()
                        post.format = format_name
                        post.meta, post.raw_content = FileStorage.read_file(
                            os.path.join(path, file))
                        post.rel_url = filename.replace('-', '/', 3) + '/'
                        post.unique_key = '/post/' + post.rel_url
                        yield post

        posts_path = os.path.join(current_app.instance_path, 'posts')
        result = filter(lambda p: include_draft or not p.is_draft,
                        posts_generator(posts_path))
        result = self._filter_result(result, filter_functions)

        return sorted(result, key=lambda p: p.created, reverse=True)
321965
def files(self):
        """"""
        if self.topic.has_file:
            yield self.topic.file.file_url
        for reply in self.replies:
            if reply.has_file:
                yield reply.file.file_url
1003048
def run(self):
        
        document = {}
        document['_id'] = hashlib.sha1('%s:%s' % (
                                       self.date, self.url)).hexdigest()
        with self.input().open() as handle:
            document['content'] = handle.read().decode('utf-8', 'ignore')
        document['url'] = self.url
        document['date'] = unicode(self.date)
        with self.output().open('w') as output:
            output.write(json.dumps(document))
622860
def proceed(self):
        
        self._parse()
        for e in self.docs_list:
            e['docs'].generate_docs()
        return self.docs_list
1164568
def to_url(self):
        
        if self.__collection_format == 'multi':
            return [str(s) for s in self]
        else:
            return [str(self)]
421957
def entries(self):
        """"""
        Tags = Query()
        tag = self.table.get(Tags.name == self.name)
        posts = tag['post_ids']

        for id in posts:
            post = self.db.posts.get(doc_id=id)
            if not post:  # pragma: no coverage
                raise ValueError("No post found for doc_id %s" % id)
            yield Entry(os.path.join(CONFIG['content_root'], post['filename']), id)
1257930
def get_files():
    

    files_root = path.join(path.dirname(__file__), 'files')

    for root, dirs, files in walk(files_root):
        rel_root = path.relpath(root, files_root)

        for file_name in files:
            try:
                f = open(path.join(root, file_name), 'r', encoding='utf-8')
                with f:
                    yield rel_root, file_name, f.read(), True
            except UnicodeError:
                f = open(path.join(root, file_name), 'rb')
                with f:
                    yield rel_root, file_name, f.read(), False
85334
def file_handles(self) -> Iterable[IO[str]]:
        
        if self.file_handle:
            yield self.file_handle
            self.file_handle.close()
            self.file_handle = None
        else:
            for name in self.file_names():
                with open(name, "r") as f:
                    yield f
1219971
def list_documents(self, limit=None):
        
        from itertools import chain

        return chain(self.backend.dataset_index.list_documents(limit=limit),
                     self.backend.partition_index.list_documents(limit=limit),
                     self.backend.identifier_index.list_documents(limit=limit))
312215
def post_document(self, data):
    
    data.update({ 'client' : CLIENT })
    return self._call('POST', self._generate_url_path('documents'), data)
183007
def forms(self):
        
        forms = MultiDict()
        for name, item in self.POST.iterallitems():
            if not hasattr(item, 'filename'):
                forms[name] = item
        return forms