{"id":838,"date":"2016-03-18T11:58:30","date_gmt":"2016-03-18T09:58:30","guid":{"rendered":"http:\/\/dety.net.ua\/?p=838"},"modified":"2016-03-18T12:34:08","modified_gmt":"2016-03-18T10:34:08","slug":"my-script-to-parse-wheather-data-and-speak-it","status":"publish","type":"post","link":"https:\/\/dety.net.ua\/?p=838","title":{"rendered":"My python 2.7 script to parse wheather data and speak it"},"content":{"rendered":"<blockquote><p># -*- coding: utf8<br \/>\n## encoding=utf8<br \/>\nimport urllib<br \/>\nimport re<br \/>\nfrom bs4 import BeautifulSoup<br \/>\nimport os<br \/>\nimport subprocess<br \/>\nimport codecs<br \/>\nimport sys<\/p>\n<p>from setupcon import setup_console<br \/>\nsetup_console(&#8216;cp866&#8217;)<\/p>\n<p>sys.getdefaultencoding()<br \/>\nreload(sys)<br \/>\nsys.setdefaultencoding(&#8220;cp866&#8221;)<br \/>\n# Get the page<br \/>\nsock = urllib.urlopen(&#8220;http:\/\/tvoj.kharkov.ua\/help\/weather\/&#8221;)<br \/>\nhtmlSource = sock.read()<br \/>\nsock.close()<br \/>\n#print htmlSource<\/p>\n<p>#<br \/>\nsoup = BeautifulSoup(htmlSource, &#8220;html5lib&#8221;)<br \/>\nstring = soup.h1<br \/>\nresults = soup.find_all(&#8216;span&#8217;, limit=10)<br \/>\nfor i in results:<br \/>\nprint i.text<br \/>\ntemp = results[1].text<br \/>\nhumidity = results[4].text<br \/>\npressure = results[6].text<br \/>\npressure = pressure[0:3]<br \/>\nwind = results[7].text<br \/>\nspeed = results[8].text<br \/>\nspeed = speed[0:1]<br \/>\nactivity = results[9].text<\/p>\n<p>#NETATMO<br \/>\nimport lnetatmo<br \/>\nauthorization = lnetatmo.ClientAuth()<br \/>\ndevList = lnetatmo.DeviceList(authorization)<br \/>\ntheData = devList.lastData()<br \/>\n#print(&#8216;Available modules : &#8216;, theData.keys() )<br \/>\n#print(&#8216;In-house CO2 level : &#8216;, theData[&#8216;Indoor&#8217;][&#8216;CO2&#8217;] )<br \/>\n#print(&#8216;Outside temperature : &#8216;, theData[&#8216;Outdoor&#8217;][&#8216;Temperature&#8217;] )<br \/>\n#print(&#8216;External module battery : &#8216;, &#8220;OK&#8221; if int(theData[&#8216;Outdoor&#8217;][&#8216;battery_vp&#8217;]) &gt; 5000 \\<br \/>\n#\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 else &#8220;NEEDS TO BE REPLACED&#8221; )<br \/>\nprint(theData[&#8216;Indoor&#8217;][&#8216;CO2&#8217;])<br \/>\nCO2 = theData[&#8216;Indoor&#8217;][&#8216;CO2&#8217;]<br \/>\nif int(CO2) &gt; 1500:<br \/>\nmessage = u&#8221; \u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0432\u0435\u0442\u0440\u0438\u0442\u044c \u043f\u043e\u043c\u0435\u0449\u0435\u043d\u0438\u0435 &#8221;<br \/>\nelse:<br \/>\nmessage = u&#8221; \u0412 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043d\u043e\u0440\u043c\u044b &#8221;<br \/>\nprint message<\/p>\n<p>command = &#8220;C:\/Progra~1\/Govorilka\/CP\/govorilka_cp.exe&#8221;<br \/>\ncommand.encode(&#8216;cp1251&#8217;).strip()<br \/>\nspeech = u&#8221;\u0423\u0440\u043e\u0432\u0435\u043d\u044c \u0443\u0433\u043b\u0435\u043a\u0438\u0441\u043b\u043e\u0433\u043e \u0433\u0430\u0437\u0430 &#8221; + str(CO2) + message + u&#8221;, \u0422\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0430 \u0432\u043e\u0437\u0434\u0443\u0445\u0430 &#8221; + temp + u&#8221;, \u0432\u043b\u0430\u0436\u043d\u043e\u0441\u0442\u044c &#8221; + humidity + u&#8221; \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043e\u0432, \u0434\u0430\u0432\u043b\u0435\u043d\u0438\u0435 &#8221; + pressure + u&#8221;\u043c\u0438\u043b\u043b\u0438\u043c\u0435\u0442\u0440\u043e\u0432, \u0432\u0435\u0442\u0435\u0440 &#8221; + wind + u&#8221;, \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u0435\u0442\u0440\u0430 &#8221; + speed + u&#8221; \u043c\u0435\u0442\u0440\u043e\u0432 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443, \u043f\u043e\u0433\u043e\u0434\u043d\u044b\u0435 \u044f\u0432\u043b\u0435\u043d\u0438\u044f &#8221; + activity<br \/>\nprint speech<br \/>\nspeech.encode(&#8216;cp866&#8217;)<br \/>\ncmd = &#8220;c:\/\/temp\/\/out.cmd&#8221;<br \/>\nopen(&#8220;c:\/\/temp\/\/out.cmd&#8221;, &#8220;w&#8221;).write(&#8216; &#8216;.join([command,speech]))<br \/>\nsubprocess.call([cmd])<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p># -*- coding: utf8 ## encoding=utf8 import urllib import re from bs4 import BeautifulSoup import os import subprocess import codecs import sys from setupcon import setup_console setup_console(&#8216;cp866&#8217;) sys.getdefaultencoding() reload(sys) sys.setdefaultencoding(&#8220;cp866&#8221;) # Get the page sock = urllib.urlopen(&#8220;http:\/\/tvoj.kharkov.ua\/help\/weather\/&#8221;) htmlSource = sock.read() sock.close() #print htmlSource # soup = BeautifulSoup(htmlSource, &#8220;html5lib&#8221;) string = soup.h1 results = soup.find_all(&#8216;span&#8217;, limit=10) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,12],"tags":[],"class_list":["post-838","post","type-post","status-publish","format-standard","hentry","category-novosti","category-windows"],"_links":{"self":[{"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/posts\/838","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dety.net.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=838"}],"version-history":[{"count":2,"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/posts\/838\/revisions"}],"predecessor-version":[{"id":855,"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/posts\/838\/revisions\/855"}],"wp:attachment":[{"href":"https:\/\/dety.net.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=838"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dety.net.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=838"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dety.net.ua\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=838"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}