스팀잇 개발 2 - @booming-kr Phase 2.5 를 위한 댓글 보팅 기능

in #kr13 days ago

✅ 조건 요약:
• A 계정의 포스팅이 있음
• B 계정이 그 포스팅에:
1. 댓글을 달고
2. 보팅도 하는 경우
• 그러면 A 계정이 자동으로 그 댓글에 full vote(보팅)

⚙️ 전제 사항
• 이 코드는 A 계정에서 실행됨 (자동 보팅 주체)
• A 계정의 posting key가 필요함
• Python beem 라이브러리 사용

코드

from beem import Steem
from beem.comment import Comment
from beem.blockchain import Blockchain
from beem.account import Account
from beem.instance import set_shared_steem_instance
import time

A 계정 정보

my_account = "A_account" # A 계정 ID
my_posting_key = "your_posting_key" # A 계정 posting key

세팅

stm = Steem(keys=[my_posting_key])
set_shared_steem_instance(stm)
bchain = Blockchain(mode="head")
account = Account(my_account)

중복 방지

voted_comment_ids = set()

def is_reply_to_my_post(comment):
return comment["parent_author"] == my_account

def is_voted_by_author(comment):
"""B 계정이 자기 댓글에 이미 보팅했는지 확인"""
author = comment["author"]
permlink = comment["permlink"]
c = Comment(f"@{author}/{permlink}")
for vote in c["active_votes"]:
if vote["voter"] == author and float(vote["percent"]) > 0:
return True
return False

def auto_vote_on_valid_comments():
stream = bchain.stream(opNames=["comment"], raw_ops=False)
print(f"🔁 Auto voting bot activated for @{my_account}")

for comment in stream:
    try:
        comment_id = f"{comment['author']}/{comment['permlink']}"
        if comment_id in voted_comment_ids:
            continue

        # 1. A 계정 글에 달린 댓글인지
        if not is_reply_to_my_post(comment):
            continue

        # 2. B 계정이 자기가 쓴 댓글에 보팅했는지
        if not is_voted_by_author(comment):
            continue

        # 3. 보팅 수행
        c = Comment(f"@{comment['author']}/{comment['permlink']}")
        c.upvote(weight=100.0, voter=my_account)
        print(f"[VOTE] @{my_account} voted on @{comment['author']}/{comment['permlink']}")
        voted_comment_ids.add(comment_id)
    
    except Exception as e:
        print(f"[ERROR] Failed to process comment: {e}")
    
    time.sleep(2)

실행

auto_vote_on_valid_comments()

Sort:  

[광고] STEEM 개발자 커뮤니티에 참여 하시면, 다양한 혜택을 받을 수 있습니다.

Upvoted! Thank you for supporting witness @jswit.