Skip to content

Instantly share code, notes, and snippets.

@suhaotian
Last active June 14, 2017 09:34
Show Gist options
  • Save suhaotian/f531588b1568f652bc2276422c6afcf0 to your computer and use it in GitHub Desktop.
Save suhaotian/f531588b1568f652bc2276422c6afcf0 to your computer and use it in GitHub Desktop.
const fetch = require('node-fetch')
const url = '' // url
let result = []
fetch(url+1).then(res => res.json()).then(res => {
const total = res.cardlistInfo.total
const arr = []
result = result.concat(res.cards)
const pages = Math.ceil(total/10)
let i = 2
while (i<=pages) {
arr.push(i)
i++
}
arr.reduce(function(chain, page) {
return chain.then(() => {
return fetch(url+page).then(res => res.json()).then(res => {
result = result.concat(res.cards)
console.log(page)
return result
})
})
}, Promise.resolve())
.then(result => {
console.log(result.length)
}).catch(e => {
console.log(e)
console.log(result.length)
})
})
const fetch = require('node-fetch')
const url = '' // api url
function gen(requests, base) {
const counts = Math.ceil(requests/base)
const result = []
for (let i=0;i < counts;i++) {
let tmp_arr = []
for (let j = i*base;j < (i+1)*base;j++) {
tmp_arr.push(j)
}
result.push(tmp_arr)
}
return result
}
let result = {}
fetch(url+1).then(res => res.json()).then(res => {
const total = res.cardlistInfo.total
const pages = Math.ceil(total/10)
const all_requests = gen(pages, 1000)
all_requests.forEach((block, index) => {
(function(block, index) {
result[index] = []
block.reduce(function(chain, page) {
return chain.then(() => {
return fetch(url+page).then(res => res.json()).then(res => {
result[index] = result[index].concat(res.cards)
console.log(`result-${index} page-${page}`)
return result[index]
})
})
}, Promise.resolve())
.then(res => {
console.log(`result-${index} page-${page} length-${result[index].length}`)
}).catch(e => {
console.error(e)
console.log(`length-${result[index].length}`)
})
})(block, index)
})
})
import React, { Component } from 'react'
import 'antd/dist/antd.css'
import { Form, DatePicker, Button, Tooltip, Switch, Icon, Input} from 'antd';
const FormItem = Form.Item;
const RangePicker = DatePicker.RangePicker;
// import antd from './antd-components';
// const {
// DatePicker,
// } = antd
const formItemLayout = {
labelCol: { span: 4 },
wrapperCol: { span: 8 },
};
const formTailLayout = {
labelCol: { span: 4 },
wrapperCol: { span: 8, offset: 4 },
};
class App extends Component {
render() {
return (
<div className="App">
<div className="topbar">
</div>
<div className="Menu" style={{maxWidth: 640}}>
<FormItem
label="筛选日期"
{...formItemLayout}
>
<RangePicker />
</FormItem>
<FormItem
label='保留原创'
{...formItemLayout}
>
<Switch checkedChildren={'开'} unCheckedChildren={'关'} />
<Tooltip title="仅删除转载,保留原创">
<Icon type="question-circle-o" style={{marginLeft: 10}}/>
</Tooltip>
</FormItem>
<FormItem {...formTailLayout}>
<Button type="primary">
开始筛选
</Button>
</FormItem>
</div>
<div className="Del" style={{maxWidth: 640}}>
<FormItem {...formTailLayout}>
<Button type="danger">删除</Button>
</FormItem>
</div>
<div className="list">
</div>
</div>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment