{"id":1015,"date":"2014-06-20T10:26:07","date_gmt":"2014-06-20T10:26:07","guid":{"rendered":"http:\/\/www.silkstream.net\/blog\/?p=1015"},"modified":"2014-09-05T14:56:39","modified_gmt":"2014-09-05T14:56:39","slug":"random-tweets-with-twython","status":"publish","type":"post","link":"https:\/\/www.silkstream.net\/blog\/2014\/06\/random-tweets-with-twython.html","title":{"rendered":"Noob&#8217;s Guide #3: Random Tweets with Twython"},"content":{"rendered":"<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1023\" alt=\"Noob's Guide to Twython\" src=\"https:\/\/www.silkstream.net\/blog\/wp-content\/uploads\/2014\/06\/noob-guide-twython-3.jpg\" width=\"556\" height=\"300\" \/><\/p>\n<p style=\"text-align: justify;\">Welcome to the third installment of The Noob&#8217;s Guide to Twython, where we&#8217;re playing around with the Twitter API with Python, using the Twython module. These tutorials are aimed at those who are perhaps learning to code for the first time, or have only a beginner&#8217;s knowledge of Python. If you&#8217;re looking for some advanced stuff, you&#8217;ve come to the wrong place!<\/p>\n<p style=\"text-align: justify;\">So far, we&#8217;ve covered <a title=\"How To Get Going With Twython\" href=\"https:\/\/www.silkstream.net\/blog\/2014\/06\/how-to-get-going-with-twython.html\" target=\"_blank\">setting up your Twython for the first time<\/a> and <a title=\"ReTweeting with your Twython Twitter Bot\" href=\"https:\/\/www.silkstream.net\/blog\/2014\/06\/retweeting-with-your-twython-twitter-bot.html\" target=\"_blank\">ReTweeting status updates based on search query<\/a> using filters to keep out all that pesky noise!<\/p>\n<p style=\"text-align: justify;\">But there&#8217;s nothing really interesting about a Twitter bot that does nothing but ReTweet things. In fact, it might even be a little bit boring. People like original content, or just a little something more that they can interact with. So why not have your bot automatically Tweet things as well as ReTweet things?\u00a0<span style=\"font-size: 1rem;\">You could even use this for promotions of a product or service or what have you. <\/span><span style=\"line-height: 1.714285714; font-size: 1rem;\">Of course you can schedule posts on a daily or weekly basis. But if you don&#8217;t want to be Tweeting anything from the bot account manually everyday&#8230;<\/span><\/p>\n<h2 style=\"text-align: justify;\">Let&#8217;s make a Twython Twitter Bot!<\/h2>\n<p style=\"text-align: justify;\">So let&#8217;s take a quick gander at what we can expect to create, before we start dissecting it all up and going through what everything actual means! You might notice we&#8217;ve added two new things to import that weren&#8217;t in our previous bot. We&#8217;re now going to need to import time and random too.<\/p>\n<div style=\"border: dashed #f79239; padding: 8px; text-align: justify;\">\n<pre style=\"color: #000000;\"><code><span style=\"color: #ff6600;\">#Importing time and random now!<\/span>\r\nfrom twython import Twython, TwythonError\r\nimport time\r\nimport random\r\n\r\napp_key = \"YOUR_APP_KEY\"\r\napp_secret = \"YOUR_APP_SECRET\"\r\noauth_token = \"YOUR_OAUTH_TOKEN\"\r\noauth_token_secret = \"YOUR_OAUTH_TOKEN_SECRET\"\r\n\r\ntwitter = Twython(app_key, app_secret, oauth_token, oauth_token_secret)\r\n\r\n<span style=\"color: #ff6600;\">#Small list of Tweets to Tweet<\/span>\r\nlist = [\r\n    \"Hello, I'm a Tweet.\",\r\n    \"And I'm another!\",\r\n    \"Yoohoo! I'm here too!\",\r\n    \"We're all here together!\",\r\n    \"Isn't Twitter so much fun =D\",\r\n    \"(I think you get the idea by this point...)\"\r\n    ]\r\n\r\n<span style=\"color: #ff6600;\">#This is called a while loop.<\/span>\r\nwhile True:\r\n    try:\r\n        if len(list) &gt; 0:\r\n            toTweet = list[random.randint(0,len(list))-1]\r\n            twitter.update_status(status=toTweet)\r\n            list.remove(toTweet)\r\n            time.sleep(60)\r\n        else:\r\n<span style=\"color: #ff6600;\">#Oops! Our twitter.update_status should all be on one line!<\/span>\r\n            twitter.update_status(status=\"Oh dear... I'm afraid I'm rather empty =(\")\r\n            break\r\n    except TwythonError as e:\r\n        print e<\/code><\/pre>\n<\/div>\n<p style=\"text-align: justify;\">Ready? Great! Let&#8217;s get started&#8230;<\/p>\n<h2 style=\"text-align: justify;\">Creating a bunch of Tweets to Tweet!<\/h2>\n<p>First we&#8217;re going to need to create a list of Tweets that our Twitter Bot can choose from to Tweet. We can then just add new Tweets to our list whenever we want.<\/p>\n<p>Lists in Python look a little something like this:<\/p>\n<div style=\"border: dashed #f79239; padding: 8px; text-align: justify;\">\n<pre><span style=\"color: #000000;\">list = [\"Something 1\", \"Something 2\", \"Something 3\"]<\/span><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Each <strong><span style=\"color: #ff6600;\">Something<\/span><\/strong> is an item in our list, separated by a comma. And since it&#8217;s a string it&#8217;s enclosed in quotation marks. <strong><span style=\"color: #ff6600;\">list<\/span><\/strong> is what they they&#8217;re all called together (which makes sense). We can also spread them across multiple lines, just so they&#8217;re easier to read. Like so:<\/p>\n<div style=\"border: dashed #f79239; padding: 8px; text-align: justify;\">\n<pre><span style=\"color: #000000;\">list = [\r\n    \"Something 1\",\r\n    \"Something 2\",\r\n    \"Something 3\"\r\n    ]<\/span><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Which might be easier if you have a dozen or so items in your list and want to be able to read them easily. So for this example, you can replace each <strong><span style=\"color: #ff6600;\">Something<\/span> <\/strong>with a Tweet. It can be an inspiring quote or message, or a promotion or whatever you want!<\/p>\n<h2>While Loops that Loop While Something<\/h2>\n<p style=\"text-align: justify;\">A while loop is like an if statement that repeats over and over again until something tells it to stop.<\/p>\n<p style=\"text-align: justify;\">This whole block of code right here is our while loop:<\/p>\n<div style=\"border: dashed #f79239; padding: 8px; text-align: justify;\">\n<pre style=\"color: #000000;\"><code><span style=\"color: #ff6600;\">#This is called a while loop.<\/span>\r\nwhile True:\r\n    try:\r\n        if len(list) &gt; 0:\r\n            toTweet = list[random.randint(0,len(list))-1]\r\n            twitter.update_status(status=toTweet)\r\n<span style=\"color: #ff6600;\">#Removal of the Tweet is optional<\/span>\r\n            list.remove(toTweet)\r\n            time.sleep(60)\r\n        else:\r\n<span style=\"color: #ff6600;\">#Oops! twitter.update_status should all be on one line!<\/span>\r\n            twitter.update_status(status=\"Oh dear... I'm afraid I'm rather empty =(\")\r\n            break\r\n    except TwythonError as e:\r\n        print e<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Basically we&#8217;re telling our bot that <strong><span style=\"color: #ff6600;\">while True<\/span> <\/strong>(which is always until we tell it it&#8217;s not), we want it to try grabbing a random item in our list and Tweeting it, then removing it from our list so it never gets Tweeted again, then pausing for a duration of time, before going through the process again. But ONLY if there&#8217;s something in our list to actually Tweet. If our list is empty, we want to update our Twitter status to say &#8220;Oh dear&#8230; I&#8217;m afraid I&#8217;m rather empty =(&#8220;, notifying us that we need to add more things to our list, before breaking out of the while loop and exiting the program completely.<\/p>\n<p style=\"text-align: center;\"><em>FYI: The =( is supposed to be a sad face&#8230;<\/em><\/p>\n<p style=\"text-align: justify;\">Pheww! That was a confusing explanation. I even confused myself. So let&#8217;s break it down even further&#8230;<\/p>\n<div style=\"border: dashed #f79239; padding: 8px; text-align: justify;\">\n<pre><span style=\"color: #000000;\">if len(list) &gt; 0:<\/span><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>That just means that if the length of <strong><span style=\"color: #ff6600;\">list<\/span> <\/strong>is more than 0 (i.e. if there is something in our list to be Tweeted), do the following. <strong><span style=\"color: #ff6600;\">len<\/span><\/strong> means length, so to get the length of something we just put that something in the brackets!<\/p>\n<div style=\"border: dashed #f79239; padding: 8px; text-align: justify;\">\n<pre><span style=\"color: #000000;\"><code>toTweet = list[random.randint(0,len(list))-1]<\/code><\/span><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Here we are setting a new variable called <strong><span style=\"color: #ff6600;\">toTweet<\/span><\/strong>, which is going to stand for a random item our list. Remember we imported <span style=\"color: #ff6600;\"><strong>random<\/strong><\/span> earlier? It was like the first thing we did &#8211; this is why we needed it!<\/p>\n<p style=\"text-align: justify;\">Notice how everything following <strong><span style=\"color: #ff6600;\">list<\/span><\/strong> is enclosed in [square brackets]. Like how when we first created in our list, we inserted all our items between square brackets and separated them by a comma. To use a single item in our list, we need to call it by where it is in the index. The index starts from 0. So the first item in our list can be called using\u00a0<span style=\"color: #ff6600;\"><strong>list[0]<\/strong><span style=\"color: #000000;\">.<\/span><\/span><\/p>\n<p style=\"text-align: justify;\">So looking back at our example list earlier:<\/p>\n<div style=\"border: dashed #f79239; padding: 8px; text-align: justify;\">\n<pre><span style=\"color: #000000;\">list = [\r\n    \"Something 1\",    <span style=\"color: #ff6600;\">#This would be list[0]<\/span>\r\n    \"Something 2\",    <span style=\"color: #ff6600;\">#This would be list[1]<\/span>\r\n    \"Something 3\"     <span style=\"color: #ff6600;\">#This would be list[2]<\/span>\r\n    ]<\/span><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">But the problem with this is that we want to Tweet a random item from our list, so we can&#8217;t tell the bot where in the index to extract our Tweet from! This is where we use our <strong><span style=\"color: #ff6600;\">random<\/span> <\/strong>module&#8230;<\/p>\n<p style=\"text-align: justify;\">Because we need an integer (a whole number) from our index &#8211; like <strong><span style=\"color: #ff6600;\">list[1]<\/span><\/strong><span style=\"color: #000000;\">,<\/span> 1 being the integer &#8211; we need to use <strong><span style=\"color: #ff6600;\">randint<\/span> <\/strong>(which means random integer) from our <strong><span style=\"color: #ff6600;\">random<\/span><\/strong> module. Within the <strong><span style=\"color: #ff6600;\">randint<\/span> <\/strong>parameters, we need to specify between what number and what number do we want to select a random integer. So we set our parameters to <strong><span style=\"color: #ff6600;\">(0,len(list))<\/span><\/strong>. Remember what <strong><span style=\"color: #ff6600;\">len<\/span><\/strong> means? We&#8217;re telling our <strong><span style=\"color: #ff6600;\">randint<\/span><\/strong> to randomly select an integer between 0 and the length of our list, since the length of our list is going to be dynamic and we can&#8217;t set it to a static number. We&#8217;re going to be adding and removing items from our list all the time, so we can&#8217;t state how many items are going to be in our list.<\/p>\n<p style=\"text-align: justify;\">And the <strong><span style=\"color: #ff6600;\">-1<\/span><\/strong>? What does that mean? Well, if you recall, the index of a list starts at 0. So <strong><span style=\"color: #ff6600;\">list[1]<\/span><\/strong> isn&#8217;t actually the first item in our list but the second! Therefore, we need to add <strong><span style=\"color: #ff6600;\">-1<\/span><\/strong> so that the random integer we get acknowledges that the first item in our list starts at <strong><span style=\"color: #ff6600;\">list[0]<\/span><\/strong>. Make sense?<\/p>\n<div style=\"border: dashed #f79239; padding: 8px; text-align: justify;\">\n<pre><span style=\"color: #000000;\">twitter.status_update(status=toTweet)<\/span><\/pre>\n<\/div>\n<p style=\"text-align: justify;\">Here we&#8217;re just telling Twitter to Tweet the random item from our list that we&#8217;ve grabbed!<\/p>\n<h2 style=\"text-align: justify;\">Removing already Tweeted Tweets from our list<\/h2>\n<p style=\"text-align: justify;\">This is completely optional. If you want to repeat statuses, you might not want to remove it from the list. You might want it Tweeted again some time. But in case you don&#8217;t want your Twitter bot to be repeating itself, you&#8217;re going to want to remove it from our list of things to Tweet:<\/p>\n<div style=\"border: dashed #f79239; padding: 8px; text-align: justify;\">\n<pre><span style=\"color: #000000;\"><code>list.remove(toTweet)<\/code><\/span><\/pre>\n<\/div>\n<p style=\"text-align: justify;\">The above bit of code tells our program to do just that. Once something&#8217;s been Tweeted, remove it from our list so it doesn&#8217;t get Tweeted again! If you have a small number of items in your list, it&#8217;s more likely that two duplicate Tweets might get Tweeted back-to-back. In which case, you might experience a <strong><span style=\"color: #ff6600;\">403<\/span><span style=\"color: #ff6600;\"> Error<\/span><\/strong>, which is like Twitter warning us that they&#8217;ve detected spam activity on our account because we&#8217;re trying to Tweet a duplicate status so soon after we posted the last one. So just be careful of that. We don&#8217;t want that to happen too many times&#8230;<\/p>\n<h2 style=\"text-align: justify;\">Putting Twython to Sleep&#8230;<\/h2>\n<p style=\"text-align: justify;\">We obviously don&#8217;t want our bot to immediately go back to the start of the loop, and go through it again so soon. Our Twitter needs a rest, otherwise it&#8217;s going to just be spamming new Tweets one after another. (And we&#8217;re going to run out of things to Tweet pretty quickly&#8230;)<\/p>\n<p style=\"text-align: justify;\">This is why we needed to <strong><span style=\"color: #ff6600;\">import time<\/span><\/strong> into our Twitter bot. To give it a sense of time!<\/p>\n<div style=\"border: dashed #f79239; padding: 8px; text-align: justify;\">\n<pre><span style=\"color: #000000;\"><code>time.sleep(60)<\/code><\/span><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">What this tells our bot is that, from our <strong><span style=\"color: #ff6600;\">time<\/span><\/strong> module, we would like to use the sleep function. And we would like to sleep for 60 seconds please!<\/p>\n<p style=\"text-align: justify;\">In the wild, 60 seconds is actually far too short a duration. We certainly do not want our account to be Tweeting something new every minute. That&#8217;s a quick way of getting yourself thrown under the ban hammer.<\/p>\n<p style=\"text-align: justify;\">In actuality, you&#8217;ll probably want your Twitter bot to nap for AT LEAST an hour or two. So for easy reference, there are\u00a03600 seconds in an hour. So three hours would be\u00a010800 seconds. You can work out the rest&#8230;<\/p>\n<h2 style=\"text-align: justify;\">What if our list is empty?<\/h2>\n<p style=\"text-align: justify;\">Everything been removed from your list? Either you&#8217;ve been Tweeting too much or you haven&#8217;t been actively maintaining your list by adding new items! Either way, we need to tell our bot to stop trying to find random items in our list when we don&#8217;t have anything left in our list.<\/p>\n<p style=\"text-align: justify;\">Earlier, we told our bot to only do those things <strong><span style=\"color: #ff6600;\">if len(list) &gt; 0<\/span><\/strong>. So now we need to tell our bot what to do if our list is empty.<\/p>\n<div style=\"border: dashed #f79239; padding: 8px; text-align: justify;\">\n<pre><span style=\"color: #000000;\"><code>else:\r\n    twitter.update_status(status=\"Oh dear... I'm afraid I'm rather empty =(\")\r\n    break<\/code><\/span><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>We learnt this one in our first tutorial! Just a simple status update to tell us that we&#8217;ve run out of things to Tweet. Followed by a <strong><span style=\"color: #ff6600;\">break<\/span><\/strong>. A break is exactly what it sounds like. You&#8217;re breaking out of the while loop, since there&#8217;s nothing left to do here&#8230;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1019\" alt=\"Empty List Tweet\" src=\"https:\/\/www.silkstream.net\/blog\/wp-content\/uploads\/2014\/06\/empty-list-tweet.jpg\" width=\"515\" height=\"95\" \/><\/p>\n<h2>One more thing&#8230;<\/h2>\n<p style=\"text-align: justify;\">This program relies on it being run in the background the entire time. You close the program, it&#8217;s not going to keep Tweeting. You need to host the program somewhere and run it online if you want it to be running 24\/7. But that&#8217;s a tutorial for another time. Also, if you were to use cron or Windows scheduler, you wouldn&#8217;t need to contain it in a while loop or tell the bot when to sleep. You could just simply schedule the program to run every three hours. But that again is a tutorial for another time!<\/p>\n<h2>The Final Product<\/h2>\n<p>It should look something like this:<\/p>\n<div style=\"border: dashed #f79239; padding: 8px; text-align: justify;\">\n<pre style=\"color: #000000;\"><code>from twython import Twython, TwythonError\r\nimport time\r\nimport random\r\n\r\napp_key = \"YOUR_APP_KEY\"\r\napp_secret = \"YOUR_APP_SECRET\"\r\noauth_token = \"YOUR_OAUTH_TOKEN\"\r\noauth_token_secret = \"YOUR_OAUTH_TOKEN_SECRET\"\r\n\r\ntwitter = Twython(app_key, app_secret, oauth_token, oauth_token_secret)\r\n\r\nlist = [\r\n    \"Hello, I'm a Tweet.\",\r\n    \"And I'm another!\",\r\n    \"Yoohoo! I'm here too!\",\r\n    \"We're all here together!\",\r\n    \"Isn't Twitter so much fun =D\",\r\n    \"(I think you get the idea by this point...)\"\r\n    ]\r\n\r\nwhile True:\r\n    try:\r\n        if len(list) &gt; 0:\r\n            toTweet = list[random.randint(0,len(list))-1]\r\n            twitter.update_status(status=toTweet)\r\n            list.remove(toTweet)\r\n            time.sleep(60)\r\n        else:\r\n            twitter.update_status(status=\"Oh dear... I'm afraid I'm rather empty =(\")\r\n            break\r\n    except TwythonError as e:\r\n        print e<\/code><\/pre>\n<\/div>\n<p style=\"text-align: center;\"><strong>HOMEWORK:<\/strong><\/p>\n<p style=\"text-align: center;\"><strong>Play around with ways to combine your ReTweet bot and your Random Tweet bot!<\/strong><\/p>\n<h3 style=\"text-align: center;\"><a title=\"ReTweeting with your Twython Twitter Bot\" href=\"https:\/\/www.silkstream.net\/blog\/2014\/06\/retweeting-with-your-twython-twitter-bot.html\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1009 alignleft\" alt=\"How To Get Going With Twython\" src=\"https:\/\/www.silkstream.net\/blog\/wp-content\/uploads\/2014\/06\/orange-arrow-left.png\" width=\"127\" height=\"120\" \/><\/a><a title=\"ReTweeting with your Twython Twitter Bot\" href=\"https:\/\/www.silkstream.net\/blog\/2014\/06\/retweeting-with-your-twython-twitter-bot.html\">The Noob&#8217;s Guide to Twython &#8211; Part 2:<\/a><\/h3>\n<p style=\"text-align: center;\"><a title=\"ReTweeting with your Twython Twitter Bot\" href=\"https:\/\/www.silkstream.net\/blog\/2014\/06\/retweeting-with-your-twython-twitter-bot.html\"><strong>ReTweeting with your Twython Twitter Bot<\/strong><\/a><\/p>\n<h3 style=\"text-align: center;\"><a title=\"Playing with Followers with Twython\" href=\"https:\/\/www.silkstream.net\/blog\/2014\/06\/playing-with-followers-with-twython-csv.html\">The Noob&#8217;s Guide to Twython &#8211; Part 5:<img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1010 alignright\" alt=\"\" src=\"https:\/\/www.silkstream.net\/blog\/wp-content\/uploads\/2014\/06\/orange-arrow-right.png\" width=\"127\" height=\"120\" \/><\/a><\/h3>\n<p style=\"text-align: center;\"><a title=\"Playing with Followers with Twython\" href=\"https:\/\/www.silkstream.net\/blog\/2014\/06\/playing-with-followers-with-twython-csv.html\"><strong>Playing with Followers with Twython<\/strong><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\nWelcome to the third installment of The Noob&#8217;s Guide to Twython, where we&#8217;re playing around with the Twitter API with Python, using the Twython <\/p>\n","protected":false},"author":7,"featured_media":1022,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,7],"tags":[],"class_list":["post-1015","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-online-marketing","category-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Random Tweets with Twython - Silkstream | Web Design Blog<\/title>\n<meta name=\"description\" content=\"The third part of our Noob&#039;s Guide To Twython, where we will be looking at creating a Twitter bot that randomly Tweets things from our list!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silkstream.net\/blog\/2014\/06\/random-tweets-with-twython.html\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Random Tweets with Twython - Silkstream | Web Design Blog\" \/>\n<meta property=\"og:description\" content=\"The third part of our Noob&#039;s Guide To Twython, where we will be looking at creating a Twitter bot that randomly Tweets things from our list!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silkstream.net\/blog\/2014\/06\/random-tweets-with-twython.html\" \/>\n<meta property=\"og:site_name\" content=\"Silkstream\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/silkstream\" \/>\n<meta property=\"article:published_time\" content=\"2014-06-20T10:26:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-09-05T14:56:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.silkstream.net\/blog\/wp-content\/uploads\/2014\/06\/twython-guide-thumb-3.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"120\" \/>\n\t<meta property=\"og:image:height\" content=\"120\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ria\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@RiaLolwut\" \/>\n<meta name=\"twitter:site\" content=\"@silkstreamnet\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ria\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/2014\\\/06\\\/random-tweets-with-twython.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/2014\\\/06\\\/random-tweets-with-twython.html\"},\"author\":{\"name\":\"Ria\",\"@id\":\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/#\\\/schema\\\/person\\\/1516b66b9d6da001d8052655282481b1\"},\"headline\":\"Noob&#8217;s Guide #3: Random Tweets with Twython\",\"datePublished\":\"2014-06-20T10:26:07+00:00\",\"dateModified\":\"2014-09-05T14:56:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/2014\\\/06\\\/random-tweets-with-twython.html\"},\"wordCount\":1624,\"commentCount\":4,\"image\":{\"@id\":\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/2014\\\/06\\\/random-tweets-with-twython.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/06\\\/twython-guide-thumb-3.jpg\",\"articleSection\":[\"Online Marketing\",\"Tutorials\"],\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/2014\\\/06\\\/random-tweets-with-twython.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/2014\\\/06\\\/random-tweets-with-twython.html\",\"url\":\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/2014\\\/06\\\/random-tweets-with-twython.html\",\"name\":\"Random Tweets with Twython - Silkstream | Web Design Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/2014\\\/06\\\/random-tweets-with-twython.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/2014\\\/06\\\/random-tweets-with-twython.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/06\\\/twython-guide-thumb-3.jpg\",\"datePublished\":\"2014-06-20T10:26:07+00:00\",\"dateModified\":\"2014-09-05T14:56:39+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/#\\\/schema\\\/person\\\/1516b66b9d6da001d8052655282481b1\"},\"description\":\"The third part of our Noob's Guide To Twython, where we will be looking at creating a Twitter bot that randomly Tweets things from our list!\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/2014\\\/06\\\/random-tweets-with-twython.html#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/2014\\\/06\\\/random-tweets-with-twython.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/2014\\\/06\\\/random-tweets-with-twython.html#primaryimage\",\"url\":\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/06\\\/twython-guide-thumb-3.jpg\",\"contentUrl\":\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/06\\\/twython-guide-thumb-3.jpg\",\"width\":120,\"height\":120,\"caption\":\"Noob's Guide to Twython\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/2014\\\/06\\\/random-tweets-with-twython.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.silkstream.net\\\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Noob&#8217;s Guide #3: Random Tweets with Twython\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/\",\"name\":\"Silkstream\",\"description\":\"Here you&#039;ll find the latest blogs, white papers and case studies from Silkstream experts.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.silkstream.net\\\/blog\\\/#\\\/schema\\\/person\\\/1516b66b9d6da001d8052655282481b1\",\"name\":\"Ria\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/dad9acd650d88d7fd9c7e2b77f38d25ec2c921eb7efb622d785820719d8a75df?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/dad9acd650d88d7fd9c7e2b77f38d25ec2c921eb7efb622d785820719d8a75df?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/dad9acd650d88d7fd9c7e2b77f38d25ec2c921eb7efb622d785820719d8a75df?s=96&d=mm&r=g\",\"caption\":\"Ria\"},\"description\":\"SEO &amp; Internet Marketing addict, and aspiring crazy cat lady.\",\"sameAs\":[\"http:\\\/\\\/www.silkstream.net\",\"https:\\\/\\\/x.com\\\/RiaLolwut\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Random Tweets with Twython - Silkstream | Web Design Blog","description":"The third part of our Noob's Guide To Twython, where we will be looking at creating a Twitter bot that randomly Tweets things from our list!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silkstream.net\/blog\/2014\/06\/random-tweets-with-twython.html","og_locale":"en_GB","og_type":"article","og_title":"Random Tweets with Twython - Silkstream | Web Design Blog","og_description":"The third part of our Noob's Guide To Twython, where we will be looking at creating a Twitter bot that randomly Tweets things from our list!","og_url":"https:\/\/www.silkstream.net\/blog\/2014\/06\/random-tweets-with-twython.html","og_site_name":"Silkstream","article_publisher":"https:\/\/www.facebook.com\/silkstream","article_published_time":"2014-06-20T10:26:07+00:00","article_modified_time":"2014-09-05T14:56:39+00:00","og_image":[{"width":120,"height":120,"url":"https:\/\/www.silkstream.net\/blog\/wp-content\/uploads\/2014\/06\/twython-guide-thumb-3.jpg","type":"image\/jpeg"}],"author":"Ria","twitter_card":"summary_large_image","twitter_creator":"@RiaLolwut","twitter_site":"@silkstreamnet","twitter_misc":{"Written by":"Ria","Estimated reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.silkstream.net\/blog\/2014\/06\/random-tweets-with-twython.html#article","isPartOf":{"@id":"https:\/\/www.silkstream.net\/blog\/2014\/06\/random-tweets-with-twython.html"},"author":{"name":"Ria","@id":"https:\/\/www.silkstream.net\/blog\/#\/schema\/person\/1516b66b9d6da001d8052655282481b1"},"headline":"Noob&#8217;s Guide #3: Random Tweets with Twython","datePublished":"2014-06-20T10:26:07+00:00","dateModified":"2014-09-05T14:56:39+00:00","mainEntityOfPage":{"@id":"https:\/\/www.silkstream.net\/blog\/2014\/06\/random-tweets-with-twython.html"},"wordCount":1624,"commentCount":4,"image":{"@id":"https:\/\/www.silkstream.net\/blog\/2014\/06\/random-tweets-with-twython.html#primaryimage"},"thumbnailUrl":"https:\/\/www.silkstream.net\/blog\/wp-content\/uploads\/2014\/06\/twython-guide-thumb-3.jpg","articleSection":["Online Marketing","Tutorials"],"inLanguage":"en-GB","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.silkstream.net\/blog\/2014\/06\/random-tweets-with-twython.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.silkstream.net\/blog\/2014\/06\/random-tweets-with-twython.html","url":"https:\/\/www.silkstream.net\/blog\/2014\/06\/random-tweets-with-twython.html","name":"Random Tweets with Twython - Silkstream | Web Design Blog","isPartOf":{"@id":"https:\/\/www.silkstream.net\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.silkstream.net\/blog\/2014\/06\/random-tweets-with-twython.html#primaryimage"},"image":{"@id":"https:\/\/www.silkstream.net\/blog\/2014\/06\/random-tweets-with-twython.html#primaryimage"},"thumbnailUrl":"https:\/\/www.silkstream.net\/blog\/wp-content\/uploads\/2014\/06\/twython-guide-thumb-3.jpg","datePublished":"2014-06-20T10:26:07+00:00","dateModified":"2014-09-05T14:56:39+00:00","author":{"@id":"https:\/\/www.silkstream.net\/blog\/#\/schema\/person\/1516b66b9d6da001d8052655282481b1"},"description":"The third part of our Noob's Guide To Twython, where we will be looking at creating a Twitter bot that randomly Tweets things from our list!","breadcrumb":{"@id":"https:\/\/www.silkstream.net\/blog\/2014\/06\/random-tweets-with-twython.html#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silkstream.net\/blog\/2014\/06\/random-tweets-with-twython.html"]}]},{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.silkstream.net\/blog\/2014\/06\/random-tweets-with-twython.html#primaryimage","url":"https:\/\/www.silkstream.net\/blog\/wp-content\/uploads\/2014\/06\/twython-guide-thumb-3.jpg","contentUrl":"https:\/\/www.silkstream.net\/blog\/wp-content\/uploads\/2014\/06\/twython-guide-thumb-3.jpg","width":120,"height":120,"caption":"Noob's Guide to Twython"},{"@type":"BreadcrumbList","@id":"https:\/\/www.silkstream.net\/blog\/2014\/06\/random-tweets-with-twython.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.silkstream.net\/blog"},{"@type":"ListItem","position":2,"name":"Noob&#8217;s Guide #3: Random Tweets with Twython"}]},{"@type":"WebSite","@id":"https:\/\/www.silkstream.net\/blog\/#website","url":"https:\/\/www.silkstream.net\/blog\/","name":"Silkstream","description":"Here you&#039;ll find the latest blogs, white papers and case studies from Silkstream experts.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.silkstream.net\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/www.silkstream.net\/blog\/#\/schema\/person\/1516b66b9d6da001d8052655282481b1","name":"Ria","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/dad9acd650d88d7fd9c7e2b77f38d25ec2c921eb7efb622d785820719d8a75df?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/dad9acd650d88d7fd9c7e2b77f38d25ec2c921eb7efb622d785820719d8a75df?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dad9acd650d88d7fd9c7e2b77f38d25ec2c921eb7efb622d785820719d8a75df?s=96&d=mm&r=g","caption":"Ria"},"description":"SEO &amp; Internet Marketing addict, and aspiring crazy cat lady.","sameAs":["http:\/\/www.silkstream.net","https:\/\/x.com\/RiaLolwut"]}]}},"_links":{"self":[{"href":"https:\/\/www.silkstream.net\/blog\/wp-json\/wp\/v2\/posts\/1015","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silkstream.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silkstream.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silkstream.net\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silkstream.net\/blog\/wp-json\/wp\/v2\/comments?post=1015"}],"version-history":[{"count":11,"href":"https:\/\/www.silkstream.net\/blog\/wp-json\/wp\/v2\/posts\/1015\/revisions"}],"predecessor-version":[{"id":1560,"href":"https:\/\/www.silkstream.net\/blog\/wp-json\/wp\/v2\/posts\/1015\/revisions\/1560"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.silkstream.net\/blog\/wp-json\/wp\/v2\/media\/1022"}],"wp:attachment":[{"href":"https:\/\/www.silkstream.net\/blog\/wp-json\/wp\/v2\/media?parent=1015"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silkstream.net\/blog\/wp-json\/wp\/v2\/categories?post=1015"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silkstream.net\/blog\/wp-json\/wp\/v2\/tags?post=1015"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}