Skip to content
This repository has been archived by the owner on Dec 31, 2024. It is now read-only.

Commit

Permalink
- 小修改
Browse files Browse the repository at this point in the history
  • Loading branch information
mikoto2464 committed Jan 8, 2022
1 parent da4fb87 commit d070c16
Show file tree
Hide file tree
Showing 39 changed files with 40 additions and 120 deletions.
Binary file not shown.
Empty file.
Binary file removed .gradle/7.1/executionHistory/executionHistory.bin
Binary file not shown.
Binary file removed .gradle/7.1/executionHistory/executionHistory.lock
Binary file not shown.
Binary file removed .gradle/7.1/fileChanges/last-build.bin
Binary file not shown.
Binary file removed .gradle/7.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file removed .gradle/7.1/fileHashes/fileHashes.lock
Binary file not shown.
Empty file removed .gradle/7.1/gc.properties
Empty file.
Binary file modified .gradle/7.2/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/7.2/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/7.2/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/7.2/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/7.2/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file modified .gradle/checksums/checksums.lock
Binary file not shown.
Binary file modified .gradle/checksums/md5-checksums.bin
Binary file not shown.
Binary file modified .gradle/checksums/sha1-checksums.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group 'net.mikoto.pixiv'
version '1.0.1'
version '1.0.4'

