Book Image

Getting Started with Python and Raspberry Pi (Redirected from Learning Python By Developing Raspberry Pi Applications)

By : Dan Nixon
Book Image

Getting Started with Python and Raspberry Pi (Redirected from Learning Python By Developing Raspberry Pi Applications)

By: Dan Nixon

Overview of this book

Table of Contents (18 chapters)
Getting Started with Python and Raspberry Pi
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Parsing XML APIs


In this section, we will look at creating a simple weather forecast application using the OpenWeatherMap 5 day forecast API (http://openweathermap.org/forecast#5days), which can return an XML document containing the forecast data.

This API is accessed through a URL in the following format; in this case, we are searching for the weather in Harwell, UK:

http://api.openweathermap.org/data/2.5/forecast?q=Harwell,GB&mode=xml

This gives an output in the following format, where the time element is repeated for the number of forecasts that are available in the 5 day time range:

<?xml version="1.0" encoding="UTF-8"?>
<weatherdata>
   <location>
      <name>Harwell</name>
      <type />
      <country>GB</country>
      <timezone />
      <location altitude="0" latitude="51.599468" longitude="-1.29175" geobase="geonames" geobaseid="0" />
   </location>
   <credit />
   <meta>
      <lastupdate />
...