Skip to content

Instantly share code, notes, and snippets.

@mygoare
Created May 3, 2020 03:51
Show Gist options
  • Save mygoare/0b5b2e56f3bbcd7b61e146a10216d5aa to your computer and use it in GitHub Desktop.
Save mygoare/0b5b2e56f3bbcd7b61e146a10216d5aa to your computer and use it in GitHub Desktop.
v2ex sign everyday
const request = require('request');
const rp = require('request-promise');
const j = rp.jar();
const cookie = rp.cookie(`
YOUR_V2EX_COOKIE
`.trim());
const url = "https://v2ex.com";
j.setCookie(cookie, url);
const r = rp.defaults({
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.57 Safari/537.36 OPR/40.0.2308.15 (Edition beta)',
'Referer': 'https://www.v2ex.com/signin',
'Origin': 'https://www.v2ex.com',
'Cookie': cookie,
},
});
const dailyUrl = 'https://www.v2ex.com/mission/daily';
async function t() {
return r({
url: dailyUrl,
}).then(body => {
// console.log(body);
if (/每日登录奖励已领取/.test(body)) {
console.log('You haved signed');
} else {
let matched = /mission\/daily\/redeem\?once=\d+/.exec(body);
let u = 'https://www.v2ex.com/' + matched[0];
// console.log(u);
return r({url: u})
.then(body=> {
console.log(body, 'Success');
})
}
});
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function access() {
// for(let i = 0; i < 50; i++) {
// console.log(i);
console.log('a');
await t();
console.log('b');
// await sleep(Math.random() * 4000);
// }
}
access();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment