modify scripts
This commit is contained in:
BIN
tushare/mod/00698.xlsx
Normal file
BIN
tushare/mod/00698.xlsx
Normal file
Binary file not shown.
52
tushare/mod/HKStock.py
Normal file
52
tushare/mod/HKStock.py
Normal file
@ -0,0 +1,52 @@
|
||||
#!/usr/bin/py
|
||||
|
||||
import json
|
||||
from requests import get
|
||||
from pandas import DataFrame
|
||||
|
||||
def balance_data(code,years):
|
||||
#query = 'http://HKf10.eastmoney.com/F9HKStock/GetFinanceAssetData.do?securityCode={}.HK&comType=127000000606281483&yearList={}&reportTypeList=1,5,3,6&dateSearchType=1&listedType=0,1&reportTypeInScope=1&reportType=0&rotate=0&seperate=0&order=desc&cashType=1&exchangeValue=1&customSelect=0&CurrencySelect=0'.format(code,years)
|
||||
query = 'http://emweb.securities.eastmoney.com/PC_HKF10/NewFinancialAnalysis/GetZCFZB?code={}&startdate={}&ctype=4&rtype=0'.format(code,years)
|
||||
ct = get(query).text.replace('\\u0026nbsp','')
|
||||
ct = ct.replace('\\u003cb\\u003e','').replace('\\u003c/b\\u003e','')
|
||||
d = json.loads(ct)['data']
|
||||
df = DataFrame(d)
|
||||
print(df)
|
||||
hdr = df.iloc[0,:].values
|
||||
hdr[0] = "名目"
|
||||
df.columns = hdr
|
||||
df = df.iloc[1:,:]
|
||||
df.index = df.iloc[:,0]
|
||||
df = df.iloc[:,1:]
|
||||
df = df.sort_values('截止日期',axis=1,ascending=False)
|
||||
return df
|
||||
|
||||
def income_data(code,years):
|
||||
query = 'http://hkf10.eastmoney.com/F9HKStock/GetFinanceProfitData.do?securityCode={c}.HK&comType=127000000606281483&yearList={ny}&reportTypeList=1,5,3,6&dateSearchType=1&listedType=0,1&reportTypeInScope=1&reportType=0&rotate=0&seperate=0&order=desc&cashType=1&exchangeValue=1&customSelect=0&CurrencySelect=0'.format(c=code,ny=years)
|
||||
ct = get(query).text.replace('\\u0026nbsp','')
|
||||
ct = ct.replace('\\u003cb\\u003e','').replace('\\u003c/b\\u003e','')
|
||||
d = json.loads(ct)['resultList']
|
||||
df = DataFrame(d)
|
||||
hdr = df.iloc[0,:].values
|
||||
hdr[0] = "名目"
|
||||
df.columns = hdr
|
||||
df = df.iloc[1:,:]
|
||||
df.index = df.iloc[:,0]
|
||||
df = df.iloc[:,1:]
|
||||
df = df.sort_values('截止日期',axis=1,ascending=False)
|
||||
return df
|
||||
|
||||
def cash_data(code,years):
|
||||
query = 'http://hkf10.eastmoney.com/F9HKStock/GetFinanceCashflowData.do?securityCode={c}.HK&comType=127000000606281483&yearList={ny}&reportTypeList=1,5,3,6&dateSearchType=1&listedType=0,1&reportTypeInScope=1&reportType=0&rotate=0&seperate=0&order=desc&cashType=1&exchangeValue=1&customSelect=0&CurrencySelect=0'.format(c=code,ny=years)
|
||||
ct = get(query).text.replace('\\u0026nbsp','')
|
||||
ct = ct.replace('\\u003cb\\u003e','').replace('\\u003c/b\\u003e','')
|
||||
d = json.loads(ct)['resultList']
|
||||
df = DataFrame(d)
|
||||
hdr = df.iloc[0,:].values
|
||||
hdr[0] = "名目"
|
||||
df.columns = hdr
|
||||
df = df.iloc[1:,:]
|
||||
df.index = df.iloc[:,0]
|
||||
df = df.iloc[:,1:]
|
||||
df = df.sort_values('截止日期',axis=1,ascending=False)
|
||||
return df
|
||||
BIN
tushare/mod/Template.xlsx
Normal file
BIN
tushare/mod/Template.xlsx
Normal file
Binary file not shown.
21
tushare/mod/main.py
Normal file
21
tushare/mod/main.py
Normal file
@ -0,0 +1,21 @@
|
||||
from HKStock import *
|
||||
import xlwings as xw
|
||||
|
||||
code = input("请输入港股代码(不可省略前0):")
|
||||
years = input("请输入下载年份,以英文逗号分隔:")
|
||||
|
||||
t = r'Template.xlsx'
|
||||
b = balance_data(code,years)
|
||||
p = income_data(code,years)
|
||||
c = cash_data(code,years)
|
||||
|
||||
bk = xw.Book(t)
|
||||
bk.sheets['balance_data'].clear_contents()
|
||||
xw.view(b,bk.sheets['balance_data'])
|
||||
#bk.sheets['cash_data'].clear_contents()
|
||||
#xw.view(c,bk.sheets['cash_data'])
|
||||
#bk.sheets['income_data'].clear_contents()
|
||||
#xw.view(p,bk.sheets['income_data'])
|
||||
|
||||
bk.save(str(code)+'.xlsx')
|
||||
xw.apps[0].quit()
|
||||
Reference in New Issue
Block a user