Skip to content

Commit

Permalink
feat(stock_hot_deal_xq): add stock_hot_deal_xq interface
Browse files Browse the repository at this point in the history
add stock_hot_deal_xq interface
  • Loading branch information
ak-quant committed Apr 27, 2022
1 parent 7d7901c commit 6b1d60c
Show file tree
Hide file tree
Showing 7 changed files with 522 additions and 2 deletions.
17 changes: 16 additions & 1 deletion akshare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1964,9 +1964,10 @@
1.5.42 fix: fix stock_zt_pool_dtgc_em interface
1.5.43 fix: fix stock_zt_pool_em interface
1.5.44 fix: fix futures_to_spot_czce interface
1.5.45 add: add stock_hot_deal_xq interface
"""

__version__ = "1.5.44"
__version__ = "1.5.45"
__author__ = "AKFamily"

import sys
Expand All @@ -1977,6 +1978,20 @@

del sys

"""
股票热度-淘股吧
"""
from akshare.stock_feature.stock_hot_tgb import stock_hot_tgb

"""
股票热度-雪球
"""
from akshare.stock_feature.stock_hot_xq import (
stock_hot_deal_xq,
stock_hot_follow_xq,
stock_hot_tweet_xq,
)

"""
南华期货-板块指数涨跌
南华期货-品种指数涨跌
Expand Down
2 changes: 1 addition & 1 deletion akshare/index/drewry_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding:utf-8 -*-
"""
Date: 2021/9/23 15:38
Desc: Drewry集装箱指数
Desc: Drewry 集装箱指数
https://www.drewry.co.uk/supply-chain-advisors/supply-chain-expertise/world-container-index-assessed-by-drewry
https://infogram.com/world-container-index-1h17493095xl4zj
"""
Expand Down
32 changes: 32 additions & 0 deletions akshare/stock_feature/stock_hot_tgb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding:utf-8 -*-
# !/usr/bin/env python
"""
Date: 2022/4/27 17:01
Desc: 淘股吧-热门股票
https://www.taoguba.com.cn/stock/moreHotStock
"""
import pandas as pd
import requests


def stock_hot_tgb() -> pd.DataFrame:
"""
淘股吧-热门股票
https://www.taoguba.com.cn/stock/moreHotStock
:return: 热门股票
:rtype: pandas.DataFrame
"""
url = "https://www.taoguba.com.cn/stock/moreHotStock"
r = requests.get(url)
temp_df = pd.concat([pd.read_html(r.text, header=0)[0], pd.read_html(r.text, header=0)[1]])
temp_df = temp_df[[
"个股代码",
"个股名称",
]]
temp_df.reset_index(inplace=True, drop=True)
return temp_df


if __name__ == '__main__':
stock_hot_tgb_df = stock_hot_tgb()
print(stock_hot_tgb_df)
248 changes: 248 additions & 0 deletions akshare/stock_feature/stock_hot_xq.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
# -*- coding:utf-8 -*-
# !/usr/bin/env python
"""
Date: 2022/4/27 17:01
Desc: 雪球-沪深股市-热度排行榜
https://xueqiu.com/hq
"""
import pandas as pd
import requests


def stock_hot_follow_xq(symbol: str = "本周新增") -> pd.DataFrame:
"""
雪球-沪深股市-热度排行榜-关注排行榜
https://xueqiu.com/hq
:param symbol: choice of {"本周新增", "最热门"}
:type symbol: str
:return: 关注排行榜
:rtype: pandas.DataFrame
"""
symbol_map = {
"本周新增": "follow7d",
"最热门": "follow",
}
url = "https://xueqiu.com/service/v5/stock/screener/screen"
params = {
"category": "CN",
"size": "10000",
"order": "desc",
"order_by": symbol_map[symbol],
"only_count": "0",
"page": "1",
"_": "1651050034006",
}
headers = {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Host": "xueqiu.com",
"Pragma": "no-cache",
"Referer": "https://xueqiu.com/hq",
"sec-ch-ua": '" Not A;Brand";v="99", "Chromium";v="100", "Google Chrome";v="100"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
"X-Requested-With": "XMLHttpRequest",
}
r = requests.get(url, params=params, headers=headers)
data_json = r.json()
temp_df = pd.DataFrame(data_json["data"]["list"])
if symbol == "本周新增":
temp_df = temp_df[
[
"symbol",
"name",
"follow7d",
"current",
]
]
else:
temp_df = temp_df[
[
"symbol",
"name",
"follow",
"current",
]
]
temp_df.columns = [
"股票代码",
"股票简称",
"关注",
"最新价",
]
temp_df["关注"] = pd.to_numeric(temp_df["关注"])
temp_df["最新价"] = pd.to_numeric(temp_df["最新价"])
return temp_df


