How to write all decrypted memos into a csv-file

in #steemdev7 years ago (edited)

As far as I know it is not possible to search encrypted memos. What to do when I want to go through all me sent and received transfers containing an encrypted memo text?


image.png

The following script uses beem. More information about installing this can be found on the github site.

The following script asks for a username and a memo key. Then it go through the complete account history and decrypts all encrypted transfer memos. The decrypted text is printed and stored into a csv file.

Store the following lines into a file decrypt_memos.py.

#!/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})

The script can then be started by:

python decrypt_memos.py

or

python3 decrypt_memos.py

The script generates an output as:

2018-10-13T07:00:21 - from: beembot, to: holger80, amount: 0.001 SBD, decr. text: This is a test

and writes all memos in a csv-file "encrypted_memos.csv".


image source

Sort:  

$rewarding 10% 13min

🏆 Hi @holger80! You have received 0.15 SBD reward for this post from the following subscribers: @cardboard
More about the subscription feature can be found here :)

Okay, now I definitely have to learn to use beem..^^
I really need some old messages.

This post has been just added as new item to timeline of beem on Steem Projects.

If you want to be notified about new updates from this project, register on Steem Projects and add beem to your favorite projects.

Business idea: decryption service:)

Hi, @holger80!

You just got a 1.43% upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in here to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.

Hi @holger80!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your UA account score is currently 7.236 which ranks you at #69 across all Steem accounts.
Your rank has not changed in the last three days.

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

Evaluation of your UA score:
  • Your follower network is great!
  • The readers appreciate your great work!
  • Good user engagement!

Feel free to join our @steem-ua Discord server

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

You received more than 3000 as payout for your posts. Your next target is to reach a total payout of 4000

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:

The Meet the Steemians Contest is over - Results are coming soon ...

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

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

You made more than 500 comments. Your next target is to reach 600 comments.

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!