Compare commits
10 Commits
Author | SHA1 | Date |
---|---|---|
LingZhaoHui | 3943de1696 | |
LingZhaoHui | a71bde4a04 | |
LingZhaoHui | 46a0faca8a | |
LingZhaoHui | a04540e6f2 | |
LingZhaoHui | 9a70b76324 | |
LingZhaoHui | d3a78d414a | |
LingZhaoHui | 30d46c56b9 | |
LingZhaoHui | 4b7d53d2dc | |
LingZhaoHui | 174d35dc96 | |
LingZhaoHui | 2cf756e34d |
|
@ -1,5 +1,6 @@
|
||||||
## 跟新个人主页
|
## 跟新个人主页
|
||||||
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
git clone ssh://git@git.zeekling.cn:222/zeekling/github_zeekling.git
|
git clone ssh://git@git.zeekling.cn:222/zeekling/github_zeekling.git
|
||||||
cd github_zeekling
|
cd github_zeekling
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.zeekling.blog;
|
package com.zeekling.blog;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zeekling [lingzhaohui@zeekling.cn]
|
* @author zeekling [lingzhaohui@zeekling.cn]
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
|
@ -11,4 +13,6 @@ public interface BlogUpdateService {
|
||||||
|
|
||||||
int update();
|
int update();
|
||||||
|
|
||||||
|
JSONArray getGitHubRepos();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,15 +7,22 @@ import com.zeekling.util.ConfigureUtil;
|
||||||
import com.zeekling.util.FeedXmlUtil;
|
import com.zeekling.util.FeedXmlUtil;
|
||||||
import com.zeekling.util.FileUtils;
|
import com.zeekling.util.FileUtils;
|
||||||
import com.zeekling.util.GitHubs;
|
import com.zeekling.util.GitHubs;
|
||||||
|
import jodd.http.HttpRequest;
|
||||||
|
import jodd.http.HttpResponse;
|
||||||
import org.apache.log4j.Level;
|
import org.apache.log4j.Level;
|
||||||
import org.apache.log4j.LogManager;
|
import org.apache.log4j.LogManager;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zeekling [lingzhaohui@zeekling.cn]
|
* @author zeekling [lingzhaohui@zeekling.cn]
|
||||||
|
@ -72,44 +79,61 @@ public class BlogUpdateServiceImpl implements BlogUpdateService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String genSoloBlogReadme(final String repoFullName) {
|
private String genSoloBlogReadme(final String repoFullName) {
|
||||||
final StringBuilder bodyBuilder = new StringBuilder("### 最新\n");
|
final StringBuilder bodyBuilder = new StringBuilder("### 最新文章\n");
|
||||||
try {
|
try {
|
||||||
List<SyndEntry> entries = FeedXmlUtil.parseXml(blogConfigure.getRss());
|
List<SyndEntry> entries = FeedXmlUtil.parseXml(blogConfigure.getRss());
|
||||||
for (SyndEntry syndEntry: entries){
|
for (SyndEntry syndEntry: entries){
|
||||||
String des = syndEntry.getDescription().getValue();
|
bodyBuilder.append("\n* \uD83D\uDCDD [")
|
||||||
des = des.replaceAll("\n", "\n > ");
|
.append(syndEntry.getTitle())
|
||||||
bodyBuilder.append("\n* \uD83D\uDCDD [").append(syndEntry.getTitle()).append("](").append(syndEntry.getLink())
|
.append("](")
|
||||||
.append(") \n > ").append(des);
|
.append(syndEntry.getLink())
|
||||||
|
.append(") \n ");
|
||||||
}
|
}
|
||||||
} catch (FeedException | MalformedURLException e) {
|
} catch (FeedException | MalformedURLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
bodyBuilder.append("\n\n");
|
bodyBuilder.append("\n\n");
|
||||||
|
|
||||||
String ret = "### Hey \uD83D\uDC4B, I'm [ZEEKLING](https://www.zeekling.cn)! \n" +
|
String ret = "### Hey \uD83D\uDC4B, I'm [${title}](${home})! \n" +
|
||||||
"![Github Stats](https://github-readme-stats.vercel.app/api?username=zeekling&show_icons=true) \n" +
|
"\n![Github Stats](https://github-readme-stats-zeekling.vercel.app/api?username=${username}&show_icons=true) \n\n" +
|
||||||
"### 我在[小令童鞋](https://www.zeekling.cn)的近期动态\n" +
|
"### 我在博客[${title}](${home})的近期动态\n" +
|
||||||
"\n" +
|
"⭐️ Star [个人主页](https://github.com/${username}) 后会自动更新" +
|
||||||
"⭐️ Star [个人主页](https://github.com/zeekling/zeekling) 后会自动更新" +
|
"\n\n<p align=\"center\"><img alt=\"${title}\" src=\"${favicon}\"></p>" +
|
||||||
"\n<p align=\"center\"><img alt=\"${title}\" src=\"${favicon}\"></p><h2 align=\"center\">" +
|
"<h2 align=\"center\"> ${title} </h2>\n" +
|
||||||
"${title}\n" +
|
"\n" +
|
||||||
"</h2>\n" +
|
"<h4 align=\"center\">${subtitle}</h4>\n" +
|
||||||
"\n" +
|
"<p align=\"center\">" +
|
||||||
"<h4 align=\"center\">${subtitle}</h4>\n" +
|
"<a title=\"${title}\" target=\"_blank\" href=\"https://github.com/${repoFullName}\"><img src=\"https://img.shields.io/github/last-commit/${repoFullName}.svg?style=flat-square&color=FF9900\"></a>\n" +
|
||||||
"<p align=\"center\">" +
|
"<a title=\"GitHub repo size in bytes\" target=\"_blank\" href=\"https://github.com/${repoFullName}\"><img src=\"https://img.shields.io/github/repo-size/${repoFullName}.svg?style=flat-square\"></a>\n" +
|
||||||
"<a title=\"${title}\" target=\"_blank\" href=\"https://github.com/${repoFullName}\"><img src=\"https://img.shields.io/github/last-commit/${repoFullName}.svg?style=flat-square&color=FF9900\"></a>\n" +
|
"<a title=\"Hits\" target=\"_blank\" href=\"https://github.com/${username}/hits\">" +
|
||||||
"<a title=\"GitHub repo size in bytes\" target=\"_blank\" href=\"https://github.com/${repoFullName}\"><img src=\"https://img.shields.io/github/repo-size/${repoFullName}.svg?style=flat-square\"></a>\n" +
|
"<img src=\"https://hits.b3log.org/${repoFullName}.svg\"></a>" +
|
||||||
"<a title=\"Hits\" target=\"_blank\" href=\"https://github.com/zeekling/hits\"><img src=\"https://hits.b3log.org/${repoFullName}.svg\"></a>" +
|
"</p>\n" +
|
||||||
"</p>\n" +
|
"\n" +
|
||||||
"\n" +
|
"${body}\n\n" +
|
||||||
"${body}\n\n" +
|
"\n";
|
||||||
"\n" ;
|
|
||||||
ret = ret.replace("${title}", blogConfigure.getClientTitle()).
|
ret = ret.replace("${title}", blogConfigure.getClientTitle()).
|
||||||
replace("${subtitle}", blogConfigure.getClientSubtitle()).
|
replace("${subtitle}", blogConfigure.getClientSubtitle()).
|
||||||
replace("${favicon}", blogConfigure.getFavicon()).
|
replace("${favicon}", blogConfigure.getFavicon()).
|
||||||
replace("${repoFullName}", repoFullName).
|
replace("${repoFullName}", repoFullName).
|
||||||
replace("${body}", bodyBuilder.toString());
|
replace("${body}", bodyBuilder.toString()).
|
||||||
|
replace("${username}", blogConfigure.getRepoName()).
|
||||||
|
replace("${home}", blogConfigure.getHome());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONArray getGitHubRepos() {
|
||||||
|
if (blogConfigure == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final JSONObject gitHubUser = GitHubs.getGitHubUser(blogConfigure.getPat());
|
||||||
|
if (null == gitHubUser) {
|
||||||
|
LOGGER.error("login failed");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
LOGGER.info("login success");
|
||||||
|
final String myGitHubID = gitHubUser.optString("login");
|
||||||
|
return GitHubs.getGitHubRepos(myGitHubID);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,19 +47,14 @@ public final class GitHubs {
|
||||||
*/
|
*/
|
||||||
public static JSONArray getGitHubRepos(final String githubUserId) {
|
public static JSONArray getGitHubRepos(final String githubUserId) {
|
||||||
try {
|
try {
|
||||||
final HttpResponse res = HttpRequest.get("https://hacpai.com/github/repos?id=" + githubUserId).trustAllCerts(true).
|
final HttpResponse res = HttpRequest.get("https://api.github.com/users/" + githubUserId + "/repos").
|
||||||
connectionTimeout(3000).timeout(7000).header("User-Agent", GitHubConstants.USER_AGENT).send();
|
connectionTimeout(20000).timeout(60000).header("User-Agent", GitHubConstants.USER_AGENT).send();
|
||||||
if (200 != res.statusCode()) {
|
if (200 != res.statusCode()) {
|
||||||
LOGGER.error("error code:" + res.statusCode());
|
LOGGER.error("error code:" + res.statusCode());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
res.charset("UTF-8");
|
res.charset("UTF-8");
|
||||||
final JSONObject result = new JSONObject(res.bodyText());
|
return new JSONArray(res.bodyText());
|
||||||
if (0 != result.optInt(GitHubConstants.CODE)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
final JSONObject data = result.optJSONObject(GitHubConstants.DATA);
|
|
||||||
return data.optJSONArray("githubrepos");
|
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
LOGGER.log(Level.ERROR, "Gets GitHub repos failed", e);
|
LOGGER.log(Level.ERROR, "Gets GitHub repos failed", e);
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -14,7 +14,7 @@ public class BlogUpdateTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateGitHub(){
|
public void updateGitHub(){
|
||||||
String configPath = "/home/zeek/project/github_zeekling/src/main/resources/blog.properties";
|
String configPath = "/home/zeekling/project/ling/github_zeekling/src/main/resources/blog.properties";
|
||||||
BlogUpdateService updateService = new BlogUpdateServiceImpl(configPath);
|
BlogUpdateService updateService = new BlogUpdateServiceImpl(configPath);
|
||||||
int res = updateService.update();
|
int res = updateService.update();
|
||||||
if (res == 0){
|
if (res == 0){
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
package com.zeekling.util;
|
package com.zeekling.util;
|
||||||
|
|
||||||
|
import com.zeekling.blog.BlogUpdateService;
|
||||||
|
import com.zeekling.blog.BlogUpdateServiceImpl;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zeekling [lingzhaohui@zeekling.cn]
|
* @author zeekling [lingzhaohui@zeekling.cn]
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
|
@ -8,6 +15,63 @@ package com.zeekling.util;
|
||||||
*/
|
*/
|
||||||
public class GitHubsTest {
|
public class GitHubsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void genGitHubInfo() {
|
||||||
|
String configPath = "/home/zeekling/project/ling/github_zeekling/src/main/resources/blog.properties";
|
||||||
|
BlogUpdateService updateService = new BlogUpdateServiceImpl(configPath);
|
||||||
|
JSONArray result = updateService.getGitHubRepos();
|
||||||
|
JSONArray compatibleResult = new JSONArray();
|
||||||
|
for (int i = 0; i < result.length(); i++){
|
||||||
|
JSONObject resultObject = result.optJSONObject(i);
|
||||||
|
JSONObject compatibleObject = new JSONObject();
|
||||||
|
|
||||||
|
if (resultObject.getBoolean("fork")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
compatibleObject.put("githubrepoId", resultObject.optString("id"));
|
||||||
|
compatibleObject.put("githubrepoStatus", 0);
|
||||||
|
compatibleObject.put("oId", "" + System.currentTimeMillis());
|
||||||
|
compatibleObject.put("githubrepoDescription", resultObject.optString("description"));
|
||||||
|
compatibleObject.put("githubrepoHomepage", resultObject.optString("homepage"));
|
||||||
|
compatibleObject.put("githubrepoForksCount", resultObject.optLong("forks_count"));
|
||||||
|
compatibleObject.put("githubrepoOwnerId", resultObject.optJSONObject("owner").optString("id"));
|
||||||
|
compatibleObject.put("githubrepoStargazersCount", resultObject.optLong("stargazers_count"));
|
||||||
|
compatibleObject.put("githubrepoWatchersCount", resultObject.optLong("watchers_count"));
|
||||||
|
compatibleObject.put("githubrepoOwnerLogin", resultObject.optJSONObject("owner").optString("login"));
|
||||||
|
compatibleObject.put("githubrepoHTMLURL", resultObject.optString("html_url"));
|
||||||
|
compatibleObject.put("githubrepoLanguage", resultObject.optString("language"));
|
||||||
|
compatibleObject.put("githubrepoName", resultObject.optString("name"));
|
||||||
|
compatibleObject.put("githubrepoFullName", resultObject.optString("full_name"));
|
||||||
|
|
||||||
|
compatibleResult.put(compatibleObject);
|
||||||
|
}
|
||||||
|
System.out.println(compatibleResult);
|
||||||
|
|
||||||
|
final StringBuilder contentBuilder = new StringBuilder();
|
||||||
|
String stats = "\n![Github Stats](https://github-readme-stats.vercel.app/api?username={username}&show_icons=true) \n\n";
|
||||||
|
stats = stats.replace("{username}", "zeekling");
|
||||||
|
contentBuilder.append("![GitHub Repo](/images/github_repo.jpg)\n\n");
|
||||||
|
contentBuilder.append("## Github Stats\n").append(stats);
|
||||||
|
contentBuilder.append("## 所有开源项目\n");
|
||||||
|
contentBuilder.append("| 仓库 | 项目简介 | 收藏数 | fork数 | 项目主页 | 主要编程语言 |\n | ---- | ---- | ---- | ---- | ---- | ---- |\n");
|
||||||
|
for (int i = 0; i < compatibleResult.length(); i++) {
|
||||||
|
final JSONObject repo = compatibleResult.optJSONObject(i);
|
||||||
|
final String url = repo.optString("githubrepoHTMLURL");
|
||||||
|
final String desc = repo.optString("githubrepoDescription");
|
||||||
|
final String name = repo.optString("githubrepoName");
|
||||||
|
final String stars = repo.optString("githubrepoStargazersCount");
|
||||||
|
final String forks = repo.optString("githubrepoForksCount");
|
||||||
|
final String lang = repo.optString("githubrepoLanguage");
|
||||||
|
final String hp = repo.optString("githubrepoHomepage");
|
||||||
|
contentBuilder.append("| [").append(name).append("](").append(url).append(") | ")
|
||||||
|
.append(desc).append(" | ")
|
||||||
|
.append(stars).append(" | ")
|
||||||
|
.append(forks).append(" | ")
|
||||||
|
.append(hp).append(" | ")
|
||||||
|
.append(lang).append("|\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
FileUtils.saveDataToFile("/tmp/GITHUB.md", contentBuilder.toString());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue