- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章python结合API实现即时天气信息由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
python结合API实现即时天气信息 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
import
urllib.request
import
urllib.parse
import
json
"""
利用“最美天气”抓取即时天气情况
http://www.zuimeitianqi.com/
"""
class
ZuiMei():
def
__init__(
self
):
self
.url
=
'http://www.zuimeitianqi.com/zuimei/queryWeather'
self
.headers
=
{}
self
.headers[
'User-Agent'
]
=
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36'
# 部分城市的id信息
self
.cities
=
{}
self
.cities[
'成都'
]
=
'01012703'
self
.cities[
'杭州'
]
=
'01013401'
self
.cities[
'深圳'
]
=
'01010715'
self
.cities[
'广州'
]
=
'01010704'
self
.cities[
'上海'
]
=
'01012601'
self
.cities[
'北京'
]
=
'01010101'
# Form Data
self
.data
=
{}
self
.city
=
'北京'
def
query(
self
,city
=
'北京'
):
if
city
not
in
self
.cities:
print
(
'暂时不支持当前城市'
)
return
self
.city
=
city
data
=
urllib.parse.urlencode({
'cityCode'
:
self
.cities[
self
.city]}).encode(
'utf-8'
)
req
=
urllib.request.Request(
self
.url,data,
self
.headers)
response
=
urllib.request.urlopen(req)
html
=
response.read().decode(
'utf-8'
)
# 解析json数据并打印结果
self
.json_parse(html)
def
json_parse(
self
,html):
target
=
json.loads(html)
high_temp
=
target[
'data'
][
0
][
'actual'
][
'high'
]
low_temp
=
target[
'data'
][
0
][
'actual'
][
'low'
]
current_temp
=
target[
'data'
][
0
][
'actual'
][
'tmp'
]
today_wea
=
target[
'data'
][
0
][
'actual'
][
'wea'
]
air_desc
=
target[
'data'
][
0
][
'actual'
][
'desc'
]
# 上海 6~-2°C 现在温度 1°C 湿度:53 空气质量不好,注意防霾。
print
(
'%s: %s~%s°C 现在温度 %s°C 湿度:%s %s'
%
(
self
.city,high_temp,low_temp,current_temp,today_wea,air_desc))
if
__name__
=
=
'__main__'
:
zuimei
=
ZuiMei()
zuimei.query(
'广州'
)
|
。
效果演示:
最后此篇关于python结合API实现即时天气信息的文章就讲到这里了,如果你想了解更多关于python结合API实现即时天气信息的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我已经四处寻找我的问题的解决方案,但它们似乎都涉及看似复杂的方法,如数据透视表、交叉表等。似乎必须有一个更简单的解决方案来解决那些没有解决的问题在我看来是一个特别复杂的问题。我正在使用 MS SQL
我在共享服务器上安装了 MySQL,并且可以通过 phpMyAdmin 进行访问。我想将该数据库连续实时克隆到云 mySQL 数据库(我们专门为此数据库创建了一个支持 Nginx 的 MySQL 服务
我目前正在围绕一个相当复杂的数据模型编写一个 Django 应用程序。对于许多用例,我需要构建相似但略有不同的模板(包括 graphviz 等)。 现在我想知道是否有一种方法可以遵循 DRY 并“即时
我选择了图片并在提交表单之前进行了预览。但是我想在选择图像并预览并提交文件后即时编辑文件。 js代码: var img = null; var canvas1 = document.g
目前,我们的网站存储 2/3 的固定图像尺寸。这些在上传时生成并通过我们的 CDN 分发。然而,我们需要实现更灵活的解决方案,我们正在开发需要多种不同尺寸的移动和平板电脑应用程序。我们建议的解决方案是
在 Google Wave 的介绍视频中,他们谈到了网络应用程序中的聊天问题。在许多 Web 应用程序中,您会看到如下消息: is typing.. (消息提交前) Google 想出了一个想法“在键
这个问题在这里已经有了答案: Formatting a number with leading zeros in PHP [duplicate] (11 个回答) 关闭3年前. PHP - 是否有一种
如何在VBA的“即时”窗口中打印二维数组?是否存在执行此操作的通用方法?一种在“即时”窗口中为每行绘制一排数组的方法可以解决此问题,因为唯一要做的就是为数组的每一行循环此代码。 最佳答案 我做了一个简
与非 JIT 编译器相比,JIT 编译器具体做什么?谁能给出一个简洁易懂的描述? 最佳答案 JIT 编译器在程序启动后运行,并将代码(通常是字节码或某种 VM 指令)动态(或称为即时)编译为通常更快的
我已经在我的 Windows 2003 服务器上安装了 VisualSVN,并将其配置为提供匿名读取访问。据我了解,VisualSVN 仅使用 apache 和下面的官方 SVN 存储库服务器。 现在
我正在开发一个使用 Twig 的 PHP 应用程序(但这并不重要)作为 View 层。这个 View 层有一个自定义扩展,允许我注册远程样式和脚本 Assets 以及样式和脚本内联 block 。系统
如今在许多网页上,您会经常看到带有指向目标的箭头的即时工具提示,类似于: https://www.w3schools.com/css/tryit.asp?filename=trycss_tooltip
我正在用 C++ 编写并在 Windows 中使用 OpenGL。 我创建了一个立方体,我希望它通过按“4”或“6”小键盘键围绕 y 轴旋转(使用 glRotate3f(),而不是 gluLookat
与非 JIT 编译器相比,JIT 编译器具体做什么?谁能给出一个简洁易懂的描述? 最佳答案 JIT 编译器在程序启动后运行,并将代码(通常是字节码或某种 VM 指令)动态(或称为即时)编译为通常更快的
这个问题在这里已经有了答案: 关闭 10 年前。
与非 JIT 编译器相比,JIT 编译器具体做什么?谁能给个简洁易懂的描述? 最佳答案 JIT 编译器在程序启动后运行,并将代码(通常是字节码或某种 VM 指令)即时(或所谓的即时)编译成通常速度更快
与非 JIT 编译器相比,JIT 编译器具体做什么?谁能给个简洁易懂的描述? 最佳答案 JIT 编译器在程序启动后运行,并将代码(通常是字节码或某种 VM 指令)即时(或所谓的即时)编译成通常速度更快
我希望能够即时将音频文件转换为 MP3 以供用户浏览器使用。我正在使用的软件是:ubuntu 系统上的 Apache、PHP 和 FFMPEG。这是我到目前为止的代码: 使用此代码,仅转换音频的前几
我正在使用 IntervalObservable 连续调用我的应用程序的服务器端。我可以订阅和取消订阅 Oberservable,一切正常,但有一个异常(exception): 对服务器的第一次调用被
从服务器上的文件夹压缩(比如 2 个文件)并强制下载的最简单方法是什么?不将“zip”保存到服务器。 $zip = new ZipArchive(); //the string "fil
我是一名优秀的程序员,十分优秀!