Skip to content

Commit

Permalink
[#1] - Finished oschina
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyLv committed Dec 18, 2016
1 parent bfd9166 commit 5e0fdc9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
5 changes: 3 additions & 2 deletions scripts/auto_publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ const article = {
content: result.slice(2).join('---')
}

const { jianshu, segmentfault, zhihu, v2ex, juejin } = config.accounts
const { jianshu, segmentfault, zhihu, v2ex, juejin, oschina } = config.accounts

// require('./jianshu')(nightmare, jianshu, article)
// require('./segmentfault')(nightmare, segmentfault, article)
// require('./v2ex')(nightmare, v2ex, article)
require('./juejin')(nightmare, juejin, article)
// require('./juejin')(nightmare, juejin, article)
require('./oschina')(nightmare, oschina, article)

36 changes: 36 additions & 0 deletions scripts/oschina.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const TIMES_TO_DELAY = 2000 // need decrease/increase deps on network.

function publish(nightmare, {username, password}, {meta, content}) {
nightmare
.goto('https://my.oschina.net/JimmyLv/blog')
.exists('.btn-green') // already login?
.then(isLogin => {
console.info('already login?', isLogin)
if (!isLogin) {
nightmare
.click('.user-info>a:nth-child(1)')
.insert('input#userMail', username)
.insert('input#userPassword', password)
.click('button.btn-login')
.wait(TIMES_TO_DELAY) // login need some times
}
// will redirect to write page directly
nightmare
.goto('https://my.oschina.net/JimmyLv/blog/edit') // this way will logout, no idea
// .click('.nav-action.dropdown') // this will new tab
// .click('li[_v-c254183c]:nth-child(2)')
.wait('input#title')
.insert('input#title', meta.title)
.insert('textarea#mdeditor', content)
.click('.select-box')
.click('[data-value="428612"]') // category='前端开发'
.click('button.btn-save')
.wait(TIMES_TO_DELAY) // publish need some times
.url()
.end()
.then(url => console.info(`发布成功 => [${meta.title}](${url})`))
.catch(err => console.error(err))
})
}

module.exports = publish

0 comments on commit 5e0fdc9

Please sign in to comment.