资源简介
# 可以这么用
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
相关资源
- jpype1for python3.5
- YouMoney有钱记账一个python写的开源的个
- PyYAML-3.12.tar.gz
- 基于opencv2的骨架提取代码 python实现
- json资料(python and c)
- B站用户数据爬取
- python3+Tkinter+GUI界面+pyserial+串口+串口
- Arcgis 基于Python的高斯扩散模型代码
- Python.CLF
- python实现2048游戏
- 大学排名爬虫
- annoy-1.15.2-cp36-cp36m-win_amd64.whl
- python矩阵乘法小程序
- python 音乐播放器
- Python分词系统jieba代码有注释,无报错
- Python生成3D图,饼图,合图,散点图,
- 树莓派目标跟踪代码python
- 简单的Python蚁群算法
- Python爬虫教程千万别错过
- get_wuyou.zip
- python入门到精通某智付费课程超级完
- 用python代码把背景颜色过滤掉
- python所有源代码
- PyHook3-1.6.1-cp36-cp36m-win32.whl
- L2正则化python实现案例()
- tensorflow手写数字识别python源码案例
- 批量excel转shp(面)python
- python ds evidence theory code
- Python串口调试助手
- 推荐系统物质扩散代码python
评论
共有 条评论