tushare 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +59 -0
- data/LICENSE.txt +28 -0
- data/README.md +41 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/tushare.rb +18 -0
- data/lib/tushare/datayes.rb +50 -0
- data/lib/tushare/datayes/bond.rb +69 -0
- data/lib/tushare/datayes/constants.rb +598 -0
- data/lib/tushare/datayes/equity.rb +111 -0
- data/lib/tushare/datayes/fund.rb +115 -0
- data/lib/tushare/datayes/fundamental.rb +260 -0
- data/lib/tushare/datayes/future.rb +22 -0
- data/lib/tushare/datayes/hk_equity.rb +18 -0
- data/lib/tushare/datayes/idx.rb +19 -0
- data/lib/tushare/datayes/iv.rb +60 -0
- data/lib/tushare/datayes/macro.rb +3517 -0
- data/lib/tushare/datayes/market.rb +286 -0
- data/lib/tushare/datayes/master.rb +67 -0
- data/lib/tushare/datayes/options.rb +22 -0
- data/lib/tushare/datayes/subject.rb +349 -0
- data/lib/tushare/internet/box_office.rb +155 -0
- data/lib/tushare/stock/billboard.rb +197 -0
- data/lib/tushare/stock/classifying.rb +288 -0
- data/lib/tushare/stock/fundamental.rb +232 -0
- data/lib/tushare/stock/macro.rb +253 -0
- data/lib/tushare/stock/news_event.rb +165 -0
- data/lib/tushare/stock/reference.rb +473 -0
- data/lib/tushare/stock/shibor.rb +136 -0
- data/lib/tushare/stock/trading.rb +513 -0
- data/lib/tushare/util.rb +293 -0
- data/lib/tushare/version.rb +3 -0
- data/tushare.gemspec +32 -0
- metadata +211 -0
@@ -0,0 +1,232 @@
|
|
1
|
+
require 'tushare/util'
|
2
|
+
|
3
|
+
module Tushare
|
4
|
+
module Stock
|
5
|
+
module Fundamental
|
6
|
+
extend Tushare::Util
|
7
|
+
|
8
|
+
# 获取沪深上市公司基本情况
|
9
|
+
# Return
|
10
|
+
# --------
|
11
|
+
# DataFrame
|
12
|
+
# code,代码
|
13
|
+
# name,名称
|
14
|
+
# industry,细分行业
|
15
|
+
# area,地区
|
16
|
+
# pe,市盈率
|
17
|
+
# outstanding,流通股本
|
18
|
+
# totals,总股本(万)
|
19
|
+
# totalAssets,总资产(万)
|
20
|
+
# liquidAssets,流动资产
|
21
|
+
# fixedAssets,固定资产
|
22
|
+
# reserved,公积金
|
23
|
+
# reservedPerShare,每股公积金
|
24
|
+
# eps,每股收益
|
25
|
+
# bvps,每股净资
|
26
|
+
# pb,市净率
|
27
|
+
# timeToMarket,上市日期
|
28
|
+
def get_stock_basics
|
29
|
+
url = ALL_STOCK_BASICS_FILE
|
30
|
+
response = HTTParty.get(url)
|
31
|
+
if response.code.to_s == '200'
|
32
|
+
table_value = response.body.encode('utf-8', 'gbk')
|
33
|
+
table = CSV.new(table_value)
|
34
|
+
headers = table.shift
|
35
|
+
result = []
|
36
|
+
table.each do |row|
|
37
|
+
object = {}
|
38
|
+
row.each_with_index do |cell, index|
|
39
|
+
object[headers[index]] = cell
|
40
|
+
end
|
41
|
+
result << object
|
42
|
+
end
|
43
|
+
result
|
44
|
+
else
|
45
|
+
[]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# 获取业绩报表数据
|
50
|
+
# Parameters
|
51
|
+
# --------
|
52
|
+
# year:int 年度 e.g:2014
|
53
|
+
# quarter:int 季度 :1、2、3、4,只能输入这4个季度
|
54
|
+
# 说明:由于是从网站获取的数据,需要一页页抓取,速度取决于您当前网络速度
|
55
|
+
#
|
56
|
+
# Return
|
57
|
+
# --------
|
58
|
+
# DataFrame
|
59
|
+
# code,代码
|
60
|
+
# name,名称
|
61
|
+
# eps,每股收益
|
62
|
+
# eps_yoy,每股收益同比(%)
|
63
|
+
# bvps,每股净资产
|
64
|
+
# roe,净资产收益率(%)
|
65
|
+
# epcf,每股现金流量(元)
|
66
|
+
# net_profits,净利润(万元)
|
67
|
+
# profits_yoy,净利润同比(%)
|
68
|
+
# distrib,分配方案
|
69
|
+
# report_date,发布日期
|
70
|
+
def get_report_data(year, quarter)
|
71
|
+
check_year(year)
|
72
|
+
check_quarter(quarter)
|
73
|
+
get_data(year, quarter, 1, REPORT_COLS, REPORT_URL)
|
74
|
+
end
|
75
|
+
|
76
|
+
# 获取盈利能力数据
|
77
|
+
# Parameters
|
78
|
+
# --------
|
79
|
+
# year:int 年度 e.g:2014
|
80
|
+
# quarter:int 季度 :1、2、3、4,只能输入这4个季度
|
81
|
+
# 说明:由于是从网站获取的数据,需要一页页抓取,速度取决于您当前网络速度
|
82
|
+
|
83
|
+
# Return
|
84
|
+
# --------
|
85
|
+
# DataFrame
|
86
|
+
# code,代码
|
87
|
+
# name,名称
|
88
|
+
# roe,净资产收益率(%)
|
89
|
+
# net_profit_ratio,净利率(%)
|
90
|
+
# gross_profit_rate,毛利率(%)
|
91
|
+
# net_profits,净利润(万元)
|
92
|
+
# eps,每股收益
|
93
|
+
# business_income,营业收入(百万元)
|
94
|
+
# bips,每股主营业务收入(元)
|
95
|
+
def get_profit_data(year, quarter)
|
96
|
+
check_year(year)
|
97
|
+
check_quarter(quarter)
|
98
|
+
get_data(year, quarter, 1, PROFIT_COLS, PROFIT_URL)
|
99
|
+
end
|
100
|
+
|
101
|
+
# 获取营运能力数据
|
102
|
+
# Parameters
|
103
|
+
# --------
|
104
|
+
# year:int 年度 e.g:2014
|
105
|
+
# quarter:int 季度 :1、2、3、4,只能输入这4个季度
|
106
|
+
# 说明:由于是从网站获取的数据,需要一页页抓取,速度取决于您当前网络速度
|
107
|
+
|
108
|
+
# Return
|
109
|
+
# --------
|
110
|
+
# DataFrame
|
111
|
+
# code,代码
|
112
|
+
# name,名称
|
113
|
+
# arturnover,应收账款周转率(次)
|
114
|
+
# arturndays,应收账款周转天数(天)
|
115
|
+
# inventory_turnover,存货周转率(次)
|
116
|
+
# inventory_days,存货周转天数(天)
|
117
|
+
# currentasset_turnover,流动资产周转率(次)
|
118
|
+
# currentasset_days,流动资产周转天数(天)
|
119
|
+
def get_operation_data(year, quarter)
|
120
|
+
check_year(year)
|
121
|
+
check_quarter(quarter)
|
122
|
+
get_data(year, quarter, 1, OPERATION_COLS, OPERATION_URL)
|
123
|
+
end
|
124
|
+
|
125
|
+
# 获取成长能力数据
|
126
|
+
# Parameters
|
127
|
+
# --------
|
128
|
+
# year:int 年度 e.g:2014
|
129
|
+
# quarter:int 季度 :1、2、3、4,只能输入这4个季度
|
130
|
+
# 说明:由于是从网站获取的数据,需要一页页抓取,速度取决于您当前网络速度
|
131
|
+
|
132
|
+
# Return
|
133
|
+
# --------
|
134
|
+
# DataFrame
|
135
|
+
# code,代码
|
136
|
+
# name,名称
|
137
|
+
# mbrg,主营业务收入增长率(%)
|
138
|
+
# nprg,净利润增长率(%)
|
139
|
+
# nav,净资产增长率
|
140
|
+
# targ,总资产增长率
|
141
|
+
# epsg,每股收益增长率
|
142
|
+
# seg,股东权益增长率
|
143
|
+
def get_growth_data(year, quarter)
|
144
|
+
check_year(year)
|
145
|
+
check_quarter(quarter)
|
146
|
+
get_data(year, quarter, 1, GROWTH_COLS, GROWTH_URL)
|
147
|
+
end
|
148
|
+
|
149
|
+
# 获取偿债能力数据
|
150
|
+
# Parameters
|
151
|
+
# --------
|
152
|
+
# year:int 年度 e.g:2014
|
153
|
+
# quarter:int 季度 :1、2、3、4,只能输入这4个季度
|
154
|
+
# 说明:由于是从网站获取的数据,需要一页页抓取,速度取决于您当前网络速度
|
155
|
+
|
156
|
+
# Return
|
157
|
+
# --------
|
158
|
+
# DataFrame
|
159
|
+
# code,代码
|
160
|
+
# name,名称
|
161
|
+
# currentratio,流动比率
|
162
|
+
# quickratio,速动比率
|
163
|
+
# cashratio,现金比率
|
164
|
+
# icratio,利息支付倍数
|
165
|
+
# sheqratio,股东权益比率
|
166
|
+
# adratio,股东权益增长率
|
167
|
+
def get_debtpaying_data(year, quarter)
|
168
|
+
check_year(year)
|
169
|
+
check_quarter(quarter)
|
170
|
+
get_data(year, quarter, 1, DEBTPAYING_COLS, DEBTPAYING_URL)
|
171
|
+
end
|
172
|
+
|
173
|
+
# 获取现金流量数据
|
174
|
+
# Parameters
|
175
|
+
# --------
|
176
|
+
# year:int 年度 e.g:2014
|
177
|
+
# quarter:int 季度 :1、2、3、4,只能输入这4个季度
|
178
|
+
# 说明:由于是从网站获取的数据,需要一页页抓取,速度取决于您当前网络速度
|
179
|
+
|
180
|
+
# Return
|
181
|
+
# --------
|
182
|
+
# DataFrame
|
183
|
+
# code,代码
|
184
|
+
# name,名称
|
185
|
+
# cf_sales,经营现金净流量对销售收入比率
|
186
|
+
# rateofreturn,资产的经营现金流量回报率
|
187
|
+
# cf_nm,经营现金净流量与净利润的比率
|
188
|
+
# cf_liabilities,经营现金净流量对负债比率
|
189
|
+
# cashflowratio,现金流量比率
|
190
|
+
def get_cashflow_data(year, quarter)
|
191
|
+
check_year(year)
|
192
|
+
check_quarter(quarter)
|
193
|
+
get_data(year, quarter, 1, CASHFLOW_COLS, CASHFLOW_URL)
|
194
|
+
end
|
195
|
+
|
196
|
+
protected
|
197
|
+
|
198
|
+
def get_data(year, quarter, page, headers, url_format)
|
199
|
+
_write_head
|
200
|
+
_write_console
|
201
|
+
result = []
|
202
|
+
result.concat process_data(page, headers, lambda do |p|
|
203
|
+
format(url_format, P_TYPE['http'], DOMAINS['vsf'], PAGES['fd'],
|
204
|
+
year, quarter, p, PAGE_NUM[1])
|
205
|
+
end)
|
206
|
+
end
|
207
|
+
|
208
|
+
def process_data(page, headers, url_generator)
|
209
|
+
result = []
|
210
|
+
loop do
|
211
|
+
url = url_generator.call(page)
|
212
|
+
doc = Nokogiri::HTML(open(url), nil, 'gbk')
|
213
|
+
doc.css('table.list_table > tr').each do |tr|
|
214
|
+
item = {}
|
215
|
+
tr.css('td').each_with_index do |td, index|
|
216
|
+
item[headers[index]] = td.content if headers[index]
|
217
|
+
end
|
218
|
+
result << item
|
219
|
+
end
|
220
|
+
next_page = doc.css('div.pages > a:last').css('a.nolink')
|
221
|
+
break unless next_page.empty?
|
222
|
+
page += 1
|
223
|
+
end
|
224
|
+
result
|
225
|
+
end
|
226
|
+
|
227
|
+
module_function :get_stock_basics, :get_report_data, :get_profit_data,
|
228
|
+
:get_operation_data, :get_growth_data, :get_data,
|
229
|
+
:get_debtpaying_data, :get_cashflow_data, :process_data
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
@@ -0,0 +1,253 @@
|
|
1
|
+
require 'tushare/util'
|
2
|
+
|
3
|
+
module Tushare
|
4
|
+
module Stock
|
5
|
+
# 宏观经济数据接口
|
6
|
+
module Macro
|
7
|
+
extend Tushare::Util
|
8
|
+
|
9
|
+
# 获取年度国内生产总值数据
|
10
|
+
# Return
|
11
|
+
# --------
|
12
|
+
# DataFrame
|
13
|
+
# year :统计年度
|
14
|
+
# gdp :国内生产总值(亿元)
|
15
|
+
# pc_gdp :人均国内生产总值(元)
|
16
|
+
# gnp :国民生产总值(亿元)
|
17
|
+
# pi :第一产业(亿元)
|
18
|
+
# si :第二产业(亿元)
|
19
|
+
# industry :工业(亿元)
|
20
|
+
# cons_industry :建筑业(亿元)
|
21
|
+
# ti :第三产业(亿元)
|
22
|
+
# trans_industry :交通运输仓储邮电通信业(亿元)
|
23
|
+
# lbdy :批发零售贸易及餐饮业(亿元)
|
24
|
+
def gdp_year
|
25
|
+
random_int = rand(100)
|
26
|
+
url = format(MACRO_URL, P_TYPE['http'], DOMAINS['sina'], random_int,
|
27
|
+
MACRO_TYPE[0], 0, 70, random_int)
|
28
|
+
fetch_data(url, GDP_YEAR_COLS)
|
29
|
+
end
|
30
|
+
|
31
|
+
# 获取季度国内生产总值数据
|
32
|
+
# Return
|
33
|
+
# --------
|
34
|
+
# DataFrame
|
35
|
+
# quarter :季度
|
36
|
+
# gdp :国内生产总值(亿元)
|
37
|
+
# gdp_yoy :国内生产总值同比增长(%)
|
38
|
+
# pi :第一产业增加值(亿元)
|
39
|
+
# pi_yoy:第一产业增加值同比增长(%)
|
40
|
+
# si :第二产业增加值(亿元)
|
41
|
+
# si_yoy :第二产业增加值同比增长(%)
|
42
|
+
# ti :第三产业增加值(亿元)
|
43
|
+
# ti_yoy :第三产业增加值同比增长(%)
|
44
|
+
def gdp_quarter
|
45
|
+
random_int = rand(100)
|
46
|
+
url = format(MACRO_URL, P_TYPE['http'], DOMAINS['sina'], random_int,
|
47
|
+
MACRO_TYPE[0], 1, 250, random_int)
|
48
|
+
fetch_data(url, GDP_QUARTER_COLS)
|
49
|
+
end
|
50
|
+
|
51
|
+
# 获取三大需求对GDP贡献数据
|
52
|
+
# Return
|
53
|
+
# --------
|
54
|
+
# DataFrame
|
55
|
+
# year :统计年度
|
56
|
+
# end_for :最终消费支出贡献率(%)
|
57
|
+
# for_rate :最终消费支出拉动(百分点)
|
58
|
+
# asset_for :资本形成总额贡献率(%)
|
59
|
+
# asset_rate:资本形成总额拉动(百分点)
|
60
|
+
# goods_for :货物和服务净出口贡献率(%)
|
61
|
+
# goods_rate :货物和服务净出口拉动(百分点)
|
62
|
+
def gdp_for
|
63
|
+
random_int = rand(100)
|
64
|
+
url = format(MACRO_URL, P_TYPE['http'], DOMAINS['sina'], random_int,
|
65
|
+
MACRO_TYPE[0], 4, 80, random_int)
|
66
|
+
fetch_data(url, GDP_FOR_COLS)
|
67
|
+
end
|
68
|
+
|
69
|
+
# 获取三大产业对GDP拉动数据
|
70
|
+
# Return
|
71
|
+
# --------
|
72
|
+
# DataFrame
|
73
|
+
# year :统计年度
|
74
|
+
# gdp_yoy :国内生产总值同比增长(%)
|
75
|
+
# pi :第一产业拉动率(%)
|
76
|
+
# si :第二产业拉动率(%)
|
77
|
+
# industry:其中工业拉动(%)
|
78
|
+
# ti :第三产业拉动率(%)
|
79
|
+
def gdp_pull
|
80
|
+
random_int = rand(100)
|
81
|
+
url = format(MACRO_URL, P_TYPE['http'], DOMAINS['sina'], random_int,
|
82
|
+
MACRO_TYPE[0], 5, 60, random_int)
|
83
|
+
fetch_data(url, GDP_PULL_COLS)
|
84
|
+
end
|
85
|
+
|
86
|
+
# 获取三大产业贡献率数据
|
87
|
+
# Return
|
88
|
+
# --------
|
89
|
+
# DataFrame
|
90
|
+
# year :统计年度
|
91
|
+
# gdp_yoy :国内生产总值
|
92
|
+
# pi :第一产业献率(%)
|
93
|
+
# si :第二产业献率(%)
|
94
|
+
# industry:其中工业献率(%)
|
95
|
+
# ti :第三产业献率(%)
|
96
|
+
def gdp_contrib
|
97
|
+
random_int = rand(100)
|
98
|
+
url = format(MACRO_URL, P_TYPE['http'], DOMAINS['sina'], random_int,
|
99
|
+
MACRO_TYPE[0], 6, 60, random_int)
|
100
|
+
fetch_data(url, GDP_CONTRIB_COLS)
|
101
|
+
end
|
102
|
+
|
103
|
+
# 获取居民消费价格指数数据
|
104
|
+
# Return
|
105
|
+
# --------
|
106
|
+
# DataFrame
|
107
|
+
# month :统计月份
|
108
|
+
# cpi :价格指数
|
109
|
+
def cpi
|
110
|
+
random_int = rand(100)
|
111
|
+
url = format(MACRO_URL, P_TYPE['http'], DOMAINS['sina'], random_int,
|
112
|
+
MACRO_TYPE[1], 0, 600, random_int)
|
113
|
+
fetch_data(url, CPI_COLS)
|
114
|
+
end
|
115
|
+
|
116
|
+
# 获取工业品出厂价格指数数据
|
117
|
+
# Return
|
118
|
+
# --------
|
119
|
+
# DataFrame
|
120
|
+
# month :统计月份
|
121
|
+
# ppiip :工业品出厂价格指数
|
122
|
+
# ppi :生产资料价格指数
|
123
|
+
# qm:采掘工业价格指数
|
124
|
+
# rmi:原材料工业价格指数
|
125
|
+
# pi:加工工业价格指数
|
126
|
+
# cg:生活资料价格指数
|
127
|
+
# food:食品类价格指数
|
128
|
+
# clothing:衣着类价格指数
|
129
|
+
# roeu:一般日用品价格指数
|
130
|
+
# dcg:耐用消费品价格指数
|
131
|
+
def ppi
|
132
|
+
random_int = rand(100)
|
133
|
+
url = format(MACRO_URL, P_TYPE['http'], DOMAINS['sina'], random_int,
|
134
|
+
MACRO_TYPE[1], 3, 600, random_int)
|
135
|
+
fetch_data(url, PPI_COLS)
|
136
|
+
end
|
137
|
+
|
138
|
+
# 获取存款利率数据
|
139
|
+
# Return
|
140
|
+
# --------
|
141
|
+
# DataFrame
|
142
|
+
# date :变动日期
|
143
|
+
# deposit_type :存款种类
|
144
|
+
# rate:利率(%)
|
145
|
+
def deposit_rate
|
146
|
+
random_int = rand(100)
|
147
|
+
url = format(MACRO_URL, P_TYPE['http'], DOMAINS['sina'], random_int,
|
148
|
+
MACRO_TYPE[2], 2, 600, random_int)
|
149
|
+
fetch_data(url, DEPOSIT_COLS)
|
150
|
+
end
|
151
|
+
|
152
|
+
# 获取贷款利率数据
|
153
|
+
# Return
|
154
|
+
# --------
|
155
|
+
# DataFrame
|
156
|
+
# date :执行日期
|
157
|
+
# loan_type :存款种类
|
158
|
+
# rate:利率(%)
|
159
|
+
def loan_rate
|
160
|
+
random_int = rand(100)
|
161
|
+
url = format(MACRO_URL, P_TYPE['http'], DOMAINS['sina'], random_int,
|
162
|
+
MACRO_TYPE[2], 3, 800, random_int)
|
163
|
+
fetch_data(url, LOAN_COLS)
|
164
|
+
end
|
165
|
+
|
166
|
+
# 获取存款准备金率数据
|
167
|
+
# Return
|
168
|
+
# --------
|
169
|
+
# DataFrame
|
170
|
+
# date :变动日期
|
171
|
+
# before :调整前存款准备金率(%)
|
172
|
+
# now:调整后存款准备金率(%)
|
173
|
+
# changed:调整幅度(%)
|
174
|
+
def rrr
|
175
|
+
random_int = rand(100)
|
176
|
+
url = format(MACRO_URL, P_TYPE['http'], DOMAINS['sina'], random_int,
|
177
|
+
MACRO_TYPE[2], 4, 100, random_int)
|
178
|
+
fetch_data(url, RRR_COLS)
|
179
|
+
end
|
180
|
+
|
181
|
+
# 获取货币供应量数据
|
182
|
+
# Return
|
183
|
+
# --------
|
184
|
+
# DataFrame
|
185
|
+
# month :统计时间
|
186
|
+
# m2 :货币和准货币(广义货币M2)(亿元)
|
187
|
+
# m2_yoy:货币和准货币(广义货币M2)同比增长(%)
|
188
|
+
# m1:货币(狭义货币M1)(亿元)
|
189
|
+
# m1_yoy:货币(狭义货币M1)同比增长(%)
|
190
|
+
# m0:流通中现金(M0)(亿元)
|
191
|
+
# m0_yoy:流通中现金(M0)同比增长(%)
|
192
|
+
# cd:活期存款(亿元)
|
193
|
+
# cd_yoy:活期存款同比增长(%)
|
194
|
+
# qm:准货币(亿元)
|
195
|
+
# qm_yoy:准货币同比增长(%)
|
196
|
+
# ftd:定期存款(亿元)
|
197
|
+
# ftd_yoy:定期存款同比增长(%)
|
198
|
+
# sd:储蓄存款(亿元)
|
199
|
+
# sd_yoy:储蓄存款同比增长(%)
|
200
|
+
# rests:其他存款(亿元)
|
201
|
+
# rests_yoy:其他存款同比增长(%)
|
202
|
+
def money_supply
|
203
|
+
random_int = rand(100)
|
204
|
+
url = format(MACRO_URL, P_TYPE['http'], DOMAINS['sina'], random_int,
|
205
|
+
MACRO_TYPE[2], 1, 600, random_int)
|
206
|
+
fetch_data(url, MONEY_SUPPLY_COLS)
|
207
|
+
end
|
208
|
+
|
209
|
+
|
210
|
+
# 获取货币供应量(年底余额)数据
|
211
|
+
# Return
|
212
|
+
# --------
|
213
|
+
# DataFrame
|
214
|
+
# year :统计年度
|
215
|
+
# m2 :货币和准货币(亿元)
|
216
|
+
# m1:货币(亿元)
|
217
|
+
# m0:流通中现金(亿元)
|
218
|
+
# cd:活期存款(亿元)
|
219
|
+
# qm:准货币(亿元)
|
220
|
+
# ftd:定期存款(亿元)
|
221
|
+
# sd:储蓄存款(亿元)
|
222
|
+
# rests:其他存款(亿元)
|
223
|
+
def money_supply_bal
|
224
|
+
random_int = rand(100)
|
225
|
+
url = format(MACRO_URL, P_TYPE['http'], DOMAINS['sina'], random_int,
|
226
|
+
MACRO_TYPE[2], 0, 200, random_int)
|
227
|
+
fetch_data(url, MONEY_SUPPLY_BLA_COLS)
|
228
|
+
end
|
229
|
+
|
230
|
+
private
|
231
|
+
|
232
|
+
def fetch_data(url, cols)
|
233
|
+
resp = HTTParty.get(url)
|
234
|
+
str = resp.body.encode('utf-8', 'gbk')
|
235
|
+
index = str.index 'count:'
|
236
|
+
arr = JSON.parse str[index..-1].split('data:').last[0..-4]
|
237
|
+
result = []
|
238
|
+
arr.each do |row|
|
239
|
+
object = {}
|
240
|
+
cols.each_with_index do |key, i|
|
241
|
+
object[key] = row[i]
|
242
|
+
end
|
243
|
+
result << object
|
244
|
+
end
|
245
|
+
result
|
246
|
+
end
|
247
|
+
|
248
|
+
module_function :gdp_year, :gdp_quarter, :gdp_for, :gdp_pull,
|
249
|
+
:gdp_contrib, :cpi, :ppi, :deposit_rate, :loan_rate,
|
250
|
+
:rrr, :money_supply, :money_supply_bal, :fetch_data
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|