API
- 介绍
Agrisk-tools数据库的API应用
-
我们提供API应用来帮助您无需访问该网站就可以代码的方式调用该数据库中的数据。
API应用的基本格式是 "http://www.agrisk-bigdata.com/product/download?", 以SQL字符串为参数。该url以CSV格式返回数据。
获取数据的一个例子为:
“http://www.agrisk-bigdata.com/product/download?province=1&nameEn=smallpig&ymStart=2000-01&ymEnd=2012-01&type=csv”
各数据库不同类别数据的查询,检查我们的代码对照表如下:
Province codes | to | Chinese | English |
1 | => | 北京 | Beijing |
2 | => | 天津 | Tianjing |
3 | => | 河北 | Hebei |
4 | => | 山西 | Shanxi |
5 | => | 辽宁 | Liaoning |
6 | => | 吉林 | Jiling |
7 | => | 上海 | Shanghai |
8 | => | 江苏 | Jiangsu |
9 | => | 浙江 | Zhejiang |
10 | => | 安徽 | Anhui |
11 | => | 福建 | Fujian |
12 | => | 江西 | Jiangxi |
13 | => | 山东 | Shandong |
14 | => | 河南 | Henan |
15 | => | 内蒙古 | Neimenggu |
16 | => | 黑龙江 | Helongjiang |
17 | => | 湖北 | Hubei |
18 | => | 湖南 | Hunan |
19 | => | 广东 | Guangdong |
20 | => | 广西 | Guangxi |
21 | => | 海南 | Hainan |
22 | => | 四川 | Sichuan |
23 | => | 重庆 | Chongqing |
24 | => | 贵州 | Guizhou |
25 | => | 云南 | Yunnan |
26 | => | 西藏 | Xizang |
27 | => | 陕西 | Shaanxi |
28 | => | 甘肃 | Gansu |
29 | => | 青海 | Qinghai |
30 | => | 宁夏 | Ningxia |
31 | => | 新疆 | xinjiang |
Livestock codes | to | Chinese | English |
smallpig | => | 仔猪 | Piglet |
livepig | => | 生猪 | Hog |
pork | => | 去皮带骨猪肉 | Pork |
beef | => | 去骨牛肉 | Beef |
mutton | => | 带骨羊肉 | Mutton |
smallmeatch | => | 肉用雏鸡 | Meat chicks |
livech | => | 活鸡 | Live chicken |
westch | => | 白条鸡 | Chicken |
smalleggch | => | 蛋用雏鸡 | Egg chicks |
egg | => | 鸡蛋 | Egg |
corn | => | 玉米 | Corn |
bean | => | 豆粕 | Soybean meal |
whear | => | 小麦麸 | Wheat bran |
pigfeed | => | 育肥猪配合饲料 | Compound piglet feed |
meatchfeed | => | 肉鸡配合饲料 | Compound meat chicks feed |
eggchfeed | => | 蛋鸡配合饲料 | Compound egg chicks feed |
wool | => | 绵羊毛 | Sheep wool |
pigfood | => | 猪粮比 | Hog-corn ratio |
fish | => | 鱼粉 | Fish meal |
Type :
csv return to csv format
json return to json format
R 示例代码
1. 关于csv格式,即type = csv,可以这样获取数据:
> url <- "http://www.agrisk-bigdata.com/product/download?province=1&nameEn=smallpig&ymStart=2000-01&ymEnd=2012-01&type=csv"
> read.csv(url, header = FALSE, sep = ",",quote="\"", dec=".", fill = TRUE, comment.char="")
2. 关于json格式,即type = json,可以这样获取数据:
安装软件包 "httr"
安装软件包 "RJSONIO"
> library(httr)
> url <- "http://www.agrisk-bigdata.com/product/download?province=1&nameEn=smallpig&ymStart=2000> 1&ymEnd=2012-01&type=json"
> response <- GET(url)
> content = content(response, "text")
> library(RJSONIO)
> romJSON(content)
Matlab 示例代码
使用Matlab的新webread()函数来查询Agrisk工具。
data = webread("http://www.agrisk-bigdata.com/product/download?province=1&nameEn=smallpig&ymStart=2000-01&ymEnd=2012-01&type=csv")