def stock_hot_tweet_xq(symbol: str = "本周新增") -> pd.DataFrame:
"""
雪球-沪深股市-热度排行榜-讨论排行榜
https://xueqiu.com/hq
:param symbol: choice of {"本周新增", "最热门"}
:type symbol: str
:return: 讨论排行榜
:rtype: pandas.DataFrame
"""
symbol_map = {
"本周新增": "tweet7d",
"最热门": "tweet",
}
url = "https://xueqiu.com/service/v5/stock/screener/screen"
params = {
"category": "CN",
"size": "10000",
"order": "desc",
"order_by": symbol_map[symbol],
"only_count": "0",
"page": "1",
"_": "1651050034006",
}
headers = {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Host": "xueqiu.com",
"Pragma": "no-cache",
"Referer": "https://xueqiu.com/hq",
"sec-ch-ua": '" Not A;Brand";v="99", "Chromium";v="100", "Google Chrome";v="100"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
"X-Requested-With": "XMLHttpRequest",
}
r = requests.get(url, params=params, headers=headers)
data_json = r.json()
temp_df = pd.DataFrame(data_json["data"]["list"])
if symbol == "本周新增":
temp_df = temp_df[
[
"symbol",
"name",
"tweet7d",
"current",
]
]
else:
temp_df = temp_df[
[
"symbol",
"name",
"tweet",
"current",
]
]
temp_df.columns = [
"股票代码",
"股票简称",
"关注",
"最新价",
]
temp_df["关注"] = pd.to_numeric(temp_df["关注"])
temp_df["最新价"] = pd.to_numeric(temp_df["最新价"])
return temp_df


def stock_hot_deal_xq(symbol: str = "本周新增") -> pd.DataFrame:
"""
雪球-沪深股市-热度排行榜-分享交易排行榜
https://xueqiu.com/hq
:param symbol: choice of {"本周新增", "最热门"}
:type symbol: str
:return: 分享交易排行榜
:rtype: pandas.DataFrame
"""
symbol_map = {
"本周新增": "deal7d",
"最热门": "deal",
}
url = "https://xueqiu.com/service/v5/stock/screener/screen"
params = {
"category": "CN",
"size": "10000",
"order": "desc",
"order_by": symbol_map[symbol],
"only_count": "0",
"page": "1",
"_": "1651050034006",
}
headers = {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Host": "xueqiu.com",
"Pragma": "no-cache",
"Referer": "https://xueqiu.com/hq",
"sec-ch-ua": '" Not A;Brand";v="99", "Chromium";v="100", "Google Chrome";v="100"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
"X-Requested-With": "XMLHttpRequest",
}
r = requests.get(url, params=params, headers=headers)
data_json = r.json()
temp_df = pd.DataFrame(data_json["data"]["list"])
if symbol == "本周新增":
temp_df = temp_df[
[
"symbol",
"name",
"deal7d",
"current",
]
]
else:
temp_df = temp_df[
[
"symbol",
"name",
"deal",
"current",
]
]
temp_df.columns = [
"股票代码",
"股票简称",
"关注",
"最新价",
]
temp_df["关注"] = pd.to_numeric(temp_df["关注"])
temp_df["最新价"] = pd.to_numeric(temp_df["最新价"])
return temp_df


if __name__ == "__main__":
stock_hot_follow_xq_df = stock_hot_follow_xq(symbol="本周新增")
print(stock_hot_follow_xq_df)

stock_hot_follow_xq_df = stock_hot_follow_xq(symbol="最热门")
print(stock_hot_follow_xq_df)

stock_hot_tweet_xq_df = stock_hot_tweet_xq(symbol="本周新增")
print(stock_hot_tweet_xq_df)

stock_hot_tweet_xq_df = stock_hot_tweet_xq(symbol="最热门")
print(stock_hot_tweet_xq_df)

stock_hot_deal_xq_df = stock_hot_deal_xq(symbol="本周新增")
print(stock_hot_deal_xq_df)

stock_hot_deal_xq_df = stock_hot_deal_xq(symbol="最热门")
print(stock_hot_deal_xq_df)
6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

## 更新说明

1.5.45 add: add stock_hot_deal_xq interface

1. 新增 stock_hot_deal_xq 接口,获取雪球-沪深股市-热度排行榜-分享交易排行榜数据

1.5.44 fix: fix futures_to_spot_czce interface

1. 修复 futures_to_spot_czce 接口,直接读取 Excel 文件并规范输出的字段类型
Expand Down Expand Up @@ -441,6 +445,8 @@

## 版本更新说明

1.5.45 add: add stock_hot_deal_xq interface

1.5.44 fix: fix futures_to_spot_czce interface

1.5.43 fix: fix stock_zt_pool_em interface
Expand Down
Loading

0 comments on commit 6b1d60c

Please sign in to comment.