{"id":449,"date":"2012-05-02T10:06:15","date_gmt":"2012-05-02T14:06:15","guid":{"rendered":"http:\/\/www.deadcodersociety.org\/?p=449"},"modified":"2012-04-29T16:00:42","modified_gmt":"2012-04-29T20:00:42","slug":"tweeting-tweetable-bible-verses","status":"publish","type":"post","link":"http:\/\/www.deadcodersociety.org\/blog\/tweeting-tweetable-bible-verses\/","title":{"rendered":"Tweeting Tweetable Bible Verses"},"content":{"rendered":"<figure id=\"attachment_457\" aria-describedby=\"caption-attachment-457\" style=\"width: 300px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.deadcodersociety.org\/blog\/wp-content\/uploads\/2012\/04\/The-twitter-bible.jpg\"><img loading=\"lazy\" class=\"size-medium wp-image-457\" title=\"Tweet tweet\" src=\"http:\/\/www.deadcodersociety.org\/blog\/wp-content\/uploads\/2012\/04\/The-twitter-bible-300x225.jpg\" alt=\"Tweet tweet\" width=\"300\" height=\"225\" srcset=\"http:\/\/www.deadcodersociety.org\/blog\/wp-content\/uploads\/2012\/04\/The-twitter-bible-300x225.jpg 300w, http:\/\/www.deadcodersociety.org\/blog\/wp-content\/uploads\/2012\/04\/The-twitter-bible.jpg 400w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-457\" class=\"wp-caption-text\">Tweet tweet<\/figcaption><\/figure>\n<p>I follow several Twitter feeds that tweet verses from the Bible. I whipped up the <a title=\"KJVTweeter on Twitter\" href=\"https:\/\/twitter.com\/#!\/kjvtweeter\" target=\"_blank\">KJVTweeter<\/a>\u00a0Twitter account when I realized that the accounts I followed had some common afflictions:<\/p>\n<ul>\n<li>tweeting popular verses only<\/li>\n<li>selecting verses over 140 characters<\/li>\n<li>tweeting one verse at a time from the beginning<\/li>\n<\/ul>\n<p>The popular verses are nice, but doesn&#8217;t help me learn. Longer verses require a click-through, which isn&#8217;t always desirable. They might be lesser-known verses, but for a medium like Twitter, you really want to focus on the tweet-friendly verses. Another account is beginning in Genesis and is estimated to be done in 83 years. I just need a simple account that tweets short verses in random order. <a title=\"KJVTweeter on Github\" href=\"https:\/\/github.com\/Stantheman\/KJVTweeter\" target=\"_blank\">KJVTweeter (github)<\/a>\u00a0does all of these things.<\/p>\n<h2>Behind the Scenes:<\/h2>\n<p>I found a copy of the King James\u00a0Translation\u00a0in text format. I wanted to find a version with shortened names of the books (tweet-friendly). The copy available at\u00a0<a title=\"KJV text\" href=\"http:\/\/av1611.com\/misc\/KJV.zip\" target=\"_blank\">av1611.com<\/a>\u00a0had the book, chapter, and verse number, a newline, and then the verse. Some quick perl transforms the file into verses contained in a single line, and only prints if the verse is under 141 characters.<\/p>\n<p>The transformation process after obtaining the file is short and sweet:<\/p>\n<pre>unzip -p KJV.zip | .\/parser.pl | sort -R -o random_bible.txt<\/pre>\n<p>One interesting point is that the unzip program doesn&#8217;t accept STDIN, so prepending this pipeline with wget or curl won&#8217;t work.<\/p>\n<figure id=\"attachment_464\" aria-describedby=\"caption-attachment-464\" style=\"width: 300px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/twitter.com\/#!\/kjvtweeter\"><img loading=\"lazy\" class=\"size-medium wp-image-464\" title=\"kjvtweeter-twitter\" src=\"http:\/\/www.deadcodersociety.org\/blog\/wp-content\/uploads\/2012\/04\/Screen-shot-2012-04-29-at-3.53.56-PM-300x185.png\" alt=\"kjvtweeter-twitter\" width=\"300\" height=\"185\" srcset=\"http:\/\/www.deadcodersociety.org\/blog\/wp-content\/uploads\/2012\/04\/Screen-shot-2012-04-29-at-3.53.56-PM-300x185.png 300w, http:\/\/www.deadcodersociety.org\/blog\/wp-content\/uploads\/2012\/04\/Screen-shot-2012-04-29-at-3.53.56-PM.png 870w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-464\" class=\"wp-caption-text\">Still pretty new!<\/figcaption><\/figure>\n<p>It&#8217;s also been a while since I&#8217;ve come across a file with carriage returns. I was having a hard time figuring out why I couldn&#8217;t do something as simple as joining two strings. In the original version, I just used dos2unix, but it was just as easy to substitute out the return.<\/p>\n<p>The tweeting shell script is run every hour. It takes the very first line from the verse file, tweets it, then removes the first line from the file. I was having difficulty figuring out how I&#8217;d select a random line from the file (shuf -n1) and later remove it. I originally pulled a random line, then used grep to get the line number, then used sed to remove that line number. It is much more efficient to sort the file upfront, then pull from the top. The perl to tweet the verse itself is a modified copy of the code available here:\u00a0<a title=\"http:\/\/lukesthoughtdump.blogspot.com\/2009\/06\/tweeting-from-command-line-with-perl.html\" href=\"http:\/\/lukesthoughtdump.blogspot.com\/2009\/06\/tweeting-from-command-line-with-perl.html\" target=\"_blank\">lukesthoughtdump.blogspot.com<\/a>.<\/p>\n<p>For this file,\u00a016758 of the\u00a031102 verses are tweetable &#8212; 53.88% of the Bible. The cronjob is set up to tweet once an hour, which means that it will finish after 699 days (1.91 years or 1 year and 334 days). It&#8217;ll be very easy to kick it off again at that time!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>KJVTweeter tweets every verse from the Bible under 141 characters.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_links_to":"","_links_to_target":""},"categories":[4],"tags":[31,32,30,29],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/posts\/449"}],"collection":[{"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/comments?post=449"}],"version-history":[{"count":18,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/posts\/449\/revisions"}],"predecessor-version":[{"id":470,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/posts\/449\/revisions\/470"}],"wp:attachment":[{"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/media?parent=449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/categories?post=449"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/tags?post=449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}