使用程式碼將github倉庫裡某個issue同步到CSDN部落格上
我是一個懶惰的程式設計師。我在github倉庫裡用issue的方式寫了很多分享文章,想同步到CSDN上。但是我又不想一篇篇手動複製貼上,因此想用程式碼來實現自動化。
例子:
https://github.com/i042416/KnowlegeRepository/issues/2215
這是我的一個issue:
我使用下面這些nodejs程式碼實現從github 倉庫issue到CSDN部落格的拷貝:
var config = require("./mcConfig");var request = require('request');var querystring = require('querystring');function createPost(oPost) { var url = "https://mp.csdn.net/mdeditor/saveArticle"; var oBody = { title: oPost.title, markdowncontent: oPost.body, tags:"Fiori", categories:"Fiori", channel:"14", type:"original", articleedittype:"1", content: oPost.body };var formData = querystring.stringify(oBody);var contentLength = formData.length;var createPostOptions = { url: url, method: "POST", headers: { "content-type": "application/x-www-form-urlencoded", "Content-Length": contentLength, "origin" :"https://mp.csdn.net", "referer" :"https://mp.csdn.net/mdeditor", "User-Agent" :"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36", "cookie": config.cookie }, body: formData }; return new Promise(function(resolve,reject){ var requestC = request.defaults({jar: true}); console.log("Step1: create post via url: " url ); requestC(createPostOptions,function(error,response,body){ if(error){ reject(error); } console.log("response: " body); resolve(body); }); }); }module.exports = createPost;var request = require('request');function getIssue(issueNumber) { var url = "https://api.github.com/repos/i042416/KnowlegeRepository/issues/" issueNumber; var getIssueOptions = { url: url, method: "GET", json:true, headers: { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36" } }; return new Promise(function(resolve,reject){ var requestC = request.defaults({jar: true}); console.log("Step1: get issue detail via url: " url ); requestC(getIssueOptions,function(error,response,body){ if(error){ console.log("error occurred: " error); reject(error); } console.log("title:" body.title); console.log("body: " body.body); for( var i = 0; i < body.labels.length; i ){ console.log("label: " body.labels[i].name); } resolve(body); }); }); }module.exports = getIssue;var readIssue = require("./readIssueMod");var createPost = require("./createPostMod"); readIssue(2215).then(createPost).catch((error)=>{console.log("error: " error)});
執行結果:
已經自動同步到CSDN了,方便!
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2645497/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 自動同步 Github 倉庫到 Gitee 倉庫GithubGitee
- 將部落格搬至CSDN
- 如何自動同步部落格到 Github 主頁?Github
- 將 Hexo 個人部落格同時部署到 GitHub 和 Coding 上HexoGithub
- 怎麼上傳自己的程式碼/專案到自己的github倉庫上Github
- github同步fork倉庫Github
- 將倉庫下某個模組複製到新倉庫並保留提交記錄(非子庫)
- 在github上寫部落格Github
- GitIssue 隨時隨地訂閱閱讀 Github Issue 部落格Github
- CSDN部落格海報分享上線啦!
- 使用Hexo在Github上搭建自己的部落格HexoGithub
- github從一個倉庫切換到另一倉庫Github
- 把部落格同時部署到github和coding上Github
- git 上傳程式碼到遠端倉庫Git
- Github程式碼fork之後,如何與原倉庫進行同步?Github
- 開發一個簡單的工具,匯出github倉庫所有issue列表Github
- Git上fork後的程式碼倉庫如何與原倉庫進行同步Git
- 繫結Github上的個人部落格到Godaddy域名GithubGo
- 如何用git將專案程式碼上傳到githubGithub
- 如何在Github上建立一個新倉庫Github
- ubuntu16系統中pycharm下使用git將程式碼提交到github倉庫UbuntuPyCharmGithub
- git本地倉庫與GitHub的同步Github
- 使用 Github Actions 部署 VuePress 部落格GithubVue
- hexo部落格部署到github後進不去!HexoGithub
- git 同步fork的倉庫程式碼Git
- git 自動上傳程式碼到遠端倉庫Git
- 使用GitHub當部落格圖床提升部落格訪問速度Github圖床
- github上搭建個人部落格(有更新)Github
- 使用vscode編輯和提交github倉庫程式碼VSCodeGithub
- GitHub 新支援在 issue 插入程式碼段Github
- 批量匯出 CSDN 部落格並轉為 hexo 部落格風格Hexo
- ThinkPHP5+LayUI雲易部落格系統-自動同步CSDN網站的部落格資料PHPUI網站
- 使用 github 和 Deno Deploy 搭建一個部落格網站Github網站
- 使用github和hexo搭建部落格GithubHexo
- 使用 github + jekyll 搭建個人部落格Github
- 如何將docker 映象上傳到docker hub倉庫Docker
- 部落格搬家到 http://leijun00.github.ioHTTPGithub
- SVN程式碼倉庫主從同步方案主從同步