decrypt memos from an account and store them in a csv file

in #python6 years ago
#!/usr/bin/python
from beem import Steem
from beem.memo import Memo
from beem.account import Account
from beem.amount import Amount
import getpass
import six
import csv


if __name__ == "__main__":
    if six.PY3:
        account = input("Enter account name: ")
    else:
        account = raw_input("Enter account name: ")    
    memo_wif = getpass.getpass(prompt='Enter the memo key of %s:' % account)
    stm = Steem(keys=[memo_wif])
    acc = Account(account, steem_instance=stm)
    with open('encrypted_memos.csv', mode='w') as csv_file:
        fieldnames = ['timestamp', 'from', 'to', 'amount', 'decrypted_memo']
        writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
        writer.writeheader()
        for h in acc.history_reverse(only_ops=["transfer"]):
            if len(h["memo"]) < 2:
                continue
            if h["memo"][0] != '#':
                continue
            memo = Memo(from_account=h["from"], to_account=h["to"], steem_instance=stm)
            try:
                decrypted_memo = memo.decrypt(h["memo"])
            except:
                decrypted_memo = "decryption failed."
            amount = Amount(h["amount"], steem_instance=stm)
            print("%s - from: %s, to: %s, amount: %s, decr. text: %s" % (h["timestamp"], h["from"], h["to"], str(amount), decrypted_memo))
            writer.writerow({"timestamp": h["timestamp"], "from": h["from"], "to": h["to"], "amount": str(amount), "decrypted_memo": decrypted_memo})
Sort:  

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

You published your First Post

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

Do not miss the last post from @steemitboard:

Meet the Steemians Contest - The results, the winners and the prizes
Meet the Steemians Contest - Special attendees revealed
Meet the Steemians Contest - Intermediate results

Support SteemitBoard's project! Vote for its witness and get one more award!

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

You got a First Vote

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

Do not miss the last post from @steemitboard:

Meet the Steemians Contest - The results, the winners and the prizes
Meet the Steemians Contest - Special attendees revealed
Meet the Steemians Contest - Intermediate results

Support SteemitBoard's project! Vote for its witness and get one more award!