{"id":33695,"date":"2023-02-12T15:44:17","date_gmt":"2023-02-12T10:14:17","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed\/"},"modified":"2023-02-12T15:44:17","modified_gmt":"2023-02-12T10:14:17","slug":"solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed\/","title":{"rendered":"[Solved] I am trying to get my python twitter bot to tweet every 30 minutes on the hour. What should I do? [closed]"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-60457689\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"60457689\" data-parentid=\"60457526\" data-score=\"1\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>So using datetime you can actually get the minutes like this:<\/p>\n<pre><code>from datetime import datetime\n\ntime = datetime.now()\n\nminutes = time.minute\n<\/code><\/pre>\n<p>Or in one line:<\/p>\n<pre><code>from datetime import datetime\n\nminutes = datetime.now().minute\n<\/code><\/pre>\n<p>Now that you have the minutes, the if statement can be simplified down, because you don&#8217;t look at the hour.<\/p>\n<pre><code>if minutes == 0 or minutes == 30:\n    # do tweet\n<\/code><\/pre>\n<p>EDIT:<\/p>\n<p>You commented asking:<br \/>\n&#8220;Also curious, does that mean I need to run my program on the hour of :00 because the time is created through the now function?&#8221;<\/p>\n<p>So theoretically here there are a few ways to answer this. Firts wrap your code in a function and call it constantly:<\/p>\n<pre><code>def tweet_check(minutes):\n    minutes = datetime.now().minutes\n\n    if minutes == 0 or minutes == 30:\n        # do tweet\n\nif __name__ == '__main__':\n    # This would be how it constantly runs the check\n    while true:\n        tweet_check()\n<\/code><\/pre>\n<h1>Option 1:<\/h1>\n<p>Then you can just manually run the script when ever you want your bot to be tweeting every 30 minutes. <\/p>\n<h1>Option 2<\/h1>\n<p>With the check if <strong>main<\/strong> == &#8216;<strong>main<\/strong>&#8216; you will be able to import this script to another one and then run it on your own terms. As an imported script you can go the route of using the scheduler to run it at specific times.<\/p>\n<h1>Option 3:<\/h1>\n<p>Run it as a system scheduled task (windows) or a cron job (linux) to have it run on boot.<\/p>\n<p>However it&#8217;s key to point out that if you do use it as option 2 or 3, it&#8217;s probably best to modify it where you can pass in an optional variable if you want it to just send no matter the time.<\/p>\n<p>So I would modify it like so:<\/p>\n<pre><code>def tweet_check(time_check=True):\n    if time_check:\n        minutes = datetime.now().minutes\n\n        if minutes == 0 or minutes == 30:\n            # do tweet\n\n    else:\n        # do tweet\n\n<\/code><\/pre>\n<p>This is because option 2 and 3 both inherently have timing built into them. So it would be excessive\/inefficient to do it again here. In this simple example, that won&#8217;t make much of a difference, but at the scale of say a few thousand tweets, that would end up rolling into the next minute and then would cut off some of the tweets. <\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">5<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved I am trying to get my python twitter bot to tweet every 30 minutes on the hour. What should I do? [closed] <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] So using datetime you can actually get the minutes like this: from datetime import datetime time = datetime.now() minutes = time.minute Or in one line: from datetime import datetime minutes = datetime.now().minute Now that you have the minutes, the if statement can be simplified down, because you don&#8217;t look at the hour. if minutes &#8230; <a title=\"[Solved] I am trying to get my python twitter bot to tweet every 30 minutes on the hour. What should I do? [closed]\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed\/\" aria-label=\"More on [Solved] I am trying to get my python twitter bot to tweet every 30 minutes on the hour. What should I do? [closed]\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[783,349,4041],"class_list":["post-33695","post","type-post","status-publish","format-standard","hentry","category-solved","tag-datetime","tag-python","tag-tweepy"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] I am trying to get my python twitter bot to tweet every 30 minutes on the hour. What should I do? [closed] - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] I am trying to get my python twitter bot to tweet every 30 minutes on the hour. What should I do? [closed] - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] So using datetime you can actually get the minutes like this: from datetime import datetime time = datetime.now() minutes = time.minute Or in one line: from datetime import datetime minutes = datetime.now().minute Now that you have the minutes, the if statement can be simplified down, because you don&#8217;t look at the hour. if minutes ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2023-02-12T10:14:17+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] I am trying to get my python twitter bot to tweet every 30 minutes on the hour. What should I do? [closed]\",\"datePublished\":\"2023-02-12T10:14:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed\/\"},\"wordCount\":329,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"datetime\",\"python\",\"tweepy\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed\/\",\"name\":\"[Solved] I am trying to get my python twitter bot to tweet every 30 minutes on the hour. What should I do? [closed] - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2023-02-12T10:14:17+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] I am trying to get my python twitter bot to tweet every 30 minutes on the hour. What should I do? [closed]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] I am trying to get my python twitter bot to tweet every 30 minutes on the hour. What should I do? [closed] - JassWeb","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:\/\/jassweb.com\/solved\/solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] I am trying to get my python twitter bot to tweet every 30 minutes on the hour. What should I do? [closed] - JassWeb","og_description":"[ad_1] So using datetime you can actually get the minutes like this: from datetime import datetime time = datetime.now() minutes = time.minute Or in one line: from datetime import datetime minutes = datetime.now().minute Now that you have the minutes, the if statement can be simplified down, because you don&#8217;t look at the hour. if minutes ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed\/","og_site_name":"JassWeb","article_published_time":"2023-02-12T10:14:17+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] I am trying to get my python twitter bot to tweet every 30 minutes on the hour. What should I do? [closed]","datePublished":"2023-02-12T10:14:17+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed\/"},"wordCount":329,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["datetime","python","tweepy"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed\/","url":"https:\/\/jassweb.com\/solved\/solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed\/","name":"[Solved] I am trying to get my python twitter bot to tweet every 30 minutes on the hour. What should I do? [closed] - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2023-02-12T10:14:17+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-i-am-trying-to-get-my-python-twitter-bot-to-tweet-every-30-minutes-on-the-hour-what-should-i-do-closed\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] I am trying to get my python twitter bot to tweet every 30 minutes on the hour. What should I do? [closed]"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/33695","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=33695"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/33695\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=33695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=33695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=33695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}