4 Star 0 Fork 1

计算机网络课程设计/pyqt5socket实现CS通信

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
weather.py 1.18 KB
一键复制 编辑 原始数据 按行查看 历史
import requests, json
def getWeather(n):
"""
:return: 无锡天气情况
"""
if n == 0:
url = "https://www.sojson.com/open/api/weather/json.shtml?city=无锡"
html = requests.get(url).text # 天气数据 字符串类型
print("html", html)
jsonData = json.loads(html) # 字典类型
print("jsondata",jsonData)
data = jsonData['data']['forecast'] # 选取出来今天的数据
todayWeather = data[0]
date = todayWeather['date']
sunrise = todayWeather['sunrise']
high = todayWeather['high']
low = todayWeather['low']
weather = todayWeather['type']
notice = todayWeather['notice']
weatherData = {
'date': date,
'sunrise': sunrise,
'high': high,
'low': low,
'weather': weather,
'notice': notice
}
with open("weather.json", 'w', encoding='utf-8') as f:
f.write(json.dumps(weatherData))
else:
with open("weather.json", 'r', encoding='utf-8') as f:
weatherData = json.loads(f.read())
print("获取到天气", weatherData)
return weatherData
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/computer_network_course_design/pyqt5_socket_CS.git
git@gitee.com:computer_network_course_design/pyqt5_socket_CS.git
computer_network_course_design
pyqt5_socket_CS
pyqt5socket实现CS通信
master

搜索帮助