Store all posts from an author in markdown files
steemdev·@holger80·
0.000 HBDStore all posts from an author in markdown files
I would find it very convenient to have all my written posts in one folder on my hard drive. The content of each file should be identical to the blockchain data. I did not found a tool for this task, so I wrote a python script. The script does the following: * it reads the blog section of the given author (limited to the newest 500 posts) * skip resteemed posts * extracts title, timestamp, permlink and store them as YAML extension at top of the md file * saves the content as markdown file ``` #!/usr/bin/python from beem import Steem from beem.comment import Comment from beem.account import Account import os import io import argparse if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("author") parser.add_argument("path") args = parser.parse_args() author = args.author path = args.path stm = Steem(node="https://api.steemit.com") account = Account(author, steem_instance=stm) for comment in account.get_blog(limit=500): if comment["author"] != author: continue markdown_content = comment.body title = comment.title timestamp = comment.json()["created"] author = comment["author"] permlink = comment["permlink"] yaml_prefix = '---\n' yaml_prefix += 'title: %s\n' % title yaml_prefix += 'date: %s\n' % timestamp yaml_prefix += 'permlink %s' % permlink yaml_prefix += 'author: %s\n---\n' % author filename = os.path.join(path, timestamp.split('T')[0] + '_' + permlink + ".md") with io.open(filename, "w", encoding="utf-8") as f: f.write(yaml_prefix + markdown_content) ``` Store this file as `save_posts_as_md.py`. `beem` need to be installed. The script needs two parameter: ``` python save_posts_as_md.py <author> <path> ``` The posts from the author are stored in the given path. The filename consists of the date and the permlink. ### Result for holger80 ``` python save_posts_as_md.py holger80 . ```  Viewing the markdown files works best using the great [typora](https://typora.io/) editor. ### Storing one post as markdown file ``` #!/usr/bin/python from beem import Steem from beem.comment import Comment from beem.account import Account import io import argparse if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("authorperm") parser.add_argument("filename") args = parser.parse_args() authorperm = args.authorperm filename = args.filename stm = Steem(node="https://api.steemit.com") comment = Comment(authorperm, steem_instance=stm) markdown_content = comment.body title = comment.title timestamp = comment["created"] author = comment["author"] yaml_prefix = '---\n' yaml_prefix += 'title: %s\n' % title yaml_prefix += 'date: %s\n' % str(timestamp) yaml_prefix += 'author: %s\n---\n' % author with io.open(filename, "w", encoding="utf-8") as f: f.write(yaml_prefix + markdown_content) ``` This script works when a authorperm and filename was given: ``` python save_post_as_md.py @holger80/how-to-post-using-typora-and-beempy how-to-post-using-typora-and-beempy.md ```
👍 passion-fruit, upgoat, lukasmining, shahabudin, literaturkritik, wstanley226, linkerstinker, nurah, fortune-master, robofox, changeangels, themuffinman, thefunfactory, funbox, funanime, goldrym, resheep, upcroak, bubbleburst, someonefun, funlands, funkyfun, funnyfun, dmonia, qeoddrir, dodrorth, nabilbouasla, soundworks, steeming-hot, eforucom, dfen, osakscinac, titadisca, inpegeartdu, baisohicjo, tempringkelfi, elizabethk87r6, taylorsed50, jessicaui89, alyssah2tp3green, mariaovs, sarah12m, elizabethp6, maduresway, hitputzfetwall, contsimilti, gailadolma, biolinghave, nicolemih, angelinafx, merlin7, flugschwein, jacekw.dev, drorion, whitebot, crokkon, steemtaker, funtraveller, espoem, mops2e, gtg, jacekw, nerdrepost, ew-and-patterns, jchappe, elleok, steemtank, isnochys, thomasgift, chamviet, snwolak, stevescoins, steembasicincome, pierrehugo, zcool, jaredk123, reggaemuffin, badham, openaccount, anthonyadavisii, warfeed, smartmeme, freebornsociety, feo, anfitriones, cardumen, monoc, thecryptodrive, glitterbooster, kingnosa, fullnodeupdate, irisworld, abigail-dantes, kamikaze, krnel, pele23, oflyhigh, jlordc, schlafhacking, samantha-w, jesusj1, perepilichnyy, michaelizer, elohim4, alvinvoo, ikarus56, commonlaw, teamsteem, fulltimebot31, unatalmaria, rach, fulltimebot39, quigua, scorer, arsadulislam, steempty, fminerten, crytiblock, personz, fulltimebot75, dramaking, jeffrey24864, amosbastian, codingdefined, mytechtrail, mcfarhat, antikesdenken, torrey.blog, condeas, smjn, fulltimebot12, fulltimebot19, themanny, qurator, qurator-tier-1-2, yadamaniart, isabelpereira, theleapingkoala, verhp11, jayna, redheadpei, steem-ua, newsrx, bluengel, steem-plus, geekpowered, timcliff, apsu, cifer, nuthman, ocdb, janse, robertgelbmann, redpalestino, linnyplant, matytan, binaural, barton26, edb, pinkwonder,