2 Star 1 Fork 27

kevin/jd_scripts

forked from XanderYe/jd_scripts 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
jd_jxgc_stock.ts 2.39 KB
一键复制 编辑 原始数据 按行查看 历史
kevin 提交于 2021-11-30 10:17 . edit
/**
* 京喜工厂:肯德基、沃尔玛
* cron: 0 * * * *
*/
import axios from "axios";
import {requireConfig, requestAlgo, o2s, wait} from "./TS_USER_AGENTS";
import {sendNotify} from './sendNotify'
let cookie: string = '', res: any = '', message: string = '';
!(async () => {
await requestAlgo(10001)
let cookiesArr: any = await requireConfig();
cookie = cookiesArr[Math.floor(Math.random() * cookiesArr.length)];
/*
let exist: string[] = [];
if (existsSync('json/jxgc_stock.json')) {
exist = JSON.parse(readFileSync('./json/jxgc_stock.json').toString() || '[]')
}
res = await api();
let current: string[] = []
for (let t of res.data.commodityList) {
console.log(t.name)
current.push(t.name)
if (!exist.includes(t.name)) {
message += t.name + '\n'
}
}
writeFileSync('./json/jxgc_stock.json', JSON.stringify(current))
if (message) {
console.log('send...')
sendNotify('京喜工厂可生产', message)
}
*/
res = await api();
await wait(1000)
let keywords: string[] = ['KFC', 'kfc', '肯德基', '沃尔玛']
for (let t of res.data.commodityList) {
let name: string = t.name, commodityId: number = t.commodityId
res = await api(commodityId)
await wait(1000)
let desp: string = res.data.commodityList[0].description
if (desp.indexOf('红包') > -1) {
desp = desp.match(/奖励以(.*)发放/)![1]
message += `${name} ${desp}\n`
} else if (desp.indexOf('支付') > -1) {
desp = desp.match(/完成需(.*元)/)![1]
} else {
o2s(res)
}
console.log(name, desp)
for (let keyword of keywords) {
if (name.indexOf(keyword) > -1) {
await sendNotify("京喜工厂", name)
break
}
}
}
if (message) {
sendNotify('京喜工厂送红包', message)
}
})()
async function api(commodityId?: number) {
let t = Date.now()
let url: string = commodityId
? `https://m.jingxi.com/dreamfactory/diminfo/GetCommodityDetails?zone=dream_factory&commodityId=${commodityId}&_time=${t}&_ts=${t}&_=${t}&sceneval=2`
: `https://m.jingxi.com/dreamfactory/diminfo/GetCommodityList?zone=dream_factory&flag=2&pageNo=1&pageSize=12&_time=${t}&_ts=${t}&_=${t}&sceneval=2`
let {data}: any = await axios.get(url, {
headers: {
'Host': 'm.jingxi.com',
'User-Agent': 'jdpingou;',
'Referer': 'https://st.jingxi.com/',
'Cookie': cookie
}
})
return data
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/kevin0217/jd_scripts.git
git@gitee.com:kevin0217/jd_scripts.git
kevin0217
jd_scripts
jd_scripts
master

搜索帮助