akshare 1.15.21__py3-none-any.whl → 1.15.22__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of akshare might be problematic. Click here for more details.

akshare/__init__.py CHANGED
@@ -2931,9 +2931,10 @@ amac_manager_cancelled_info # 中国证券投资基金业协会-信息公示-诚
2931
2931
  1.15.19 fix: fix stock_share_hold_change_szse indicator
2932
2932
  1.15.20 fix: fix rv_from_stock_zh_a_hist_min_em indicator
2933
2933
  1.15.21 fix: fix get_futures_daily indicator
2934
+ 1.15.22 fix: fix air_quality_hebei indicator
2934
2935
  """
2935
2936
 
2936
- __version__ = "1.15.21"
2937
+ __version__ = "1.15.22"
2937
2938
  __author__ = "AKFamily"
2938
2939
 
2939
2940
  import sys
akshare/air/air_hebei.py CHANGED
@@ -15,70 +15,93 @@ https://110.249.223.67/publish
15
15
  发布单位:河北省环境应急与重污染天气预警中心 技术支持:中国科学院大气物理研究所 中科三清科技有限公司
16
16
  """
17
17
 
18
- from datetime import datetime
19
-
20
18
  import pandas as pd
21
19
  import requests
22
- from tqdm import tqdm
20
+ from bs4 import BeautifulSoup
23
21
 
24
22
 
25
- def air_quality_hebei(symbol: str = "唐山市") -> pd.DataFrame:
23
+ def air_quality_hebei() -> pd.DataFrame:
26
24
  """
27
25
  河北省空气质量预报信息发布系统-空气质量预报, 未来 6 天
28
- https://110.249.223.67/publish/
29
- :param symbol: choice of {'石家庄市', '唐山市', '秦皇岛市', '邯郸市', '邢台市', '保定市', '张家口市', '承德市', '沧州市', '廊坊市', '衡水市', '辛集市', '定州市'}
30
- :type symbol: str
26
+ http://218.11.10.130:8080/#/application/home
31
27
  :return: city = "", 返回所有地区的数据; city="唐山市", 返回唐山市的数据
32
28
  :rtype: pandas.DataFrame
33
29
  """
34
- url = (
35
- "http://110.249.223.67/server/api/CityPublishInfo/GetProvinceAndCityPublishData"
36
- )
37
- params = {"publishDate": f"{datetime.today().strftime('%Y-%m-%d')} 16:00:00"}
38
- r = requests.get(url, params=params)
39
- json_data = r.json()
40
- city_list = pd.DataFrame.from_dict(json_data["cityPublishDatas"], orient="columns")[
41
- "CityName"
42
- ].tolist()
43
- outer_df = pd.DataFrame()
44
- for i in tqdm(range(1, 7), leave=False):
45
- inner_df = pd.DataFrame(
46
- [item[f"Date{i}"] for item in json_data["cityPublishDatas"]],
47
- index=city_list,
48
- )
49
- outer_df = pd.concat([outer_df, inner_df])
50
- if symbol == "":
51
- temp_df = outer_df.reset_index()
52
- temp_df.columns = [
53
- "city",
54
- "date",
55
- "pollutant",
56
- "minAQI",
57
- "maxAQI",
58
- "level",
59
- ]
60
- temp_df["date"] = pd.to_datetime(temp_df["date"]).dt.date
61
- temp_df["minaqi"] = pd.to_numeric(temp_df["minaqi"])
62
- temp_df["maxaqi"] = pd.to_numeric(temp_df["maxaqi"])
63
- return temp_df
64
- else:
65
- temp_df = outer_df.reset_index()
66
- temp_df.columns = [
67
- "city",
68
- "date",
69
- "pollutant",
70
- "minaqi",
71
- "maxaqi",
72
- "level",
73
- ]
74
- temp_df["date"] = pd.to_datetime(temp_df["date"]).dt.date
75
- temp_df["minaqi"] = pd.to_numeric(temp_df["minaqi"])
76
- temp_df["maxaqi"] = pd.to_numeric(temp_df["maxaqi"])
77
- temp_df = temp_df[temp_df["city"] == symbol]
78
- temp_df.reset_index(inplace=True, drop=True)
79
- return temp_df
30
+ url = "http://218.11.10.130:8080/api/hour/130000.xml"
31
+ r = requests.get(url)
32
+ soup = BeautifulSoup(r.content, features="xml")
33
+ data = []
34
+ cities = soup.find_all("City")
35
+ for city in cities:
36
+ pointers = city.find_all("Pointer")
37
+ for pointer in pointers:
38
+ row = {
39
+ "City": city.Name.text if city.Name else None,
40
+ "Region": pointer.Region.text if pointer.Region else None,
41
+ "Station": pointer.Name.text if pointer.Name else None,
42
+ "DateTime": pointer.DataTime.text if pointer.DataTime else None,
43
+ "AQI": pointer.AQI.text if pointer.AQI else None,
44
+ "Level": pointer.Level.text if pointer.Level else None,
45
+ "MaxPoll": pointer.MaxPoll.text if pointer.MaxPoll else None,
46
+ "Longitude": pointer.CLng.text if pointer.CLng else None,
47
+ "Latitude": pointer.CLat.text if pointer.CLat else None,
48
+ }
49
+ polls = pointer.find_all("Poll")
50
+ for poll in polls:
51
+ poll_name = poll.Name.text if poll.Name else None
52
+ poll_value = poll.Value.text if poll.Value else None
53
+ row[f"{poll_name}_Value"] = poll_value
54
+ row[f"{poll_name}_IAQI"] = poll.IAQI.text if poll.IAQI else None
55
+ data.append(row)
56
+
57
+ df = pd.DataFrame(data)
58
+ numeric_columns = ["AQI", "Longitude", "Latitude"] + [
59
+ col for col in df.columns if col.endswith("_Value") or col.endswith("_IAQI")
60
+ ]
61
+ for col in numeric_columns:
62
+ df[col] = pd.to_numeric(df[col], errors="coerce")
63
+
64
+ column_names = {
65
+ "City": "城市",
66
+ "Region": "区域",
67
+ "Station": "监测点",
68
+ "DateTime": "时间",
69
+ "Level": "空气质量等级",
70
+ "MaxPoll": "首要污染物",
71
+ "Longitude": "经度",
72
+ "Latitude": "纬度",
73
+ "SO2_Value": "二氧化硫_浓度",
74
+ "SO2_IAQI": "二氧化硫_IAQI",
75
+ "CO_Value": "一氧化碳_浓度",
76
+ "CO_IAQI": "一氧化碳_IAQI",
77
+ "NO2_Value": "二氧化氮_浓度",
78
+ "NO2_IAQI": "二氧化氮_IAQI",
79
+ "O3-1H_Value": "臭氧1小时_浓度",
80
+ "O3-1H_IAQI": "臭氧1小时_IAQI",
81
+ "O3-8H_Value": "臭氧8小时_浓度",
82
+ "O3-8H_IAQI": "臭氧8小时_IAQI",
83
+ "PM2.5_Value": "PM2.5_浓度",
84
+ "PM2.5_IAQI": "PM2.5_IAQI",
85
+ "PM10_Value": "PM10_浓度",
86
+ "PM10_IAQI": "PM10_IAQI",
87
+ }
88
+ df = df.rename(columns=column_names)
89
+ basic_columns = [
90
+ "城市",
91
+ "区域",
92
+ "监测点",
93
+ "时间",
94
+ "AQI",
95
+ "空气质量等级",
96
+ "首要污染物",
97
+ "经度",
98
+ "纬度",
99
+ ]
100
+ pollutant_columns = [col for col in df.columns if col not in basic_columns]
101
+ df = df[basic_columns + sorted(pollutant_columns)]
102
+ return df
80
103
 
81
104
 
82
105
  if __name__ == "__main__":
83
- air_quality_hebei_df = air_quality_hebei(symbol="定州市")
106
+ air_quality_hebei_df = air_quality_hebei()
84
107
  print(air_quality_hebei_df)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: akshare
3
- Version: 1.15.21
3
+ Version: 1.15.22
4
4
  Summary: AKShare is an elegant and simple financial data interface library for Python, built for human beings!
5
5
  Home-page: https://github.com/akfamily/akshare
6
6
  Author: AKFamily
@@ -1,9 +1,9 @@
1
- akshare/__init__.py,sha256=kZ1m2-OHKCI5xXz2lfc0MLGiOtR71Y2pnlCEve0WsUA,183752
1
+ akshare/__init__.py,sha256=AXVv2_gqZdsjH1cyySkVhQP5U2Btx4t2ktLayHcBrwc,183797
2
2
  akshare/datasets.py,sha256=-qdwaQjgBlftX84uM74KJqCYJYkQ50PV416_neA4uls,995
3
3
  akshare/exceptions.py,sha256=WEJjIhSmJ_xXNW6grwV4nufE_cfmmyuhmueVGiN1VAg,878
4
4
  akshare/request.py,sha256=HtFFf9MhfEibR-ETWe-1Tts6ELU4VKSqA-ghaXjegQM,4252
5
5
  akshare/air/__init__.py,sha256=RMTf1bT5EOE3ttWpn3hGu1LtUmsVxDoa0W7W0gXHOy8,81
6
- akshare/air/air_hebei.py,sha256=xIXNGLK7IGYqrkteM9fxnHAwWqk6PCQs6D9-ggZ7byY,4442
6
+ akshare/air/air_hebei.py,sha256=jFhsi41EfSGYpRUo98bvJ1oer1FPiQgw1grSrb_q5Yg,5415
7
7
  akshare/air/air_zhenqi.py,sha256=FurRxuYyoZpTa2lsP6BgUJfbfMgOO26_VPuc-ekKZXs,9636
8
8
  akshare/air/cons.py,sha256=v4TGVepsboZUpKgeuBdoSGlf7KVZPq783FfaXqtJNDA,9771
9
9
  akshare/air/crypto.js,sha256=0V4nL8-myB3vu9J-P3YEEg67Lw9ht-q9cS0odAuJsD0,8443
@@ -383,8 +383,8 @@ akshare/utils/token_process.py,sha256=K4rGXjh_tgugbRcyOK2h2x0jP3PT65IIK7nxhUKhOe
383
383
  akshare/utils/tqdm.py,sha256=MuPNwcswkOGjwWQOMWXi9ZvQ_RmW4obCWRj2i7HM7FE,847
384
384
  tests/__init__.py,sha256=gNzhlO0UPjFq6Ieb38kaVIODXv4cTDByrdohAZnDYt4,82
385
385
  tests/test_func.py,sha256=j1MGYbZI2if2j_LY1S4FLsf4qfq4NwVqD5wmRlv5Log,832
386
- akshare-1.15.21.dist-info/LICENSE,sha256=mmSZCPgfHiVw34LXuFArd-SUgQtBJ_QsIlh-kWlDHfs,1073
387
- akshare-1.15.21.dist-info/METADATA,sha256=ro5R5nJrKj_SNlSQOtbWvo3aIvftW0Z-GLLJu-Jo4UU,14259
388
- akshare-1.15.21.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
389
- akshare-1.15.21.dist-info/top_level.txt,sha256=jsf9ZzZPmHaISTVumQPsAw7vv7Yv-PdEVW70SMEelQQ,14
390
- akshare-1.15.21.dist-info/RECORD,,
386
+ akshare-1.15.22.dist-info/LICENSE,sha256=mmSZCPgfHiVw34LXuFArd-SUgQtBJ_QsIlh-kWlDHfs,1073
387
+ akshare-1.15.22.dist-info/METADATA,sha256=5kDb9qRTYO_boKapiejhKgm2GZUwl0WMEfIMa5_vB5k,14259
388
+ akshare-1.15.22.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
389
+ akshare-1.15.22.dist-info/top_level.txt,sha256=jsf9ZzZPmHaISTVumQPsAw7vv7Yv-PdEVW70SMEelQQ,14
390
+ akshare-1.15.22.dist-info/RECORD,,