repositories {
mavenCentral()
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified build/classes/java/main/net/mikoto/pixiv/engine/util/HttpUtil.class
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h1>PixivEngineTest</h1>
</td>
<td>
<div class="infoBox" id="duration">
<div class="counter">1.744s</div>
<div class="counter">0.017s</div>
<p>duration</p>
</div>
</td>
Expand Down Expand Up @@ -79,25 +79,15 @@ <h2>Tests</h2>
</thead>
<tr>
<td class="success">test()</td>
<td class="success">1.744s</td>
<td class="success">0.017s</td>
<td class="success">passed</td>
</tr>
</table>
</div>
<div id="tab1" class="tab">
<h2>Standard output</h2>
<span class="code">
<pre>[2021-12-26 02:23:31] INFO :Query data(id:0)
[2021-12-26 02:23:31] INFO :Query data(id:0)
[2021-12-26 02:23:31] INFO :Query data(id:0)
[2021-12-26 02:23:31] INFO :Query data(id:0)
[2021-12-26 02:23:31] INFO :Query data(id:0)
[2021-12-26 02:23:31] INFO :Query data(id:0)
[2021-12-26 02:23:31] INFO :Query data(id:0)
[2021-12-26 02:23:32] INFO :Query data(id:0)
[2021-12-26 02:23:32] INFO :Query data(id:0)
[2021-12-26 02:23:32] INFO :Query data(id:0)
null
<pre>
</pre>
</span>
</div>
Expand All @@ -109,7 +99,7 @@ <h2>Standard output</h2>
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
</label>
</div>Generated by
<a href="http://www.gradle.org">Gradle 7.2</a> at 2021年12月26日 上午2:23:32</p>
<a href="http://www.gradle.org">Gradle 7.2</a> at 2022年1月2日 下午1:28:23</p>
</div>
</div>
</body>
Expand Down
8 changes: 4 additions & 4 deletions build/reports/tests/test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h1>Test Summary</h1>
</td>
<td>
<div class="infoBox" id="duration">
<div class="counter">1.744s</div>
<div class="counter">0.017s</div>
<p>duration</p>
</div>
</td>
Expand Down Expand Up @@ -85,7 +85,7 @@ <h2>Packages</h2>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1.744s</td>
<td>0.017s</td>
<td class="success">100%</td>
</tr>
</tbody>
Expand All @@ -112,7 +112,7 @@ <h2>Classes</h2>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1.744s</td>
<td>0.017s</td>
<td class="success">100%</td>
</tr>
</tbody>
Expand All @@ -126,7 +126,7 @@ <h2>Classes</h2>
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
</label>
</div>Generated by
<a href="http://www.gradle.org">Gradle 7.2</a> at 2021年12月26日 上午2:23:32</p>
<a href="http://www.gradle.org">Gradle 7.2</a> at 2022年1月2日 下午1:28:23</p>
</div>
</div>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h1>Package net.mikoto.pixiv.engine</h1>
</td>
<td>
<div class="infoBox" id="duration">
<div class="counter">1.744s</div>
<div class="counter">0.017s</div>
<p>duration</p>
</div>
</td>
Expand Down Expand Up @@ -83,7 +83,7 @@ <h2>Classes</h2>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1.744s</td>
<td>0.017s</td>
<td class="success">100%</td>
</tr>
</table>
Expand All @@ -96,7 +96,7 @@ <h2>Classes</h2>
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
</label>
</div>Generated by
<a href="http://www.gradle.org">Gradle 7.2</a> at 2021年12月26日 上午2:23:32</p>
<a href="http://www.gradle.org">Gradle 7.2</a> at 2022年1月2日 下午1:28:23</p>
</div>
</div>
</body>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="net.mikoto.pixiv.engine.PixivEngineTest" tests="1" skipped="0" failures="0" errors="0" timestamp="2021-12-25T18:23:30" hostname="DESKTOP-JA9T16E" time="1.744">
<testsuite name="net.mikoto.pixiv.engine.PixivEngineTest" tests="1" skipped="0" failures="0" errors="0" timestamp="2022-01-02T05:28:23" hostname="DESKTOP-JA9T16E" time="0.017">
<properties/>
<testcase name="test()" classname="net.mikoto.pixiv.engine.PixivEngineTest" time="1.744"/>
<system-out><![CDATA[[2021-12-26 02:23:31] INFO :Query data(id:0)
[2021-12-26 02:23:31] INFO :Query data(id:0)
[2021-12-26 02:23:31] INFO :Query data(id:0)
[2021-12-26 02:23:31] INFO :Query data(id:0)
[2021-12-26 02:23:31] INFO :Query data(id:0)
[2021-12-26 02:23:31] INFO :Query data(id:0)
[2021-12-26 02:23:31] INFO :Query data(id:0)
[2021-12-26 02:23:32] INFO :Query data(id:0)
[2021-12-26 02:23:32] INFO :Query data(id:0)
[2021-12-26 02:23:32] INFO :Query data(id:0)
null
<testcase name="test()" classname="net.mikoto.pixiv.engine.PixivEngineTest" time="0.017"/>
<system-out><![CDATA[
]]></system-out>
<system-err><![CDATA[]]></system-err>
</testsuite>
12 changes: 1 addition & 11 deletions build/test-results/test/binary/output.bin
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
.[2021-12-26 02:23:31] INFO :Query data(id:0)
.[2021-12-26 02:23:31] INFO :Query data(id:0)
.[2021-12-26 02:23:31] INFO :Query data(id:0)
.[2021-12-26 02:23:31] INFO :Query data(id:0)
.[2021-12-26 02:23:31] INFO :Query data(id:0)
.[2021-12-26 02:23:31] INFO :Query data(id:0)
.[2021-12-26 02:23:31] INFO :Query data(id:0)
.[2021-12-26 02:23:32] INFO :Query data(id:0)
.[2021-12-26 02:23:32] INFO :Query data(id:0)
.[2021-12-26 02:23:32] INFO :Query data(id:0)
null

Binary file modified build/test-results/test/binary/output.bin.idx
Binary file not shown.
Binary file modified build/test-results/test/binary/results.bin
Binary file not shown.
Binary file modified build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
Binary file modified build/tmp/compileTestJava/previous-compilation-data.bin
Binary file not shown.
1 change: 0 additions & 1 deletion src/main/java/net/mikoto/pixiv/engine/PixivEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class PixivEngine {

public PixivEngine(@NotNull Config config) {
if (config.getJpbcUrl() == null
|| config.getLogger() == null
|| config.getUserName() == null
|| config.getUserPassword() == null
|| config.getPixivDataForwardServer() == null
Expand Down
17 changes: 4 additions & 13 deletions src/main/java/net/mikoto/pixiv/engine/dao/PixivDataDao.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.mikoto.pixiv.engine.dao;

import net.mikoto.dao.BaseDao;
import net.mikoto.log.Logger;
import net.mikoto.pixiv.api.pojo.PixivData;
import net.mikoto.pixiv.engine.pojo.Config;
import org.jetbrains.annotations.NotNull;
Expand All @@ -13,9 +12,6 @@
import java.util.HashMap;
import java.util.Map;

import static net.mikoto.pixiv.engine.util.CharUtil.stringToUnicode;
import static net.mikoto.pixiv.engine.util.CharUtil.unicodeToString;


/**
* @author mikoto
Expand All @@ -33,7 +29,6 @@ public class PixivDataDao extends BaseDao {
private static final Integer GRAND_8 = 5000;
private static final Integer GRAND_9 = 1000;
private static final Integer GRAND_10 = 0;
private final Logger logger;

/**
* Init method.
Expand All @@ -42,7 +37,6 @@ public class PixivDataDao extends BaseDao {
*/
public PixivDataDao(@NotNull Config config) {
super(config.getJpbcUrl(), config.getUserName(), config.getUserPassword());
this.logger = config.getLogger();
}

/**
Expand All @@ -60,8 +54,8 @@ public PixivData queryPixivData(String sql) throws SQLException {
outputPixivData.setArtworkId(resultSet.getInt("pk_artwork_id"));
outputPixivData.setArtworkTitle(resultSet.getString("artwork_title"));
outputPixivData.setAuthorId(resultSet.getInt("author_id"));
outputPixivData.setAuthorName(unicodeToString(resultSet.getString("author_name")));
outputPixivData.setDescription(unicodeToString(resultSet.getString("description")));
outputPixivData.setAuthorName(resultSet.getString("author_name"));
outputPixivData.setDescription(resultSet.getString("description"));
outputPixivData.setPageCount(resultSet.getInt("page_count"));
outputPixivData.setBookmarkCount(resultSet.getInt("bookmark_count"));
outputPixivData.setLikeCount(resultSet.getInt("like_count"));
Expand All @@ -80,8 +74,6 @@ public PixivData queryPixivData(String sql) throws SQLException {
outputPixivData.setIllustUrls(illustUrls);
}

logger.log("Query data(id:" + outputPixivData.getArtworkId() + ")");

return outputPixivData;
}

Expand Down Expand Up @@ -112,8 +104,8 @@ public void insertPixivData(@NotNull PixivData pixivData) throws SQLException {
preparedStatement.setInt(1, pixivData.getArtworkId());
preparedStatement.setString(2, pixivData.getArtworkTitle());
preparedStatement.setInt(3, pixivData.getAuthorId());
preparedStatement.setString(4, stringToUnicode(pixivData.getAuthorName()));
preparedStatement.setString(5, stringToUnicode(pixivData.getDescription()));
preparedStatement.setString(4, pixivData.getAuthorName());
preparedStatement.setString(5, pixivData.getDescription());
StringBuilder tags = new StringBuilder();
for (int i = 0; i < pixivData.getTags().length; i++) {
tags.append(pixivData.getTags()[i]);
Expand All @@ -136,7 +128,6 @@ public void insertPixivData(@NotNull PixivData pixivData) throws SQLException {
preparedStatement.setString(18, pixivData.getCreateDate());
preparedStatement.setString(19, pixivData.getCrawlDate());
preparedStatement.executeUpdate();
logger.log("update data(id:" + pixivData.getArtworkId() + ")");

preparedStatement.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import net.mikoto.log.Logger;
import net.mikoto.pixiv.api.pojo.PixivData;
import net.mikoto.pixiv.engine.dao.PixivDataDao;
import net.mikoto.pixiv.engine.pojo.Config;
Expand All @@ -17,7 +16,6 @@
import java.util.Date;
import java.util.Random;

import static net.mikoto.pixiv.engine.util.CharUtil.stringToUnicode;
import static net.mikoto.pixiv.engine.util.HttpUtil.httpGet;

/**
Expand All @@ -29,7 +27,6 @@ public class PixivDataService {
private static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private final ArrayList<String> pixivDataForwardServer;
private final String key;
private final Logger logger;
private final ArrayList<String> tableName = new ArrayList<>();
private Integer lastServer = 0;

Expand All @@ -39,7 +36,6 @@ public class PixivDataService {
public PixivDataService(@NotNull Config config) {
this.key = config.getKey();
this.pixivDataForwardServer = config.getPixivDataForwardServer();
this.logger = config.getLogger();
tableName.add("bookmark_1000_5000");
tableName.add("bookmark_5000_10000");
tableName.add("bookmark_10000_15000");
Expand Down Expand Up @@ -78,7 +74,6 @@ private PixivData crawlPixivDataById(@NotNull String server, @NotNull Integer ar
} catch (InterruptedException ex) {
ex.printStackTrace();
}
logger.log("Failed to get data(id:" + artworkId + ") [Network error]");
crawlPixivDataById(server, artworkId);
}
} catch (IOException e) {
Expand All @@ -89,7 +84,6 @@ private PixivData crawlPixivDataById(@NotNull String server, @NotNull Integer ar
} catch (InterruptedException e) {
e.printStackTrace();
}
logger.log("Success to get data(id:" + artworkId + ")");
return pixivData;
}

Expand All @@ -98,7 +92,7 @@ private PixivData crawlPixivDataById(@NotNull String server, @NotNull Integer ar
*
* @return server address.
*/
private synchronized String getPixivDataForwardServer() {
public synchronized String getPixivDataForwardServer() {
if (lastServer >= pixivDataForwardServer.size()) {
lastServer = 0;
}
Expand All @@ -115,8 +109,8 @@ private synchronized String getPixivDataForwardServer() {
* @return A pixiv data.
* @throws SQLException An error.
*/
public PixivData getPixivDataById(@NotNull Integer artworkId, @NotNull PixivDataDao pixivDataDao) throws SQLException {
PixivData pixivData = crawlPixivDataById(getPixivDataForwardServer(), artworkId);
public PixivData getPixivDataById(@NotNull String server, @NotNull Integer artworkId, @NotNull PixivDataDao pixivDataDao) throws SQLException {
PixivData pixivData = crawlPixivDataById(server, artworkId);
if (pixivData != null) {
pixivDataDao.insertPixivData(pixivData);
} else {
Expand Down Expand Up @@ -165,7 +159,7 @@ public PixivData getPixivDataByAuthorName(@NotNull String authorName, @NotNull P

for (Integer page :
pageArray) {
String sql = "SELECT * FROM `" + tableName.get(page) + "` WHERE `author_name` LIKE '%" + stringToUnicode(authorName) + "%' order by rand() limit 1";
String sql = "SELECT * FROM `" + tableName.get(page) + "` WHERE `author_name` LIKE '%" + authorName + "%' order by rand() limit 1";

PixivData pixivData = pixivDataDao.queryPixivData(sql);

Expand All @@ -183,6 +177,7 @@ public PixivData getPixivDataByAuthorName(@NotNull String authorName, @NotNull P
*
* @return An array list.
*/
@NotNull
private ArrayList<Integer> getPageArray() {
Random rand = new Random();
ArrayList<Integer> pageArray = new ArrayList<>();
Expand Down
41 changes: 0 additions & 41 deletions src/main/java/net/mikoto/pixiv/engine/util/CharUtil.java

This file was deleted.

24 changes: 15 additions & 9 deletions src/main/java/net/mikoto/pixiv/engine/util/HttpUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.net.SocketTimeoutException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.*;
Expand Down Expand Up @@ -54,14 +55,19 @@ public static Map<String, String> formData2Dic(String formData) {
*/
@NotNull
public static String httpGet(String url) throws IOException {
String result;
OkHttpClient client = new OkHttpClient.Builder()
.protocols(Collections.singletonList(Protocol.HTTP_1_1))
.readTimeout(5, TimeUnit.MINUTES)
.build();
Request request = new Request.Builder().url(url).build();
Response response = client.newCall(request).execute();
result = Objects.requireNonNull(response.body()).string();
return result;
try {
String result;
OkHttpClient client = new OkHttpClient.Builder()
.protocols(Collections.singletonList(Protocol.HTTP_1_1))
.readTimeout(5, TimeUnit.MINUTES)
.retryOnConnectionFailure(true)
.build();
Request request = new Request.Builder().url(url).build();
Response response = client.newCall(request).execute();
result = Objects.requireNonNull(response.body()).string();
return result;
} catch (SocketTimeoutException e) {
return httpGet(url);
}
}
}

0 comments on commit d070c16

Please sign in to comment.