You are viewing a single comment's thread from:

RE: [DA series - Learn Python with Steem #12] Steem 小工具DIY #4 投票幫手

# 获取vp百分比
def get_voting_power_per(account_data):
    last_vote_time = parse(account_data["last_vote_time"])
    diff_in_seconds = (datetime.utcnow() - last_vote_time).seconds
    regenerated_vp = diff_in_seconds * 10000 / 86400 / 5
    total_vp = (account_data["voting_power"] + regenerated_vp) / 100
    if total_vp > 100:
        return 100
    return total_vp

from dateutil.parser import parse
from datetime import datetime
from steem import Steem
from steem.blog import Blog
from pprint import pprint

target_username=input('被赞用户ID:')
account_name=input('你的用户ID: ')
identifier_list=[]# 记录需要点赞的文章识别码
title_list=[]# 记录需要点赞的标题
blog = Blog(target_username)
all_data = blog.all()
for post in all_data:
    # if post['total_payout_value']['amount']==0:# 偷懒用支付金额判定文章是否结算,临近7天未结算点赞s.commit.vote会报错
    if datetime.utcnow().day-post['created'].day<5:# 用当前时间减去文章发布时间判定
        if account_name in [active_vote['voter']for active_vote in post['active_votes']]:
            continue
        else:
            title_list.append(post['title'])
            print(post['title'])
            identifier_list.append(post['identifier'])
    else:
        break
dictionary=dict(zip(identifier_list, title_list))
if len(identifier_list)>0:
    print('{}结算前未点赞的文章数量:{}'.format(target_username, len(identifier_list)))
else:
    exit(0)
while True:
    try:
        vote_weight=float(input('点赞力度:'))
        voting_power=float(input('vp值高于多少百分比点赞:'))
        break
    except ValueError:
        print('浮点型纯数字!!')
        continue
account_postkey=input('Posting Key:')
s = Steem("https://api.steemit.com", keys=[account_postkey])
for identifier in identifier_list:
    voting_power_per=get_voting_power_per(Steem().get_account(account_name))
    if voting_power_per>voting_power:
        s.commit.vote(identifier,vote_weight,account=account_name)
        print('^{}'.format(dictionary[identifier]))
    else:
        print('vp不够了!')
        exit(0)

好了强迫症受不了报错,老老实实去减发帖时间,来交作业了~