How to write all decrypted memos into a csv-file
steemdev·@holger80·
0.000 HBDHow to write all decrypted memos into a csv-file
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?
<center>

</center>
The following script uses [beem](https://github.com/holgern/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](https://pixabay.com/de/computer-verschl%C3%BCsseln-1294045/)👍 lukasmining, literaturkritik, linkerstinker, nurah, upgoat, samlee2018, wstanley226, arslanyasir, upcroak, bubbleburst, funanime, funkyfun, dmonia, qeoddrir, robofox, changeangels, resheep, thefunfactory, someonefun, funbox, funlands, funnyfun, goldrym, dodrorth, gamegiveaways, soundworks, dfen, whitebot, notarfuncma, fc542f, ovthamola, espoem, merlin7, funtraveller, flugschwein, jpphotography, jacekw.dev, drorion, bitok.xyz, crokkon, angelinafx, rhampagoe, shaka, vannour, steemperor, steempire, mothership, obvious, astrophoto.kevin, cj3000, tfq86, steemworld, jacekw, luegenbaron, ew-and-patterns, jchappe, emrebeyler, shammi, akifane, elleok, steemtank, neokuduk, make-a-whale, feedyourminnows, thomasgift, isnochys, reggaemuffin, badham, snwolak, stevescoins, steembasicincome, zcool, qurator-tier-1-2, warfeed, unatalmaria, busy.pay, freebornsociety, rach, quigua, thecryptodrive, glitterbooster, kingnosa, fullnodeupdate, feo, abigail-dantes, anfitriones, kamikaze, cardumen, monoc, apsu, anthive, samantha-w, jesusj1, perepilichnyy, teamsteem, boontjie, michaelizer, elohim4, alvinvoo, ikarus56, ajuwaya, okean123, avisk, timcliff, arsadulislam, steempty, fminerten, timemaster, fulltimebot33, fulltimebot41, nikokafka, schlafhacking, thobo, fulltimebot50, fulltimebot51, fulltimebot57, fulltimebot32, smjn, mytechtrail, fulltimeangel, fulltimebot72, markgritter, steem-plus, steem-ua, janse, utopian-io, topoisomerase, chamviet, pierrehugo, jaredk123, openaccount, haxe, maxpatternman,