完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
from PyQt5 import QtWidgets, QtCore, QtXml, QtGui,QtNetwork from mainwindow import Ui_MainWindow #from QtGui import QPixmap import res import time class getWeatherInfo(object): def __init__(self,weatherXml): self.weather_updateOK=0 self.weather_city="" self.weather_wendu="" self.weahter_updatetime="" self.weather_suggest="" self.weather_fengli="" self.weather_fengxiang="" self.weather_sunrise="" self.weather_sunset="" self.forecast_weather_info_date=[] self.forecast_weather_info_high=[] self.forecast_weather_info_low=[] self.forecast_weather_info_dtype=[] self.forecast_weather_info_dfengxiang=[] self.forecast_weather_info_dfengli=[] self.forecast_weather_info_ntype=[] self.forecast_weather_info_nfengxiang=[] self.forecast_weather_info_nfengli=[] #指数 self.weather_zhishu_name=[] self.weather_zhishu_vale=[] self.weather_zhishu_data=[] self.prassWeatherInfo(weatherXml) def prassWeatherInfo(self,weatherXml): print("start prassWeatherInfo") while not weatherXml.atEnd(): if weatherXml.hasError(): print ("error: get weather data error") return -1 elif weatherXml.isStartElement(): if weatherXml.name()=="city": self.weather_city = weatherXml.readElementText() #print(city) weatherXml.readNext() elif weatherXml.name()=="updatetime": self.weahter_updatetime=weatherXml.readElementText() weatherXml.readNext() elif weatherXml.name()=="wendu": self.weather_wendu=weatherXml.readElementText() weatherXml.readNext() elif weatherXml.name()=="fengli": self.weather_fengli=weatherXml.readElementText() weatherXml.readNext() elif weatherXml.name()=="shidu": self.weather_shidu=weatherXml.readElementText() weatherXml.readNext() elif weatherXml.name()=="fengxiang": self.weather_fengxiang=weatherXml.readElementText() weatherXml.readNext() elif weatherXml.name()=="sunrise_1": self.weather_sunrise=weatherXml.readElementText() weatherXml.readNext() elif weatherXml.name()=="sunset_1": self.weather_sunset=weatherXml.readElementText() weatherXml.readNext() elif weatherXml.name()=="environment": print("environment") while not weatherXml.atEnd(): print("test") if weatherXml.name()=="suggest": self.weather_suggest=weatherXml.readElementText() print("suggest") break else: weatherXml.readNext() elif weatherXml.name()=="forecast": #print(weatherXml.readElementText()) print("forecast") weatherXml.readNext() while not weatherXml.atEnd(): if weatherXml.isStartElement(): if weatherXml.name()=="weather": weatherXml.readNext() while not weatherXml.atEnd(): if weatherXml.isStartElement(): if weatherXml.name()=="date": #print("weather info") date = weatherXml.readElementText() self.forecast_weather_info_date.append(date) weatherXml.readNext() #print(date) elif weatherXml.name()=="high": high=weatherXml.readElementText() self.forecast_weather_info_high.append(high) weatherXml.readNext() #print(high) elif weatherXml.name()=="low": low=weatherXml.readElementText() self.forecast_weather_info_low.append(low) weatherXml.readNext() #print(low) elif weatherXml.name()=="day": #print("day info") weatherXml.readNext() while not weatherXml.atEnd(): if weatherXml.isStartElement(): if weatherXml.name()=="type": type = weatherXml.readElementText() self.forecast_weather_info_dtype.append(type) weatherXml.readNext() #print("type:") #print(type) elif weatherXml.name()=="fengxiang": ffengxiang=weatherXml.readElementText() self.forecast_weather_info_dfengxiang.append(ffengxiang) weatherXml.readNext() #print(ffengxiang) elif weatherXml.name()=="fengli": ffengli=weatherXml.readElementText() print("fenli") self.forecast_weather_info_dfengli.append(ffengli) weatherXml.readNext() #print(ffengli) else: weatherXml.readNext() #break else: weatherXml.readNext() break elif weatherXml.name()=="night": #print("night info:") weatherXml.readNext() while not weatherXml.atEnd(): if weatherXml.isStartElement(): if weatherXml.name()=="type": ntype=weatherXml.readElementText() self.forecast_weather_info_ntype.append(ntype) weatherXml.readNext() #print(ntype) elif weatherXml.name()=="fengxiang": nfengxiang=weatherXml.readElementText() self.forecast_weather_info_nfengxiang.append(nfengxiang) weatherXml.readNext() #print(nfengxiang) elif weatherXml.name()=="fengli": nfengli=weatherXml.readElementText() print("nfenli") self.forecast_weather_info_nfengli.append(nfengli) weatherXml.readNext() #print(nfengli) else: weatherXml.readNext() #break else: weatherXml.readNext() break else: weatherXml.readNext() else: weatherXml.readNext() break else: weatherXml.readNext() else: weatherXml.readNext() break elif weatherXml.name()=="zhishus": #print("zhishus:") weatherXml.readNext() while not weatherXml.atEnd(): if weatherXml.isStartElement(): if weatherXml.name()=="zhishu": print("zhishu2:") weatherXml.readNext() while not weatherXml.atEnd(): if weatherXml.isStartElement(): if weatherXml.name()=="name": self.weather_zhishu_name.append(weatherXml.readElementText()) #print("name") #print(self.weather_zhishu_name) weatherXml.readNext() elif weatherXml.name()=="value": self.weather_zhishu_vale.append(weatherXml.readElementText()) #print("value") weatherXml.readNext() elif weatherXml.name()=="detail": self.weather_zhishu_data.append(weatherXml.readElementText()) #print("detail") #print(weatherXml.readElementText()) weatherXml.readNext() else: weatherXml.readNext() else: weatherXml.readNext() break else: weatherXml.readNext() else: weatherXml.readNext() break else: weatherXml.readNext() else: weatherXml.readNext() weatherXml.clear() self.updateOK=1 for i in range(0,5): print(self.weather_zhishu_name) print(self.weather_zhishu_vale) print(self.weather_zhishu_data) def updateOK(self): return self.updateOK 通过调用该类就可以实现对xml文件中个的天气数据的解析,并且通过访问类成员就可以获取相应的天气信息。 如下图所示,是调用该类解析得到的天气指数数据: 以上就是整个天气xml数据解析的过程,后期blog中我将用该类来实现天气demo中的xml数据解析,并且在dragonboard 410c平台上完成整个天气demo的设计和实现。
只有小组成员才能发言,加入小组>>
82个成员聚集在这个小组
Qualcomm_Snapdragon_VR_SDK SvrPlugin脚本简介(1)
1690 浏览 0 评论
【DragonBoard 410c试用体验】之OpenCV中canny算子边缘检测
8987 浏览 0 评论
【DragonBoard 410c】汇总帖(2016.10.25更新)
36075 浏览 2 评论
电子发烧友网
电子发烧友论坛
查看 »
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 07:45 , Processed in 0.688613 second(s), Total 43, Slave 33 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com