修改支持跟新github

This commit is contained in:
LingZhaoHui 2020-07-26 21:58:44 +08:00
parent 3852e4631c
commit deace660f3
7 changed files with 100 additions and 21 deletions

1
.gitignore vendored
View File

@ -49,3 +49,4 @@ target
*.iml *.iml
gradle gradle
logs logs
build

18
build.sh Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env bash
rm -rf ./build
if [ ! -d "./build" ]
then
mkdir build
fi
mvn clean
mvn install -Dmaven.test.skip=true
cp -r ./target/github_zeekling-1.0.jar ./build/
cp -r ./start.sh ./build/
cp -r ./src/main/resources/blog.properties ./build/
cp -r ./src/main/resources/log4j.properties ./build/
cp -r ./target/lib ./build/

42
pom.xml
View File

@ -6,7 +6,7 @@
<groupId>com.zeekling</groupId> <groupId>com.zeekling</groupId>
<artifactId>github_zeekling</artifactId> <artifactId>github_zeekling</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0</version>
<dependencies> <dependencies>
@ -49,7 +49,13 @@
<artifactId>rome</artifactId> <artifactId>rome</artifactId>
<version>1.6.0</version> <version>1.6.0</version>
</dependency> </dependency>
<!-- Thanks for using https://jar-download.com --> <dependency>
<groupId>sunjce_provider</groupId>
<artifactId>sunjce_provider</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/lib/sunjce_provider.jar</systemPath>
</dependency>
</dependencies> </dependencies>
@ -64,6 +70,38 @@
<target>1.8</target> <target>1.8</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.zeekling.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>

View File

@ -2,6 +2,8 @@ package com.zeekling;
import com.zeekling.blog.BlogUpdateService; import com.zeekling.blog.BlogUpdateService;
import com.zeekling.blog.BlogUpdateServiceImpl; import com.zeekling.blog.BlogUpdateServiceImpl;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
/** /**
* @author zeekling [lingzhaohui@zeekling.cn] * @author zeekling [lingzhaohui@zeekling.cn]
@ -11,10 +13,17 @@ import com.zeekling.blog.BlogUpdateServiceImpl;
*/ */
public class Main { public class Main {
private static final Logger LOGGER = LogManager.getLogger(Main.class);
public static void main(String[] args) { public static void main(String[] args) {
BlogUpdateService updateService = new BlogUpdateServiceImpl("/home/zeek/project/github_zeekling/src/main/resources/blog.properties"); String configPath = System.getProperty("configPath");
BlogUpdateService updateService = new BlogUpdateServiceImpl(configPath);
int res = updateService.update(); int res = updateService.update();
System.out.println(res); if (res == 0){
LOGGER.info("update github success!");
return;
}
LOGGER.error("update github failed!");
} }
} }

View File

@ -50,6 +50,7 @@ public final class GitHubs {
final HttpResponse res = HttpRequest.get("https://hacpai.com/github/repos?id=" + githubUserId).trustAllCerts(true). final HttpResponse res = HttpRequest.get("https://hacpai.com/github/repos?id=" + githubUserId).trustAllCerts(true).
connectionTimeout(3000).timeout(7000).header("User-Agent", GitHubConstants.USER_AGENT).send(); connectionTimeout(3000).timeout(7000).header("User-Agent", GitHubConstants.USER_AGENT).send();
if (200 != res.statusCode()) { if (200 != res.statusCode()) {
LOGGER.error("error code:" + res.statusCode());
return null; return null;
} }
res.charset("UTF-8"); res.charset("UTF-8");
@ -176,12 +177,13 @@ public final class GitHubs {
final HttpResponse response = HttpRequest.get("https://api.github.com/user").header("Authorization", "token " + pat). final HttpResponse response = HttpRequest.get("https://api.github.com/user").header("Authorization", "token " + pat).
connectionTimeout(7000).timeout(30000).header("User-Agent", GitHubConstants.USER_AGENT).send(); connectionTimeout(7000).timeout(30000).header("User-Agent", GitHubConstants.USER_AGENT).send();
if (200 != response.statusCode()) { if (200 != response.statusCode()) {
LOGGER.error("error code:" + response.statusCode());
return null; return null;
} }
response.charset("UTF-8"); response.charset("UTF-8");
return new JSONObject(response.bodyText()); return new JSONObject(response.bodyText());
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.ERROR, "Gets GitHub user info failed: " + e.getMessage()); LOGGER.log(Level.ERROR, "Gets GitHub user info failed: " + e);
return null; return null;
} }
} }

View File

@ -1,24 +1,31 @@
### 设置### log4j.rootLogger=INFO,stdout,R, E
log4j.rootLogger = debug,stdout,D,E
### 输出信息到控制抬 ###
log4j.appender.stdout = org.apache.log4j.ConsoleAppender log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c] [%p] - %m%n
### 输出DEBUG 级别以上的日志到=./logs/debug.log ### log4j.appender.file = org.apache.log4j.FileAppender
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender log4j.appender.file.File = ./logs/spider.log
log4j.appender.D.File = ./logs/debug.log log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.D.Append = true log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c] [%p] - %m%n
log4j.appender.D.Threshold = DEBUG
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
### 输出ERROR 级别以上的日志到=./logs/error.log ### ### 输出到日志文件 ###
# 每天生成一个新的日志文件
log4j.appender.R = org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File = ./logs/log.log
log4j.appender.R.Append = true
# DEBUG级别及以上的日志信息输出到./logs/log.log中
log4j.appender.R.Threshold = DEBUG
log4j.appender.R.layout = org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} [%t] [%c] [%p] - %m%n
### 保存异常信息到单独文件 ###
# 每天生成一个新的日志文件
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File =./logs/error.log log4j.appender.E.File = ./logs/error.log
log4j.appender.E.Append = true log4j.appender.E.Append = true
# ERROR级别及以上的日志信息输出到./logs/log.log中
log4j.appender.E.Threshold = ERROR log4j.appender.E.Threshold = ERROR
log4j.appender.E.layout = org.apache.log4j.PatternLayout log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n log4j.appender.E.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} [%t] [%c] [%p] - %m%n

4
start.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
java -Djava.ext.dirs=./lib -DconfigPath=./blog.properties -cp github_zeekling-1.0.jar com.zeekling.Main