Exemple #1
0
    def _add_to_posts_db(self, author_id, req):
        self._logger.debug("Calling article service with new foreign article")

        # check if in posts db
        article = get_article(self._logger, self._db_stub, ap_id=req.id)
        if article is not None:
            return True

        # set flag in article service that is foreign (so no need to create service)
        na = article_pb2.NewArticle(
            author_id=author_id,
            title=req.title,
            body=req.content,
            creation_datetime=req.published,
            foreign=True,
            ap_id=req.id,
            summary=req.summary,
        )
        article_resp = self._article_stub.CreateNewArticle(na)
        if article_resp.result_type == article_pb2.NewArticleResponse.ERROR:
            self._logger.error(
                "New foreign article creation returned error: %s",
                article_resp.error
            )
            return False
        return True
 def create_post(self, author, req):
     self._logger.debug("Calling article service with new foreign article")
     # set flag in article service that is foreign (so no need to create service)
     na = article_pb2.NewArticle(
         author_id=author.global_id,
         title=req.title,
         body=req.body,
         creation_datetime=req.published,
         foreign=True,
         ap_id=req.announced_object,
     )
     article_resp = self._article_stub.CreateNewArticle(na)
     if article_resp.result_type == article_pb2.NewArticleResponse.ERROR:
         self._logger.error(
             "New foreign article creation returned error: %s",
             article_resp.error)
         return None
     article, err = self._activ_util.get_article_by_ap_id(
         req.announced_object)
     if err is not None:
         self._logger.error(
             "Could not find new article ap_id: % after creation: %s",
             req.announced_object, err)
         return None
     return article
Exemple #3
0
 def PreviewArticle(self, req, context):
     self._logger.info('Recieved a new article to Preview.')
     html_body = md_to_html(self._md_stub, req.body)
     na = article_pb2.NewArticle(author_id=req.author_id,
                                 title=req.title,
                                 body=html_body,
                                 creation_datetime=req.creation_datetime)
     resp = article_pb2.PreviewResponse(
         preview=na, result_type=general_pb2.ResultType.OK)
     return resp