diff --git a/beem/cli.py b/beem/cli.py index 201465884fbaad43cf6cbbd930777d7f9680d476..90207dca631abd56691d7904be015a8e3301dc49 100644 --- a/beem/cli.py +++ b/beem/cli.py @@ -720,10 +720,9 @@ def listaccounts(): @cli.command() @click.argument('post', nargs=1) -@click.argument('vote_weight', nargs=1, required=False) @click.option('--weight', '-w', help='Vote weight (from 0.1 to 100.0)') @click.option('--account', '-a', help='Voter account name') -def upvote(post, vote_weight, account, weight): +def upvote(post, account, weight): """Upvote a post/comment POST is @author/permlink @@ -731,18 +730,17 @@ def upvote(post, vote_weight, account, weight): stm = shared_steem_instance() if stm.rpc is not None: stm.rpc.rpcconnect() - if not weight and vote_weight: - weight = vote_weight - if not weight.replace('.', '', 1).isdigit(): - raise ValueError("vote_weight must be a float!") - else: - weight = float(weight) - if weight > 100: - raise ValueError("Maximum vote weight is 100.0!") - elif weight < -100: - raise ValueError("Minimum vote weight is -100.0!") - elif not weight and not vote_weight: - weight = stm.config["default_vote_weight"] + if not weight: + weight = stm.config["default_vote_weight"] + elif not weight.replace('.', '', 1).isdigit(): + raise ValueError("vote_weight must be a float!") + else: + weight = float(weight) + if weight > 100: + raise ValueError("Maximum vote weight is 100.0!") + elif weight < -100: + raise ValueError("Minimum vote weight is -100.0!") + if not account: account = stm.config["default_account"] if not unlock_wallet(stm): @@ -761,10 +759,9 @@ def upvote(post, vote_weight, account, weight): @cli.command() @click.argument('post', nargs=1) -@click.argument('vote_weight', nargs=1, required=False) @click.option('--account', '-a', help='Voter account name') -@click.option('--weight', '-w', default=100.0, help='Vote weight (from 0.1 to 100.0)') -def downvote(post, vote_weight, account, weight): +@click.option('--weight', '-w', default=100, help='Downvote weight (from 0.1 to 100.0)') +def downvote(post, account, weight): """Downvote a post/comment POST is @author/permlink @@ -772,18 +769,15 @@ def downvote(post, vote_weight, account, weight): stm = shared_steem_instance() if stm.rpc is not None: stm.rpc.rpcconnect() - if not weight and vote_weight: - weight = vote_weight - if not weight.replace('.', '', 1).isdigit(): - raise ValueError("vote_weight must be a float!") - else: - weight = float(weight) - if weight > 100: - raise ValueError("Maximum vote weight is 100.0!") - elif weight < -100: - raise ValueError("Minimum vote weight is -100.0!") - elif not weight and not vote_weight: - weight = stm.config["default_vote_weight"] + if not weight.replace('.', '', 1).isdigit(): + raise ValueError("vote_weight must be a float!") + else: + weight = float(weight) + if weight > 100: + raise ValueError("Maximum vote weight is 100.0!") + elif weight < -100: + raise ValueError("Minimum vote weight is -100.0!") + if not account: account = stm.config["default_account"] if not unlock_wallet(stm): diff --git a/beem/comment.py b/beem/comment.py index 43520ad32741103ae957063a279435dbdadac1a0..570dc893afc04279b4385efae693eed65f0070ee 100644 --- a/beem/comment.py +++ b/beem/comment.py @@ -145,7 +145,10 @@ class Comment(BlockchainObject): [author, permlink] = resolve_authorperm(self.identifier) self.steem.rpc.set_next_node_on_empty_reply(True) if self.steem.rpc.get_use_appbase(): - content = self.steem.rpc.get_discussion({'author': author, 'permlink': permlink}, api="tags") + try: + content = self.steem.rpc.get_discussion({'author': author, 'permlink': permlink}, api="tags") + except: + content = self.steem.rpc.get_content(author, permlink) else: content = self.steem.rpc.get_content(author, permlink) if not content or not content['author'] or not content['permlink']: @@ -627,33 +630,10 @@ class Comment(BlockchainObject): form ``@author/permlink``. """ - if not account: - if "default_account" in self.steem.config: - account = self.steem.config["default_account"] - if not account: - raise ValueError("You need to provide an account") - account = Account(account, steem_instance=self.steem) if not identifier: - post_author = self["author"] - post_permlink = self["permlink"] - else: - [post_author, post_permlink] = resolve_authorperm(identifier) + identifier = construct_authorperm(self["author"], self["permlink"]) - vote_weight = int(float(weight) * STEEM_1_PERCENT) - if vote_weight > STEEM_100_PERCENT: - vote_weight = STEEM_100_PERCENT - if vote_weight < -STEEM_100_PERCENT: - vote_weight = -STEEM_100_PERCENT - - op = operations.Vote( - **{ - "voter": account["name"], - "author": post_author, - "permlink": post_permlink, - "weight": vote_weight - }) - - return self.steem.finalizeOp(op, account, "posting", **kwargs) + return self.steem.vote(weight, identifier, account=account) def edit(self, body, meta=None, replace=False): """ Edit an existing post diff --git a/beem/steem.py b/beem/steem.py index fe7173deff2f54771a2f2a4aa66babbfe889c06c..ea2196eb1e97d9cdefffda2a080c09ec24bc7493 100644 --- a/beem/steem.py +++ b/beem/steem.py @@ -1817,6 +1817,42 @@ class Steem(object): return self.finalizeOp(ops, account, "posting", **kwargs) + def vote(self, weight, identifier, account=None, **kwargs): + """ Vote for a post + + :param float weight: Voting weight. Range: -100.0 - +100.0. + :param str identifier: Identifier for the post to vote. Takes the + form ``@author/permlink``. + :param str account: (optional) Account to use for voting. If + ``account`` is not defined, the ``default_account`` will be used + or a ValueError will be raised + + """ + if not account: + if "default_account" in self.config: + account = self.config["default_account"] + if not account: + raise ValueError("You need to provide an account") + account = Account(account, steem_instance=self) + + [post_author, post_permlink] = resolve_authorperm(identifier) + + vote_weight = int(float(weight) * STEEM_1_PERCENT) + if vote_weight > STEEM_100_PERCENT: + vote_weight = STEEM_100_PERCENT + if vote_weight < -STEEM_100_PERCENT: + vote_weight = -STEEM_100_PERCENT + + op = operations.Vote( + **{ + "voter": account["name"], + "author": post_author, + "permlink": post_permlink, + "weight": vote_weight + }) + + return self.finalizeOp(op, account, "posting", **kwargs) + def comment_options(self, options, identifier, beneficiaries=[], account=None, **kwargs): """ Set the comment options diff --git a/beem/version.py b/beem/version.py index bb3e0bd30ad17c91434ef5e04ac0c9388d2192d3..90ce00a744fc77ac04c7005f9f0d748773c492c6 100644 --- a/beem/version.py +++ b/beem/version.py @@ -1,2 +1,2 @@ """THIS FILE IS GENERATED FROM beem SETUP.PY.""" -version = '0.20.21' +version = '0.20.22' diff --git a/beemapi/version.py b/beemapi/version.py index bb3e0bd30ad17c91434ef5e04ac0c9388d2192d3..90ce00a744fc77ac04c7005f9f0d748773c492c6 100644 --- a/beemapi/version.py +++ b/beemapi/version.py @@ -1,2 +1,2 @@ """THIS FILE IS GENERATED FROM beem SETUP.PY.""" -version = '0.20.21' +version = '0.20.22' diff --git a/beembase/version.py b/beembase/version.py index bb3e0bd30ad17c91434ef5e04ac0c9388d2192d3..90ce00a744fc77ac04c7005f9f0d748773c492c6 100644 --- a/beembase/version.py +++ b/beembase/version.py @@ -1,2 +1,2 @@ """THIS FILE IS GENERATED FROM beem SETUP.PY.""" -version = '0.20.21' +version = '0.20.22' diff --git a/beemgraphenebase/version.py b/beemgraphenebase/version.py index bb3e0bd30ad17c91434ef5e04ac0c9388d2192d3..90ce00a744fc77ac04c7005f9f0d748773c492c6 100644 --- a/beemgraphenebase/version.py +++ b/beemgraphenebase/version.py @@ -1,2 +1,2 @@ """THIS FILE IS GENERATED FROM beem SETUP.PY.""" -version = '0.20.21' +version = '0.20.22' diff --git a/setup.py b/setup.py index 1451c567c13c6007b2dcb702325015217fa95aa4..437d5e7c38c72173e7c32f487f16d3cf6ec40210 100755 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ except LookupError: ascii = codecs.lookup('ascii') codecs.register(lambda name, enc=ascii: {True: enc}.get(name == 'mbcs')) -VERSION = '0.20.21' +VERSION = '0.20.22' tests_require = ['mock >= 2.0.0', 'pytest', 'pytest-mock', 'parameterized'] diff --git a/tests/beem/test_discussions.py b/tests/beem/test_discussions.py index fefb9d3ef9f5fa3e6b818eb7da95d04aff4811cb..0192f2122aa6e2856ff0b1c031a8f80be03c80fe 100644 --- a/tests/beem/test_discussions.py +++ b/tests/beem/test_discussions.py @@ -131,12 +131,12 @@ class Testcases(unittest.TestCase): def test_promoted(self): bts = self.bts query = Query() - query["limit"] = 10 + query["limit"] = 1 query["tag"] = "steemit" d = Discussions_by_promoted(query, steem_instance=bts) discussions = Discussions(steem_instance=bts) d2 = [] for dd in discussions.get_discussions("promoted", query, limit=10): d2.append(dd) - self.assertEqual(len(d), 10) - self.assertEqual(len(d2), 10) + self.assertEqual(len(d), 1) + self.assertEqual(len(d2), 1)