Example #1
0
 def _get_root_identifier(self, post=None):
     if not post:
         post = self
     m = re.match("/([^/]*)/@([^/]*)/([^#]*).*", post.get("url", ""))
     if not m:
         return "", ""
     else:
         category = m.group(1)
         author = m.group(2)
         permlink = m.group(3)
         return construct_identifier(author, permlink), category
Example #2
0
    def edit(self, body, meta=None, replace=False):
        """ Edit an existing post

            :param str body: Body of the reply
            :param json meta: JSON meta object that can be attached to the
                              post. (optional)
            :param bool replace: Instead of calculating a *diff*, replace
                                 the post entirely (defaults to ``False``)
        """
        if not meta:
            meta = {}
        original_post = self

        if replace:
            newbody = body
        else:
            import diff_match_patch
            dmp = diff_match_patch.diff_match_patch()
            patch = dmp.patch_make(original_post["body"], body)
            newbody = dmp.patch_toText(patch)

            if not newbody:
                log.info("No changes made! Skipping ...")
                return

        reply_identifier = construct_identifier(
            original_post["parent_author"],
            original_post["parent_permlink"]
        )

        new_meta = {}
        if meta:
            if original_post["json_metadata"]:
                import json
                new_meta = original_post["json_metadata"].update(meta)
            else:
                new_meta = meta

        return self.commit.post(
            original_post["title"],
            newbody,
            reply_identifier=reply_identifier,
            author=original_post["author"],
            permlink=original_post["permlink"],
            json_metadata=new_meta,
        )
Example #3
0
    def __init__(self, post, steemd_instance=None):
        self.steemd = steemd_instance or shared_steemd_instance()
        self.commit = Commit(steemd_instance=self.steemd)

        # will set these during refresh()
        self.patched = False
        self.category = None
        self.root_identifier = None

        if isinstance(post, str):  # From identifier
            self.identifier = self.parse_identifier(post)
        elif isinstance(post, dict) and "author" in post and "permlink" in post:
            self.identifier = construct_identifier(post["author"], post["permlink"])
        else:
            raise ValueError("Post expects an identifier or a dict "
                             "with author and permlink!")

        self.refresh()
Example #4
0
 def test_constructIdentifier(self):
     self.assertEqual(construct_identifier("A", "B"), "@A/B")