Python interaction design based on Dragonbaord 410c development board (2) - how to get weather data

Nowadays, many websites can provide weather data services. As long as your device is connected to the network, you can easily access the weather data through the network. The wifi connection service is provided on the dragonboard 410c development board, which can be easily connected to the network. In the process of development on the dragonboard 410c, we can obtain weather data through the network to enrich our application. Currently, there are commonly used weather API interfaces of the National Weather Service and Sina. The specific URLs are as follows:

National Weather Service weather interface address:

Http://

Http://

Http://m.weather.com.cn/data/101010100.html

Sina weather interface address:

Http://

http://wthrcdn.etouch.cn/WeatherApi? City=Shenzhen

These interfaces can be opened with a browser, you can see the weather information obtained, as shown below, here we open the last Sina interface, you can get the weather XML file, query the current and the weather of the days before and after Environmental index.

However, we certainly can't use browser to open our weather interface in the development process. More often, we need to automatically get and parse the weather data through the program. Today we will teach you how to use Python script on the dragonboard 410c platform. Get weather data from Sina's official API interface and print it out.

Here we use the QNetworkAccessManager and QNetworkRequest classes in the QtNetwork module provided by pyqt to implement network programming and access the weather API interface to obtain related data services. The specific code is as follows:

From PyQt5 import QtWidgets, QtCore, QtXml, QtGui, QtNetwork

Class weatherWindows(QtWidgets.QWidget):

Def __init__(self):

Super(weatherWindows,self).__init__()

Self.img=QtGui.QImage()

Self.manager = QtNetwork.QNetworkAccessManager()

Self.weather_updateOK=0

self.Reply=self.manager.get(QtNetwork.QNetworkRequest(QtCore.QUrl("http://wthrcdn.etouch.cn/WeatherApi?city=%E6%B7%B1%E5%9C%B3")))

self.Reply.finished.connect(self.replayFinished)

Def replayFinished(self):
Global weather
Print("weather replayFinished")
#status_code = self.Reply.attribute(QtNetwork.QNetworkRequest.HttpStatusCodeAttribute)
Qbyte = self.Reply.readAll()
Pbyte = bytes(qbyte.data())
Str(pbyte, encoding = "utf-8")
weatherInfo = bytes.decode(pbyte)
Print(weatherInfo)

Self.weather_updateOK=0

If __name__=="__main__":
Import sys
App=QtWidgets.QApplicaTIon(sys.argv)
Myshow=weatherWindows()
Sys.exit(app.exec_())

The above is the entire code to get weather data and print weather data, run python script to get weather data and print it out, as follows:

In the above code, the core is through

QtNetwork.QNetworkAccessManager() creates a network management class.

Then use the object obtained by this class to send the url request self.manager.get(QtNetwork.QNetworkRequest(QtCore.QUrl("http://wthrcdn.etouch.cn/WeatherApi?city=%E6%B7%B1%E5%9C% B3")))

After completion, we only need to associate the signal after the request is completed with a slot function. After completing the request to obtain the data, the system can automatically call the slot function to parse the XML file to get the weather information. The correlation function is as follows:

self.Reply.finished.connect(self.replayFinished)

replayFinished is a slot function that is called after the request is completed.

The above is the data acquisition process of the entire weather forecast demo, but we can see that we only get the data now, but usually we don't need to display all the data in our application, just need to parse some data and display it. Here we need to parse the xml file information we obtained, instead of simply printing out the xml file information, then go to the blog to further teach you how to parse the weather XML file data and read the data content.

Vape 2000 Puffs

We supply vape 2000 puffs disposable,all these disposable pen comes with 2000-3000 puffs per device which last longer than various other disposables on the market. The 2000 puffs on an average can be consumed.
We have a variety of well-known brands of disposable e-cigarettes.
Good Taste Iget Max Vape 16 Flavors 8ml;The XXL Bang Vape features an 800mAh internal battery and 6ml of vape juice with up to 2000 puffs!

Vape 2000 Puffs,2000puffs Vape ,Vape Rechargeable ,2000puffs Disposable

TSVAPE Wholesale/OEM/ODM , https://www.tsecigarette.com

Posted on