{"id":212,"date":"2011-01-18T21:06:37","date_gmt":"2011-01-19T02:06:37","guid":{"rendered":"http:\/\/blogs.cae.tntech.edu\/mwr\/?p=212"},"modified":"2024-10-27T14:26:19","modified_gmt":"2024-10-27T14:26:19","slug":"updated-html-and-python-code-for-tweetable-office-door-sign","status":"publish","type":"post","link":"https:\/\/sites.tntech.edu\/renfro\/2011\/01\/18\/updated-html-and-python-code-for-tweetable-office-door-sign\/","title":{"rendered":"Updated HTML and Python code for Tweetable Office Door Sign"},"content":{"rendered":"<p>See <a href=\"http:\/\/blogs.cae.tntech.edu\/mwr\/2011\/01\/01\/work-in-progress-tweetable-office-door-sign\/\">the original post<\/a> for the basic information. This post exists only to highlight a few bug fixes.<\/p>\n<p>Since running with my sign for a few days, the main bug I&#8217;ve run into is that Twitter doesn&#8217;t let you post identical status messages over a short period of time. <a href=\"http:\/\/osdir.com\/ml\/twitter-development-talk@googlegroups.com\/2010-06\/msg00112.html\" target=\"_blank\" rel=\"noopener noreferrer\">One recommended fix is to append some sort of unique data to each message<\/a>. So I&#8217;ve decided to<\/p>\n<ol>\n<li>Convince my browser to append a millisecond time value to each message, and enclose the value in curly braces. So a status message of &#8220;In office&#8221; becomes &#8220;In office {339}&#8221;, for example.<\/li>\n<li>Modify the Python script to strip out the millisecond value so it doesn&#8217;t show up on the door sign. We&#8217;ll use a regular expression to filter out any pair of curly braces surrounding 1-3 digits.<\/li>\n<\/ol>\n<p>Updated code is below the break.<\/p>\n<p><!--more--><\/p>\n<h1>Page of Twitter Status Bookmarks<\/h1>\n<p>Links are now of the form<\/p>\n<pre>&lt;a href=\"javascript:void(0)\" onclick=\"gotostatuspage('In office'); return false\"&gt;In office&lt;\/a&gt;\n<\/pre>\n<p>and the gotostatusurl() Javascript function is added to the page header<\/p>\n<pre>&lt;script type=\"text\/javascript\"&gt;\n\u00a0 function gotostatuspage(message) {\n\u00a0 \/\/ Navigate to the status page, append a pseudo-random number to\n\u00a0 \/\/ trick Twitter into letting us post the same status message\n\u00a0 \/\/ repeatedly. The feed filter will edit out the added number.\n\u00a0 var d = new Date();\n\u00a0 var ms = d.getMilliseconds();\n\u00a0 var urlvar = \"http:\/\/twitter.com\/?status=\"+message+\" {\"+ms+\"}\";\n\u00a0 window.location.assign(urlvar);\n\u00a0 \/\/ Refs:\n\u00a0 \/\/ http:\/\/stackoverflow.com\/questions\/1691781\/i-need-to-build-my-url-in-a-javascript-function-then-return-the-string-back-to-hr\n\u00a0 \/\/ http:\/\/www.w3schools.com\/jsref\/met_loc_assign.asp\n\u00a0 }\n&lt;\/script&gt;<\/pre>\n<h1>Python script<\/h1>\n<pre>#!\/usr\/bin\/python\n\n# Grabs most recent tweet from RSS and reformats it for Chumby RSS\n# Reader app\n\n# Final Chumby display format:\n#\n# - feed_title\n# - item_title\n# - item_description (with Twitter ID removed, and appending timestamp\n#   in local time)\n\n# Credits:\n# http:\/\/stackoverflow.com\/questions\/1766823\/how-can-i-generate-rss-with-arbitrary-tags-and-enclosures\n\nimport feedparser, PyRSS2Gen, string\nfrom datetime import datetime, timedelta\nfrom pytz import timezone\nimport pytz\nimport re\ntwitter_id = \"REPLACEME\"\nfeed_title = \"Mike Renfro &lt;renfro@tntech.edu&gt;\"\nitem_title = \"Where's Mike?\"\ntz = timezone('US\/Central')\ntimestamp_format = ' (%A, %B %-d, %-I:%M %p)'\n\ntry:\n    parsed_feed = feedparser.parse(\"http:\/\/twitter.com\/statuses\/user_timeline\/%s.rss\" % (twitter_id))\n    items = [\n        PyRSS2Gen.RSSItem(\n        title = item_title,\n        link = \"\",\n        description = re.sub(r' {[0-9]{1,3}}',r'',\\\n                             string.replace(x.summary,\"%s: \" % (twitter_id),\"\")+\\\n                             datetime(x.modified_parsed[0],\n                                      x.modified_parsed[1],\n                                      x.modified_parsed[2],\n                                      x.modified_parsed[3],\n                                      x.modified_parsed[4],\n                                      x.modified_parsed[5],\n                                      tzinfo=pytz.utc).astimezone(tz).strftime(timestamp_format)),\n                             guid = \"\")\n        for x in parsed_feed.entries[:1] ]\n\nexcept:\n    # Occasionally, the feed will fail, and be fine the next time I\n    # check it. Since this isn't critical information, I'll just not\n    # write any output at all.\n    pass\n\nelse:\n\n    try:\n        rss = PyRSS2Gen.RSS2(\n            title = feed_title,\n            link = \"\", # parsed_feed.feed.link,\n            description = parsed_feed.feed.description,\n            items = items[:1]\n            )\n\n    except:\n        # Occasionally, the feed will fail, and be fine the next time\n        # I check it. Since this isn't critical information, I'll just\n        # not write any output at all.\n        pass\n\n    else:\n        f = open('REPLACEME.rss','w')\n        f.write(rss.to_xml())\n        f.close()\n<\/pre>\n<div style=\"width: 1px;height: 1px;overflow: hidden\">&lt;script type=&#8221;text\/javascript&#8221;&gt;<br \/>\nfunction gotostatuspage(message) {<br \/>\n\/\/ Navigate to the status page, append a pseudo-random number to<br \/>\n\/\/ trick Twitter into letting us post the same status message<br \/>\n\/\/ repeatedly. The feed filter will edit out the added number.<br \/>\nvar d = new Date();<br \/>\nvar ms = d.getMilliseconds();<br \/>\nvar urlvar = &#8220;http:\/\/twitter.com\/?status=&#8221;+message+&#8221; {&#8220;+ms+&#8221;}&#8221;;<br \/>\nwindow.location.assign(urlvar);<br \/>\n\/\/ Refs:<br \/>\n\/\/ http:\/\/stackoverflow.com\/questions\/1691781\/i-need-to-build-my-url-in-a-javascript-function-then-return-the-string-back-to-hr<br \/>\n\/\/ http:\/\/www.w3schools.com\/jsref\/met_loc_assign.asp<br \/>\n}<br \/>\n&lt;\/script&gt;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>See the original post for the basic information. This post exists only to highlight a few bug fixes. Since running with my sign for a few days, the main bug I&#8217;ve run into is that Twitter doesn&#8217;t let you post identical status messages over a short period of time. One recommended fix is to append &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/sites.tntech.edu\/renfro\/2011\/01\/18\/updated-html-and-python-code-for-tweetable-office-door-sign\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Updated HTML and Python code for Tweetable Office Door Sign&#8221;<\/span><\/a><\/p>\n","protected":false},"author":87,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,13,17],"tags":[],"class_list":["post-212","post","type-post","status-publish","format-standard","hentry","category-javascript","category-organization","category-python","entry"],"_links":{"self":[{"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/posts\/212","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/users\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/comments?post=212"}],"version-history":[{"count":1,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/posts\/212\/revisions"}],"predecessor-version":[{"id":445,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/posts\/212\/revisions\/445"}],"wp:attachment":[{"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/media?parent=212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/categories?post=212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/tags?post=212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}