Fixing Profile Query due to API Change in SteemIt

in #witness-update5 years ago (edited)

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.

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)

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

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!

image.png
image.png

// https://helloacm.com/fixing-profile-query-commadn-due-to-api-change-in-steem-blockchain/

Enjoy and Steem On!

Delegate to @justyy

@justyy runs a automatic delegation service for a long time. Delegate to @justyy for at least 5 SP and start receiving daily payout as interests (from 8% to 10% APR). Also, as a supporter, the delegators will start to receive complimentary/curation upvotes (as a thank you) per day from e.g @justyy and a few other curation trails. For more information, read this. The voting weight algorithm is open source.

image.png

@justyy is the 7-th delegated project on steem blockchain

Please note that the SP you enter is the final amount to delegate. For example, if you already delegate 10 SP and you want to delegate another 5 SP, you will need to enter 15 SP (instead of 5 SP) in the delegation form.

Vote for me or Set me as a witness Proxy - Every vote counts! - Thank you!

Your Vote is much appreciated, and every vote counts.

Check out My Witness Page

Support me and my work as a witness - witness thread by

  1. voting me here, or
  2. voting me as a witness proxy - let @justyy represent you.

Thank you! Some of My Contributions: SteemYY.com - SteemIt Tutorials, Robots, Tools and APIs and VPS Search Tool

Happy New Year to all Steemians! I wish the Steem Price Go Rocket in 2019!

image.png

Sort:  

Congratulations @justyy! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made more than 57000 upvotes. Your next target is to reach 58000 upvotes.

Click here to view your Board
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Do not miss the last post from @steemitboard:

SteemWhales has officially moved to SteemitBoard Ranking
SteemitBoard - Witness Update

You can upvote this notification to help all Steemit users. Learn why here!

Hi @justyy!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your UA account score is currently 6.869 which ranks you at #98 across all Steem accounts.
Your rank has dropped 1 places in the last three days (old rank 97).

In our last Algorithmic Curation Round, consisting of 257 contributions, your post is ranked at #28.

Evaluation of your UA score:
  • You've built up a nice network.
  • The readers like your work!
  • Good user engagement!

Feel free to join our @steem-ua Discord server

This post has been included in the latest edition of SOS Daily News - a digest of all you need to know about the State of Steem.



Coin Marketplace

STEEM 0.29
TRX 0.12
JST 0.033
BTC 63016.70
ETH 3028.58
USDT 1.00
SBD 3.75