def vote_update(row, row_index, staff_picked=False): """ Upvotes the highest priority contribution and updates the spreadsheet. """ url = row[2] category = row[4] account = Account(ACCOUNT) # Check if post was staff picked if staff_picked: vote_pct = MAX_VOTE[category] else: vote_pct = float(row[-1]) try: post = Comment(url, steem_instance=steem) logger.info(f"Voting on {post.authorperm} with {vote_pct}%") # If in last twelve hours before payout don't vote if valid_age(post): post.vote(vote_pct, account=account) bot_comment(post, category, account, staff_picked) reviewed.update_cell(row_index, 10, "Yes") else: reviewed.update_cell(row_index, 10, "EXPIRED") except Exception as vote_error: logger.error(vote_error)
def hundred_voter(): authors = [] with open(file=config['VOTER']['throw_votes_authors'], mode='r') as f: for line in f: line = line.replace('\n', '').replace('@', '') if len(line) >= 3: authors.append(line) random.shuffle(authors) log.info('Authors list: {}'.format(authors)) comment_body = '' if config.getboolean('VOTER', 'throw_write_comment'): with open(file=config['VOTER']['throw_comment_file'], mode='rb') as file: # loading comment text comment_body = file.read().decode('iso-8859-1') log.info('Loaded comment text.') for author in authors: try: for post in Account(author).history_reverse(stop=datetime.now() - timedelta(days=5), only_ops=['comment']): if post.get('parent_author') != '': continue a_perm = '{}/{}'.format(author, post.get('permlink')) log.info(a_perm) c = Comment(authorperm=a_perm) if a.name in c.get_votes(): log.info('Already voted.') continue log.info('Try vote on {}'.format(c.authorperm)) shared_steem_instance().wallet.unlock( config['GENERAL']['wallet_key']) c.vote(weight=config.getfloat('VOTER', 'throw_votes_pct'), account=a.name) if config.getboolean('VOTER', 'write_comment'): shared_steem_instance().post( title='', body=comment_body, author=config['GENERAL']['acc_name'], reply_identifier=c.authorperm, app='https://github.com/PortalMine/portalvotes') log.debug(shared_steem_instance().broadcast()) shared_steem_instance().wallet.lock() return True except AccountDoesNotExistsException: log.info('Account {} does not exist.'.format(author)) continue else: log.info('Nothing found to burn vote.') return False
def vote_contribution(contribution): """Votes on the contribution with a scaled weight (dependent on the contribution's category and weight). """ if "@amosbastian" in contribution.url: return weight = (float(contribution.weight) / max(constants.MAX_VOTE.values()) * 100.0) / constants.SCALER contribution = Comment(contribution.url) voters = [vote.voter for vote in contribution.get_votes()] if "amosbastian" not in voters: contribution.vote(weight, "amosbastian")
def test_vote(self): bts = self.bts c = Comment(self.authorperm, blockchain_instance=bts) bts.txbuffer.clear() tx = c.vote(100, account="test") self.assertEqual((tx["operations"][0][0]), "vote") op = tx["operations"][0][1] self.assertIn("test", op["voter"]) c.blockchain.txbuffer.clear() tx = c.upvote(weight=150, voter="test") op = tx["operations"][0][1] self.assertEqual(op["weight"], 10000) c.blockchain.txbuffer.clear() tx = c.upvote(weight=99.9, voter="test") op = tx["operations"][0][1] self.assertEqual(op["weight"], 9990) c.blockchain.txbuffer.clear() tx = c.downvote(weight=150, voter="test") op = tx["operations"][0][1] self.assertEqual(op["weight"], -10000) c.blockchain.txbuffer.clear() tx = c.downvote(weight=99.9, voter="test") op = tx["operations"][0][1] self.assertEqual(op["weight"], -9990)
def test_vote(self, node_param): if node_param == "non_appbase": bts = self.bts else: bts = self.appbase c = Comment(self.authorperm, steem_instance=bts) bts.txbuffer.clear() tx = c.vote(100, account="test") self.assertEqual((tx["operations"][0][0]), "vote") op = tx["operations"][0][1] self.assertIn("test", op["voter"]) c.steem.txbuffer.clear() tx = c.upvote(weight=150, voter="test") op = tx["operations"][0][1] self.assertEqual(op["weight"], 10000) c.steem.txbuffer.clear() tx = c.upvote(weight=99.9, voter="test") op = tx["operations"][0][1] self.assertEqual(op["weight"], 9990) c.steem.txbuffer.clear() tx = c.downvote(weight=-150, voter="test") op = tx["operations"][0][1] self.assertEqual(op["weight"], -10000) c.steem.txbuffer.clear() tx = c.downvote(weight=-99.9, voter="test") op = tx["operations"][0][1] self.assertEqual(op["weight"], -9990)
def upvote_contribution(contribution): """Upvotes the contribution with a pre-calculated weight.""" try: post = Comment(contribution["url"]) except Exception: constants.DB.pending_contributions.remove({"url": contribution["url"]}) return voters = [vote.voter for vote in post.get_votes()] if "amosbastian" in voters or "utopian-io" in voters: constants.DB_UTEMPIAN.pending_contributions.update_one( contribution, {"$set": { "upvoted": True }}) return post.vote(contribution["weight"], "amosbastian") constants.LOGGER.info((f"Upvoting contribution {contribution['url']} " f"with weight {contribution['weight']}%")) time.sleep(3)
def upvote_comment(comment): """Upvotes the contribution's moderator's comment.""" try: points = constants.CATEGORY_POINTS[comment["category"]] except KeyError: points = constants.TASK_REQUEST category_weight = points_to_weight(points) weight = (category_weight / max(constants.MAX_VOTE.values()) * 100.0) / constants.SCALER comment = Comment(comment["url"]) voters = [vote.voter for vote in comment.get_votes()] if "amosbastian" in voters or "utopian-io" in voters: constants.DB.comments.update_one(comment, {"$set": {"upvoted": True}}) comment.vote(weight, "amosbastian") constants.LOGGER.info((f"Upvoting comment {comment['url']} " f"with weight {weight}%")) time.sleep(3)
def unvote_post(row, previous, current): """ Unvotes the given post and updates the spreadsheet to reflect this. """ url = row[2] account = Account(ACCOUNT) post = Comment(url, steem_instance=steem) # Check if actually voted on post votes = [vote["voter"] for vote in post.json()["active_votes"]] if ACCOUNT not in votes: logger.info(f"Never voted on {url} in the first place!") return # Unvote the post try: logger.info(f"Unvoting {url}") post.vote(0, account=account) time.sleep(3) # Edit comment update_comment(post) except Exception as error: logger.error(error) # Just in case sheet was updated in the meantime previous_reviewed = sheet.worksheet(title_previous) current_reviewed = sheet.worksheet(title_current) # Update row depending on which sheet it's in if row in previous: row_index = previous.index(row) + 1 previous_reviewed.update_cell(row_index, 10, "Unvoted") previous_reviewed.update_cell(row_index, 11, 0) elif row in current: row_index = current.index(row) + 1 current_reviewed.update_cell(row_index, 10, "Unvoted") current_reviewed.update_cell(row_index, 11, 0)
vote = a.get_voting_value_SBD(not_broadcasted_vote=False) value -= vote sbd_amount = value / multiplier log.info('Payback is {} SBD'.format(sbd_amount)) if transfer['amount']['nai'] == "@@000000013": a.transfer(transfer['from'], sbd_amount, transfer['amount']['nai'], "Couldn't vote full amount. So here is your refund.") log.info('Refunded {} SBD.'.format(sbd_amount)) else: a.transfer(transfer['from'], to_steem(sbd_amount), transfer['amount']['nai'], "Couldn't vote full amount. So here is your refund.") log.info('Refunded {} STEEM.'.format(to_steem(sbd_amount))) log.info('Not full value voted.') c.vote(weight, a.name) log.info('Voted {} STU'.format(vote)) if config.getboolean('VOTING', 'reply'): try: with open(config['VOTING']['comment_file']) as f: body = f.read().format(percent=weight, name=a.name, by=transfer['from']) except FileNotFoundError: body = 'You just rose a {percent}% upvote from @{name} in courtesy of @{by}.'\ .format(percent=weight, name=a.name, by=transfer['from']) log.info(body) shared_steem_instance().post(body=body, author=a.name, reply_identifier=c.authorperm, app='@curationhelper by @portalmine',