{"id":427,"date":"2016-01-06T07:41:44","date_gmt":"2016-01-06T07:41:44","guid":{"rendered":"http:\/\/mitat.tuu.fi\/?p=427"},"modified":"2016-01-06T07:47:28","modified_gmt":"2016-01-06T07:47:28","slug":"python-snippets","status":"publish","type":"post","link":"http:\/\/mitat.tuu.fi\/?p=427","title":{"rendered":"Python snippets"},"content":{"rendered":"<p><strong>print formatting<\/strong><br \/>\n<code>print \"server said %s and %s\" % (content, txt)<\/code><\/p>\n<p><strong>delay \/ sleep<\/strong><br \/>\n<code>import time<br \/>\ntime.sleep(30)<\/code><\/p>\n<p><strong>HTTP get \/ request<\/strong><br \/>\n<code>import httplib2<br \/>\ntry:<br \/>\nresp, content = httplib2.Http().request(\"http:\/\/example.fi\")<br \/>\nexcept urllib2.HTTPError, exc:<br \/>\nexcept urllib2.URLError, exc:<br \/>\nprint \"Failed because:\", exc.reason<br \/>\n<\/code><\/p>\n<p><strong>Send email<\/strong><br \/>\n<code>def sendMail(FROM,TO,SUBJECT,TEXT,SERVER):<br \/>\n    import smtplib<br \/>\n    \"\"\"this is some test documentation in the function\"\"\"<br \/>\n    message = textwrap.dedent(\"\"\"\\<br \/>\n        From: %s<br \/>\n        To: %s<br \/>\n        Subject: %s<br \/>\n        %s<br \/>\n        \"\"\" % (FROM, TO, SUBJECT, TEXT))<br \/>\n    # Send the mail<br \/>\n    server = smtplib.SMTP(SERVER)<br \/>\n    server.sendmail(FROM, TO, message)<br \/>\n    server.quit()<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>print formatting print &#8220;server said %s and %s&#8221; % (content, txt) delay \/ sleep import time time.sleep(30) HTTP get \/ request import httplib2 try: resp, content = httplib2.Http().request(&#8220;http:\/\/example.fi&#8221;) except urllib2.HTTPError, exc: except urllib2.URLError, exc: print &#8220;Failed because:&#8221;, exc.reason Send email def sendMail(FROM,TO,SUBJECT,TEXT,SERVER): import smtplib &#8220;&#8221;&#8221;this is some test documentation in the function&#8221;&#8221;&#8221; message = textwrap.dedent(&#8220;&#8221;&#8221;\\ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-427","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/mitat.tuu.fi\/index.php?rest_route=\/wp\/v2\/posts\/427","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/mitat.tuu.fi\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/mitat.tuu.fi\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/mitat.tuu.fi\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/mitat.tuu.fi\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=427"}],"version-history":[{"count":10,"href":"http:\/\/mitat.tuu.fi\/index.php?rest_route=\/wp\/v2\/posts\/427\/revisions"}],"predecessor-version":[{"id":437,"href":"http:\/\/mitat.tuu.fi\/index.php?rest_route=\/wp\/v2\/posts\/427\/revisions\/437"}],"wp:attachment":[{"href":"http:\/\/mitat.tuu.fi\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/mitat.tuu.fi\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=427"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/mitat.tuu.fi\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}