-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85d211f
commit 0d24c15
Showing
5 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# encoding: utf-8 | ||
|
||
from opendatatools import wscn | ||
|
||
if __name__ == '__main__': | ||
wscn.login("18612562791", "xxxxxx") | ||
df, msg = wscn.get_xuangubao_theme() | ||
|
||
for index, row in df.iterrows(): | ||
tid = int(row["plate_id"]) | ||
df_data, msg2 = wscn.get_xuangubao_theme_event(tid) | ||
print(df_data["Title"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# encoding: utf-8 | ||
|
||
from .wscn_interface import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# encoding: utf-8 | ||
|
||
from opendatatools.common import RestAgent | ||
import json | ||
import datetime | ||
import io | ||
import pandas as pd | ||
|
||
class XuangubaoAgent(RestAgent): | ||
def __init__(self): | ||
RestAgent.__init__(self) | ||
self.token = None | ||
self.add_headers({ | ||
"x-appgo-platform" : "device=pc", | ||
"referer" : "https://xuangubao.cn/zhutiku", | ||
"origin": "https://xuangubao.cn", | ||
}) | ||
|
||
def login(self, username, password): | ||
url = "https://api.xuangubao.cn/api/account/mobile_login" | ||
data = { | ||
'Mobile' : username, | ||
'Password' : password, | ||
} | ||
|
||
response = self.do_request(url, param = json.dumps(data), method="POST") | ||
if response is not None: | ||
rsp = json.loads(response) | ||
self.token = rsp["Token"] | ||
self.add_headers({ | ||
"token" : self.token | ||
}) | ||
return True | ||
else: | ||
return False | ||
|
||
def get_theme(self): | ||
url = "https://wows-api.wallstreetcn.com/v3/aioria/plates/rank?count=10000&is_asc=true&rank_type=core_pcp_rank" | ||
response = self.do_request(url, method="GET") | ||
if response is not None: | ||
rsp = json.loads(response) | ||
cols = rsp["data"]['fields'] | ||
items = rsp["data"]['items'] | ||
df = pd.DataFrame(items) | ||
df.columns = cols | ||
return df, "" | ||
else: | ||
return None, "获取数据失败" | ||
|
||
def get_theme_stock(self, tid): | ||
url = "https://wows-api.wallstreetcn.com/v3/aioria/sset/bankuaiji?id=%d&terminal=pc" % tid | ||
self.add_headers({ | ||
"X-Appgo-Token" : self.token | ||
}) | ||
response = self.do_request(url, method="GET") | ||
if response is not None: | ||
rsp = json.loads(response) | ||
login_flag = rsp["data"]["login_flag"] | ||
if login_flag == True: | ||
stocks = rsp["data"]['stocks'] | ||
df = pd.DataFrame(stocks) | ||
return df, "" | ||
else: | ||
return None, "请首先登录 login" | ||
else: | ||
return None, "获取数据失败" | ||
|
||
def get_theme_kline(self, tid): | ||
url = "https://wows-api.wallstreetcn.com/v3/aioria/index/kline?prod_code=%s&data_count=10000" % tid | ||
response = self.do_request(url, method="GET") | ||
if response is not None: | ||
rsp = json.loads(response) | ||
data = rsp["data"]["candle"][str(tid)] | ||
cols = rsp["data"]["candle"]["fields"] | ||
df = pd.DataFrame(data) | ||
df.columns = cols | ||
df["min_time"] = df["min_time"].apply(lambda x: datetime.datetime.fromtimestamp(x).strftime("%Y-%m-%d")) | ||
return df, "" | ||
else: | ||
return None, "获取数据失败" | ||
|
||
def get_theme_event_onepage(self, tid, tail): | ||
url = "https://api.xuangubao.cn/api/pc/bkjMsgs/%d?limit=50&TailMark=%d" % (tid, tail) | ||
response = self.do_request(url, method="GET") | ||
if response is not None: | ||
rsp = json.loads(response) | ||
data = rsp["Messages"] | ||
TailMark = int(rsp["TailMark"]) | ||
df = pd.DataFrame(data) | ||
if len(df) > 0: | ||
return df, TailMark | ||
|
||
return None, 0 | ||
|
||
def get_theme_event(self, tid): | ||
df_list = [] | ||
tail = 0 | ||
while True: | ||
df, tail = self.get_theme_event_onepage(tid, tail) | ||
if df is not None: | ||
df_list.append(df) | ||
else: | ||
break | ||
|
||
if len(df_list)>1: | ||
df = pd.concat(df_list) | ||
df["CreatedAt"] = df["CreatedAt"].apply(lambda x : datetime.datetime.fromtimestamp(x)) | ||
df["UpdatedAt"] = df["UpdatedAt"].apply(lambda x : datetime.datetime.fromtimestamp(x)) | ||
df["ManualUpdatedAt"] = df["ManualUpdatedAt"].apply(lambda x : datetime.datetime.fromtimestamp(x)) | ||
df = df.set_index("Id") | ||
return df, "" | ||
|
||
return None, "获取数据失败" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# encoding: utf-8 | ||
|
||
from .wscn_agent import XuangubaoAgent | ||
|
||
xgb_agent = XuangubaoAgent() | ||
|
||
|
||
def login(username, password): | ||
return xgb_agent.login(username, password) | ||
|
||
def get_xuangubao_theme(): | ||
return xgb_agent.get_theme() | ||
|
||
def get_xuangubao_theme_stock(tid): | ||
return xgb_agent.get_theme_stock(tid) | ||
|
||
def get_xuangubao_theme_kline(tid): | ||
return xgb_agent.get_theme_kline(tid) | ||
|
||
def get_xuangubao_theme_event(tid): | ||
return xgb_agent.get_theme_event(tid) |