Danh mục

Smart Home Automation with Linux- Part 8

Số trang: 30      Loại file: pdf      Dung lượng: 0.00 B      Lượt xem: 25      Lượt tải: 0    
10.10.2023

Phí tải xuống: 12,000 VND Tải xuống file đầy đủ (30 trang) 0
Xem trước 3 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Smart Home Automation with Linux- P8:For every word I’ve written, five have been discarded. Such is the nature of writing. For every tenprograms I’ve downloaded, tried, and tested, nine have been discarded. Such is the nature of software.Finding a perspicuous overlap has been a long and arduous tasks, and one that I’d wish for no one tosuffer in solitude.
Nội dung trích xuất từ tài liệu:
Smart Home Automation with Linux- Part 8 CHAPTER 6 ■ DATA SOURCES■ Tip Output each piece of data on a separate line, making it easier for other tools to extract the information. You now have a way of knowing which are the next trains to leave. This could be incorporated into adaily news feed, recited by a speech synthesizer while making breakfast, added to a personal aggregatorpage, or used to control the alarm clock. (The method for this will be discussed later.)Road TrafficWith the whole world and his dog being in love with satellite navigation systems, the role of web-basedtraffic reports has become less useful in recent years. And with the cost coming down every year, it’sunlikely to gain a resurgence any time soon. However, if you have a choice of just one gadget—a SatNavor a web-capable handheld PC—the latter can still win out with one of the live traffic web sites. The United Kingdom has sites like Frixo (www.frixo.com) that report traffic speed on all major roadsand integrate Google Maps so you can see the various hotspots. It also seems like they have thought ofthe HA market, since much of the data is easily accessible, with clear labels for the road speeds betweeneach motorway junction, with the roadwork locations, and with travel news.WeatherSourcing weather data can occur from three sources: an online provider, a personal weather station, orby looking out of the window! I will consider only the first two in the following sections.ForecastsAlthough there appear to be many online weather forecasts available on the Web, most stem from theWeather Channel’s own Weather.com. This site provides a web plug-in(www.weather.com/services/downloads) and desktop app (Windows-only, alas) to access its data, butcurrently there’s nothing more open than that in the way of an API. Fortunately, many of the companiesthat have bought licenses to this data provide access to it for the visitors to their web site and with fewerrestrictions. Yahoo! Weather, for example, has data in an XML format that works well but requires a stylesheet to convert it into anything usable. Like the train times you’ve just seen, each site presents what it feels is the best trade-off betweeninformation and clarity. Consequently, some weather reports comprise only one-line dailycommentaries, while others have an hourly breakdown, with temperatures, wind speed, and windchillfactors. Pick one with the detail you appreciate and, as mentioned previously, is available with an API orcan easily be scraped. In this example, I’ll use the Yahoo! reports. This is an XML file that changes as often as the weather(literally!) and can be downloaded according to your region. This can be determined by going throughthe Yahoo! weather site as a human and noting the arguments in the URL. For London, this is UKXX0085,which enables the forecast feed to be downloaded with this:#!/bin/bashLOGFILE=/var/log/minerva/cache/weather.xmlwget -q http://weather.yahooapis.com/forecastrss?p=UKXX0085 -O $LOGFILE 193 CHAPTER 6 ■ DATA SOURCES You can then process this with XML using a style sheet and xsltproc: RESULT_INFO=/var/log/minerva/cache/weather_info.txt rm $RESULT_INFO xsltproc /usr/local/minerva/bin/weather/makedata.xsl $LOGFILE > $RESULT_INFO This converts a typical XML like this: CHAPTER 6 ■ DATA SOURCES That is perfect for speech output, status reports, or e-mail. The makedata.xsl file, however, is a littlemore fulsome: day: Monday Tuesday Wednesday Thursday Friday Saturday 195 CHAPTER 6 ■ DATA SOURCES Sunday description: low: high: end: In several places, you will note the strange carriage returns included to produce a friendlier output file. Because of the CPU time involved in querying these APIs, you download and process them with a script (like the one shown previously) and store its output in a separate file. In this way, you can schedule the weather update script once at 4 a.m. and be happy that the data will be immediately available ...

Tài liệu được xem nhiều: