Skip to content

Commit

Permalink
Fin (#3996)
Browse files Browse the repository at this point in the history
* add version

* fix stock_financial_report_sina
  • Loading branch information
albertandking authored Jul 20, 2023
1 parent 8c900fb commit 4242747
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 32 deletions.
3 changes: 2 additions & 1 deletion akshare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2480,9 +2480,10 @@
1.10.63 fix: fix stock_esg_hz_sina interface
1.10.64 fix: fix stock_zh_b_spot interface
1.10.65 fix: fix macro_china_lpr interface
1.10.66 fix: fix stock_financial_report_sina interface
"""

__version__ = "1.10.65"
__version__ = "1.10.66"
__author__ = "AKFamily"

import sys
Expand Down
43 changes: 23 additions & 20 deletions akshare/stock_fundamental/stock_finance.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2023/2/14 22:25
Date: 2023/7/20 15:00
Desc: 股票基本面数据
新浪财经-财务报表-财务摘要
https://vip.stock.finance.sina.com.cn/corp/go.php/vFD_FinanceSummary/stockid/600004.phtml
Expand All @@ -10,7 +10,6 @@
新浪财经-发行与分配
https://money.finance.sina.com.cn/corp/go.php/vISSUE_ShareBonus/stockid/600004.phtml
"""
from io import BytesIO
from datetime import datetime

import pandas as pd
Expand Down Expand Up @@ -49,6 +48,7 @@ def stock_financial_report_sina(
data_json = r.json()
df_columns = [item['date_value'] for item in data_json["result"]["data"]["report_date"]]
big_df = pd.DataFrame()
temp_df = pd.DataFrame()
for date_str in df_columns:
temp_df = pd.DataFrame(
data_json["result"]["data"]["report_list"][date_str]["data"]
Expand Down Expand Up @@ -86,6 +86,8 @@ def stock_financial_report_sina(
big_df = big_df.T
big_df.columns = temp_df["项目"]
big_df = pd.concat([pd.DataFrame({"报告日": df_columns}), big_df], axis=1)
# 此处有 '国内票证结算' 和 '内部应收款'字段重复
big_df = big_df.loc[:, ~big_df.columns.duplicated(keep='first')]
return big_df


Expand Down Expand Up @@ -283,13 +285,13 @@ def stock_history_dividend_detail(
del temp_df["查看详细"]
if temp_df.iloc[0, 0] == "暂时没有数据!":
return pd.DataFrame()
temp_df["公告日期"] = pd.to_datetime(temp_df["公告日期"]).dt.date
temp_df["送股"] = pd.to_numeric(temp_df["送股"])
temp_df["转增"] = pd.to_numeric(temp_df["转增"])
temp_df["派息"] = pd.to_numeric(temp_df["派息"])
temp_df["除权除息日"] = pd.to_datetime(temp_df["除权除息日"], errors="coerce").dt.date
temp_df["股权登记日"] = pd.to_datetime(temp_df["股权登记日"], errors="coerce").dt.date
temp_df["红股上市日"] = pd.to_datetime(temp_df["红股上市日"], errors="coerce").dt.date
temp_df["公告日期"] = pd.to_datetime(temp_df["公告日期"], errors="coerce").dt.date
temp_df["送股"] = pd.to_numeric(temp_df["送股"], errors="coerce")
temp_df["转增"] = pd.to_numeric(temp_df["转增"], errors="coerce")
temp_df["派息"] = pd.to_numeric(temp_df["派息"], errors="coerce")
temp_df["除权除息日"] = pd.to_datetime(temp_df["除权除息日"], format="%Y-%m-%d", errors="coerce").dt.date
temp_df["股权登记日"] = pd.to_datetime(temp_df["股权登记日"], format="%Y-%m-%d", errors="coerce").dt.date
temp_df["红股上市日"] = pd.to_datetime(temp_df["红股上市日"], format="%Y-%m-%d", errors="coerce").dt.date
if date:
url = "https://vip.stock.finance.sina.com.cn/corp/view/vISSUE_ShareBonusDetail.php"
params = {
Expand Down Expand Up @@ -324,16 +326,17 @@ def stock_history_dividend_detail(
del temp_df["查看详细"]
if temp_df.iloc[0, 0] == "暂时没有数据!":
return pd.DataFrame()
temp_df["公告日期"] = pd.to_datetime(temp_df["公告日期"]).dt.date
temp_df["配股方案"] = pd.to_numeric(temp_df["配股方案"])
temp_df["配股价格"] = pd.to_numeric(temp_df["配股价格"])
temp_df["基准股本"] = pd.to_numeric(temp_df["基准股本"])
temp_df["除权日"] = pd.to_datetime(temp_df["除权日"]).dt.date
temp_df["股权登记日"] = pd.to_datetime(temp_df["股权登记日"]).dt.date
temp_df["缴款起始日"] = pd.to_datetime(temp_df["缴款起始日"]).dt.date
temp_df["缴款终止日"] = pd.to_datetime(temp_df["缴款终止日"]).dt.date
temp_df["配股上市日"] = pd.to_datetime(temp_df["配股上市日"]).dt.date
temp_df["募集资金合计"] = pd.to_numeric(temp_df["募集资金合计"])
temp_df["公告日期"] = pd.to_datetime(temp_df["公告日期"], errors="coerce").dt.date
temp_df["配股方案"] = pd.to_numeric(temp_df["配股方案"], errors="coerce")
temp_df["配股价格"] = pd.to_numeric(temp_df["配股价格"], errors="coerce")
temp_df["基准股本"] = pd.to_numeric(temp_df["基准股本"], errors="coerce")
temp_df["募集资金合计"] = pd.to_numeric(temp_df["募集资金合计"], errors="coerce")
temp_df["除权日"] = pd.to_datetime(temp_df["除权日"], format="%Y-%m-%d", errors="coerce").dt.date
temp_df["股权登记日"] = pd.to_datetime(temp_df["股权登记日"], format="%Y-%m-%d", errors="coerce").dt.date
temp_df["缴款起始日"] = pd.to_datetime(temp_df["缴款起始日"], format="%Y-%m-%d", errors="coerce").dt.date
temp_df["缴款终止日"] = pd.to_datetime(temp_df["缴款终止日"], format="%Y-%m-%d", errors="coerce").dt.date
temp_df["配股上市日"] = pd.to_datetime(temp_df["配股上市日"], format="%Y-%m-%d", errors="coerce").dt.date

if date:
url = "https://vip.stock.finance.sina.com.cn/corp/view/vISSUE_ShareBonusDetail.php"
params = {
Expand Down Expand Up @@ -378,7 +381,7 @@ def stock_add_stock(stock: str = "688166") -> pd.DataFrame:
r = requests.get(url)
temp_df = pd.read_html(r.text)[12]
if temp_df.at[0, 0] == "对不起,暂时没有相关增发记录":
return f"股票 {stock} 无增发记录"
raise f"股票 {stock} 无增发记录"
big_df = pd.DataFrame()
for i in range(int(len(temp_df.at[0, 1]) / 10)):
temp_df = pd.read_html(r.text)[13 + i].iloc[:, 1]
Expand Down
6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@

## 更新说明详情

1.10.66 fix: fix stock_financial_report_sina interface

1. 修复 stock_financial_report_sina 接口

1.10.65 fix: fix macro_china_lpr interface

1. 修复 macro_china_lpr 接口
Expand Down Expand Up @@ -2674,6 +2678,8 @@

## 版本更新说明

1.10.66 fix: fix stock_financial_report_sina interface

1.10.65 fix: fix macro_china_lpr interface

1.10.64 fix: fix stock_zh_b_spot interface
Expand Down
25 changes: 14 additions & 11 deletions docs/data/stock/stock.md
Original file line number Diff line number Diff line change
Expand Up @@ -9831,6 +9831,8 @@ print(stock_notice_report_df)

限量: 单次获取指定报表的所有年份数据的历史数据

注意: 原始数据中有 '国内票证结算' 和 '内部应收款'字段重, 返回数据中已经剔除

输入参数

| 名称 | 类型 | 描述 |
Expand Down Expand Up @@ -9860,18 +9862,19 @@ print(stock_financial_report_sina_df)
数据示例

```
报告日 流动资产 货币资金 ... 币种 类型 更新日期
0 20221231 NaN 17854931855.0 ... CNY 合并期末 2023-03-22T20:50:09
1 20220930 NaN 17045567340.0 ... CNY 合并期末 2022-10-26T17:20:07
2 20220630 NaN 17587197778.0 ... CNY 合并期末 2022-08-25T21:25:04
3 20220331 NaN 12818371932.0 ... CNY 合并期末 2022-04-28T16:20:04
4 20211231 NaN 14597590313.0 ... CNY 合并期末 2022-03-29T01:05:06
报告日 流动资产 货币资金 ... 币种 类型 更新日期
0 20230331 NaN 15554422004.0 ... CNY 合并期末 2023-04-24T18:05:05
1 20221231 NaN 17854931855.0 ... CNY 合并期末 2023-03-22T20:50:09
2 20220930 NaN 17045567340.0 ... CNY 合并期末 2022-10-26T17:20:07
3 20220630 NaN 17587197778.0 ... CNY 合并期末 2022-08-25T21:25:04
4 20220331 NaN 12818371932.0 ... CNY 合并期末 2022-04-28T16:20:04
.. ... ... ... ... ... ... ...
95 19960630 NaN NaN ... CNY 合并期末 2020-03-13T15:29:48
96 19951231 NaN 741738874.0 ... CNY 合并期末 2020-03-13T15:29:48
97 19950630 NaN NaN ... CNY 合并期末 2020-03-13T15:29:48
98 19941231 NaN 712428000.0 ... CNY 合并期末 2020-03-13T15:29:48
99 19940630 NaN NaN ... CNY 合并期末 2020-03-13T15:29:48
95 19961231 NaN 671405728.0 ... CNY 合并期末 2020-03-13T15:29:48
96 19960630 NaN NaN ... CNY 合并期末 2020-03-13T15:29:48
97 19951231 NaN 741738874.0 ... CNY 合并期末 2020-03-13T15:29:48
98 19950630 NaN NaN ... CNY 合并期末 2020-03-13T15:29:48
99 19941231 NaN 712428000.0 ... CNY 合并期末 2020-03-13T15:29:48
[100 rows x 147 columns]
```

#### 财务报表-东财
Expand Down

0 comments on commit 4242747

Please sign in to comment.