Fixing Profile Query Command due to API Change in Steem Blockchain


Due to an API change in SteemIt see this post, the following code to get the last vote time is not working any more – as it says the API is depreciated.

1
2
3
acc = Account(id, steemd_instance = steem)
av = acc.get_account_votes()
account['last_vote_time'] = av[-1]['time']
acc = Account(id, steemd_instance = steem)
av = acc.get_account_votes()
account['last_vote_time'] = av[-1]['time']

The last vote time is useful to get the current VP for a user (the last recorded voting power + the VP restored since)

1
2
3
4
5
6
vot = av[-1]['time']  
vot = datetime.datetime.strptime(vot, '%Y-%m-%dT%H:%M:%S')
vot = time.mktime(vot.timetuple())
tnow = datetime.datetime.utcnow().timestamp()
dif = (((tnow-vot) / 60) * 0.0139) + account_vp
account['vp'] = min(100, dif)
vot = av[-1]['time']  
vot = datetime.datetime.strptime(vot, '%Y-%m-%dT%H:%M:%S')
vot = time.mktime(vot.timetuple())
tnow = datetime.datetime.utcnow().timestamp()
dif = (((tnow-vot) / 60) * 0.0139) + account_vp
account['vp'] = min(100, dif)

There is no easy way to get last voted time. You can scan the account history in reverse order and look for the voting action.

Thanks to steemsql, I have replaced this bit using a simple SQL

1
2
3
4
5
6
7
8
9
10
11
12
def get_last_vote_time(id):
  global cursor
     
  sql = "select top 1 timestamp from TxVotes (NOLOCK) where voter='" + id.strip() + "' order by timestamp desc"
  cursor.execute(sql)
 
  while 1:
    row = cursor.fetchone()
    if not row:
      break
    return row[0].strftime("%Y-%m-%d %H:%M:%S")
  return None 
def get_last_vote_time(id):
  global cursor
     
  sql = "select top 1 timestamp from TxVotes (NOLOCK) where voter='" + id.strip() + "' order by timestamp desc"
  cursor.execute(sql)

  while 1:
    row = cursor.fetchone()
    if not row:
      break
    return row[0].strftime("%Y-%m-%d %H:%M:%S")
  return None 

So the services for querying the profile using Discord Bot or Wechat Bot has been fixed!

discord-steemit-bot Fixing Profile Query Command due to API Change in Steem Blockchain API blockchain python SteemIt

discord-steemit-bot

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
326 words
Last Post: Bash Command to Find Out the IPs that Hit Your Server
Next Post: How to Find the Kth Smallest Element in a BST Tree Using Java/C++?

The Permanent URL is: Fixing Profile Query Command due to API Change in Steem Blockchain

Leave a Reply