Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sleepRandom = () => new Promise(r => setTimeout(r, Math.random() * 3000));
- function starURLs(name, page, myName) {
- function formatDate(d) {
- return d.getFullYear() + ('00' + (d.getMonth() + 1)).slice(-2) + ('00' + d.getDate()).slice(-2);
- }
- return fetch(`http://b.hatena.ne.jp/api/users/${name}/bookmarks?page=${page}`)
- .then(r => r.json())
- .then(
- a => a.item
- .bookmarks
- .map(i => `http://b.hatena.ne.jp/${i.user.name}/${formatDate(new Date(i.created))}#bookmark-${i.location_id}`)
- .map(url => `uri=${encodeURIComponent(url)}`).join('&')
- )
- .then(q => fetch(`http://s.hatena.ne.jp/entries.json?${q}`))
- .then(r => r.json())
- .then(
- v => v.entries.filter(e => e.stars
- .some(s => s.name == myName))
- .map(e => e.uri)
- )
- }
- function listStarURLs(name, maxPage) {
- fetch('http://b.hatena.ne.jp/api/my/profile')
- .then(r => r.json())
- .then(
- r => [...new Array(maxPage).keys()].reduce(
- (acc, x) => acc.then(l => {
- console.log("Now " + l);
- return sleepRandom().then(() => starURLs(name, x + 1, r.name))
- .then(m => l.concat(m))
- }),
- Promise.resolve([])
- )
- )
- .then(JSON.stringify)
- .then(console.log)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement