feat: add pigprice (#3314)

This commit is contained in:
Jiaju Chen
2019-10-25 17:25:50 +08:00
committed by DIYgod
parent 18b7c0c58c
commit 849058b119
3 changed files with 57 additions and 0 deletions
+6
View File
@@ -231,6 +231,12 @@ type 为 all 时,category 参数不支持 cost 和 free
<Route author="junfengP" example="/mlhang" path="/mlhang" />
## 每日生猪价格
### 每日生猪价格更新
<Route author="importcjj" example="/pork-price" path="/pork-price" />
## 米坛社区
### 表盘更新
+3
View File
@@ -1888,4 +1888,7 @@ router.get('/hk01/hot', require('./routes/hk01/hot'));
// 码农周刊
router.get('/manong-weekly', require('./routes/manong-weekly/issues'));
// 每日猪价
router.get('/pork-price', require('./routes/pork-price'));
module.exports = router;
+48
View File
@@ -0,0 +1,48 @@
const got = require('@/utils/got');
const base_url = 'https://zhujia.zhuwang.cc/';
module.exports = async (ctx) => {
const now = new Date();
const date = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}`;
const response = await got({
method: 'get',
url: `https://zhujia.zhuwang.cc/index/api/chartData?areaId=-1`,
headers: {
Referer: base_url,
},
});
const names = {
pigprice: '生猪(外三元)',
pig_local: '生猪(土杂猪)',
pig_in: '生猪(内三元)',
};
const priceItems = [];
for (const key of Object.keys(names)) {
const items = response.data[key];
const today = items[items.length - 1];
const yesterday = items[items.length - 2];
const change = (today - yesterday).toFixed(2);
let description = `较昨日价格, 每公斤上涨${change}元`;
if (yesterday > today) {
description = `较昨日价格, 下跌${change}元`;
}
if (yesterday === today) {
description = '较昨日价格持平';
}
priceItems.push({
title: `${date} ${names[key]} ${today}元/公斤. ${description}`,
description,
link: base_url,
});
}
ctx.state.data = {
title: `全国今日生猪价格`,
desription: '中国养猪网猪价频道是中国猪价权威平台,提供每日猪评,猪价和行情分析,并且预测猪价和分析每天的猪价排行。',
link: base_url,
item: priceItems,
};
};