import requests
import pandas as pd
import numpy as np
def Get_NearestDt():
write_file = 'Nearest.csv'
codes_file = 'all_codes.csv'
code_list = pd.read_csv(codes_file)
codes = code_list['ts_code'].values
names = code_list['name'].values
code_array = np.array([])
name_array = np.array([])
numDate_array = np.array([])
for code, name in zip(codes, names):
nearestUrl = 'https://quantstrategy.igoldenbeta.com:4443/signal/getsearchsecurity?secuEncode=' + code + '&type=0'
r = requests.get(nearestUrl)
#print(r.text)
text = r.text.replace('null', '"*"')
dictX = eval(text)
try:
date = dictX['data']['nearestDt']
date = date.replace('-', '')
numDate = int(date)
if numDate > 20200801:
print(code, name, numDate)
code_array = np.append(code_array, code)
name_array = np.append(name_array, name)
numDate_array = np.append(numDate_array, numDate)
data = [code_array, name_array, numDate_array]
data = np.transpose(data)
ser2 = pd.DataFrame(data, columns=['ts_code', 'name', '日期'])
ser2.to_csv(write_file, encoding="utf_8_sig")
except Exception:
print(r.text)
continue
#获取代码对应的名字
def get_code_name(ts_code):
code_list = pd.read_csv('all_codes.csv')
codes = code_list['ts_code'].values
names = code_list['name'].values
i = 0
for code in codes:
if code == ts_code:
return names[i]
else:
i = i+1
print('NOName ************************** NoName')
return 'noName'
def Get_All_Score():
rank_array= np.array([])
level_array = np.array([])
indNetProfitGRScore_array = np.array([])
safetyScore_array = np.array([])
pbpeScore_array = np.array([])
crashScore_array = np.array([])
roeScore_array = np.array([])
industryStockCount_array = np.array([])
industryName_array = np.array([])
code_array = np.array([])
name_array = np.array([])
write_file = 'kingB.csv'
codes_file = 'all_codes.csv'
code_list = pd.read_csv(codes_file)
codes = code_list['ts_code'].values
names = code_list['name'].values
for code, name in zip(codes, names):
nearestUrl = 'https://cfhstock.igoldenbeta.com:9443/stock-web/detail.fopcors?code=' + code + '&type=0'
r = requests.get(nearestUrl)
#print(r.text)
text = r.text.replace('null', '"*"')
dictX = eval(text)
try:
#好于同行
rank = dictX['data']['rank']
level = dictX['data']['level']
if int(level) > 3:
#成长性
indNetProfitGRScore = dictX['data']['indNetProfitGRScore']
#安全性
safetyScore = dictX['data']['safetyScore']
#便宜度
pbpeScore = dictX['data']['pbpeScore']
#盈利性
roeScore = dictX['data']['roeScore']
# 现金流
crashScore = dictX['data']['crashScore']
# 基金持仓数
industryStockCount = dictX['data']['industryStockCount']
#行业
industryName = dictX['data']['industryName']
code_array = np.append(code_array, code)
name_array = np.append(name_array, name)
rank_array = np.append(rank_array, rank)
industryName_array = np.append(industryName_array, industryName)
indNetProfitGRScore_array = np.append(indNetProfitGRScore_array, indNetProfitGRScore)
safetyScore_array = np.append(safetyScore_array, safetyScore)
pbpeScore_array = np.append(pbpeScore_array, pbpeScore)
roeScore_array = np.append(roeScore_array, roeScore)
crashScore_array = np.append(crashScore_array, crashScore)
industryStockCount_array = np.append(industryStockCount_array, industryStockCount)
level_array = np.append(level_array, level)
print(code, name, '得分', rank, '成长性', indNetProfitGRScore, '安全性', safetyScore, '便宜度', pbpeScore, '盈利性',
roeScore, '现金流', crashScore, '行业', industryName, dictX['data'])
data = [code_array, name_array, rank_array, industryName_array, indNetProfitGRScore_array,
safetyScore_array,
pbpeScore_array, roeScore_array, crashScore_array, industryStockCount_array, level_array]
data = np.transpose(data)
ser2 = pd.DataFrame(data, columns=['ts_code', 'name', '得分', '行业', '成长性', '安全度', '便宜度', '盈利度', '现金流', '基金数', '等级'])
ser2.to_csv(write_file, encoding="utf_8_sig")
except Exception:
print(r.text)
continue
#r = requests.get('https://cfhstock.igoldenbeta.com:9443/stock-web/detail.fopcors?code=002557.SZ&type=0')
#print(r.text)
def Get_Code_Score(code):
name = get_code_name(code)
nearestUrl = 'https://cfhstock.igoldenbeta.com:9443/stock-web/detail.fopcors?code=' + code + '&type=0'
r = requests.get(nearestUrl)
# print(r.text)
text = r.text.replace('null', '"*"')
dictX = eval(text)
try:
# 好于同行
rank = dictX['data']['rank']
level = dictX['data']['level']
if int(level) > 3:
# 成长性
indNetProfitGRScore = dictX['data']['indNetProfitGRScore']
# 安全性
safetyScore = dictX['data']['safetyScore']
# 便宜度
pbpeScore = dictX['data']['pbpeScore']
# 盈利性
roeScore = dictX['data']['roeScore']
# 现金流
crashScore = dictX['data']['crashScore']
# 基金持仓数
industryStockCount = dictX['data']['industryStockCount']
# 行业
industryName = dictX['data']['industryName']
print(code, name, '得分', rank, '成长性', indNetProfitGRScore, '安全性', safetyScore, '便宜度', pbpeScore, '盈利性',
roeScore, '现金流', crashScore, '行业', industryName, dictX['data'])
except Exception:
print(r.text)
Get_All_Score()
#Get_NearestDt()