资源简介
# 可以这么用
weather = Weather_2345('广州', '201811', '201901')
print(weather.get_weather())
# 也可以这么用
weather = Weather_2345('下面会再次设置区域这里可以随便填', '201811', '201901')
area_list = ["白云", "从化", "花都", "海珠", "黄埔", "荔湾", "南沙", "番禺", "天河", "越秀", "增城"]
with open('./weather.log', 'w', encoding='utf-8') as fw:
fw.write("区域,日期,最高气温,最低气温,天气,风向,风力,空气指数,空气情况,空气等级" + "\n")
for area in area_list:
print()
weather.area = area
weather_list = weather.get_weather()
for lines in weather_list:
fw.write(",".join(lines) + '\n')
代码片段和文件信息
#!/usr/bin/env python
# -*- coding: utf-8 -*-
“““
__title__ = ‘‘
__author__ = ‘tiany‘
__mtime__ = ‘2019/1/25‘
# code is far away from bugs with the god animal protecting ~
“““
import demjson
import requests
class Weather_2345():
def __init__(self area begin_time end_time):
self.area self.begin_time self.end_time = area begin_time end_time
self.headers = {
“User-Agent“: “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML like Gecko) Chrome/65.0.3325.181 Safari/537.36“ }
self.prefix_url = “http://tianqi.2345.com/t/wea_history/js/{1}/{0}_{1}.js“
self.code_url = “http://tianqi.2345.com/js/citySelectData.js“
self.code_str = None
def get_weather(self):
‘‘‘
:return: 区域日期最高气温最低气温天气风向风力空气指数空气情况空气等级
‘‘‘
result = []
time_list = self.__generate_time_list(self.begin_time self.end_time)
for curr_month in time_list:
area_code = self.get_areacode(self.area)
url = self.prefix_url.format(area_code curr_month)
try:
response = requests.get(url headers=self.headers).text[16:-1]
response_dict = demjson.decode(response)
city = response_dict[‘city‘]
for line in response_dict[‘tqInfo‘]:
if line:
if “aqi“ in line:
result.append((city line[“ymd“] line[“bWendu“].rstrip(“℃“) line[“yWendu“].rstrip(“℃“)
line[“tianqi“] line[“fengxiang“] line[“fengli“] line[“aqi“]
line[“aqiInfo“] line[“a
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论