fixed errors on parsing text due to JSON legacy compatibilities process in the REDDIT JSON API.

from https://www.reddit.com/dev/api : "response body encoding
For legacy reasons, all JSON response bodies currently have <, >, and & replaced with &lt;, &gt;, and &amp;, respectively. If you wish to opt out of this behaviour, add a raw_json=1 parameter to your request."
This commit is contained in:
Louis Vallat 2019-08-06 11:22:38 +02:00
parent f2259f82d7
commit b0e6f33b87
5 changed files with 21 additions and 15 deletions

View File

@ -1,4 +1,4 @@
#Mon, 15 Jul 2019 21:54:15 +0200
#Tue, 06 Aug 2019 11:12:49 +0200
C\:\\Users\\louis\\Documents\\GitHub\\twitter_techsupportgore_bot\\reddit_reposter_bot=

View File

@ -67,8 +67,8 @@ public final class ConfigFileReader {
/**
* Read the config file.
*
* @throws TwitterTechSupportGoreBot.exceptions.NotSufficientRights
* @throws TwitterTechSupportGoreBot.exceptions.NoSuchFile
* @throws RedditReposterBot.exceptions.NoSuchFile
* @throws RedditReposterBot.exceptions.NotSufficientRights
*/
public void readConfigFile() throws NoSuchFile, NotSufficientRights {
if (!new File(CONFIGFILE).exists()) {
@ -93,8 +93,7 @@ public final class ConfigFileReader {
*
* @param id the property id.
* @return the properties.
*
* @throws TwitterTechSupportGoreBot.exceptions.NoSuchProperty
* @throws RedditReposterBot.exceptions.NoSuchProperty
*/
public String getProperties(String id) throws NoSuchProperty {
if (!this.prop.containsKey(id)) {

View File

@ -129,12 +129,12 @@ public class Hypervisor {
* @return the instance.
*
* @throws java.lang.ClassNotFoundException
* @throws TwitterTechSupportGoreBot.exceptions.NotSufficientRights
* @throws RedditReposterBot.exceptions.NotSufficientRights
* @throws java.sql.SQLException
* @throws java.io.IOException
* @throws TwitterTechSupportGoreBot.exceptions.NoSuchFile
* @throws TwitterTechSupportGoreBot.exceptions.NoSuchProperty
* @throws TwitterTechSupportGoreBot.exceptions.NoSuchOrder
* @throws RedditReposterBot.exceptions.NoSuchFile
* @throws RedditReposterBot.exceptions.NoSuchProperty
* @throws RedditReposterBot.exceptions.NoSuchOrder
*/
public static Hypervisor getSingleton()
throws ClassNotFoundException, NotSufficientRights,
@ -399,8 +399,7 @@ public class Hypervisor {
* Set working directory.
*
* @param tempDir the path to the working directory.
*
* @throws TwitterTechSupportGoreBot.exceptions.NotSufficientRights
* @throws RedditReposterBot.exceptions.NotSufficientRights
*/
public void setWorkDir(String tempDir) throws NotSufficientRights {
this.workingDirectory = tempDir;

View File

@ -34,7 +34,7 @@ public class RedditReposterBot {
/**
* Version of the application.
*/
private static final String VERSION = "0.9.1";
private static final String VERSION = "1.0.1";
/**
* Launch the Hypervisor.

View File

@ -157,9 +157,17 @@ public final class RedditExtractor {
String title = childData.get("title") != null
? childData.get("title").toString()
: this.sub.getName();
title = title.replace("\"", "").replace("\\", "\"");
title = title
.replace("\"", "")
.replace("\\", "\"")
.replace("&lt;", "<")
.replace("&gt;", ">")
.replace("&amp;", "&");
String author = childData.get("author") != null
? childData.get("author").toString() : "anonymous";
? childData.get("author").toString()
.replace("&lt;", "<")
.replace("&gt;", ">")
.replace("&amp;", "&") : "anonymous";
author = author.replace("\"", "");
boolean quarantine = childData.get("quarantine")
.getAsBoolean();
@ -178,7 +186,7 @@ public final class RedditExtractor {
.get(0).toString()).getAsJsonObject();
JsonObject urlSrc = new JsonParser().parse(source
.get("source").toString()).getAsJsonObject();
url = urlSrc.get("url").toString().replace("amp;", "")
url = urlSrc.get("url").toString().replace("&amp;", "&")
.replace("\"", "");
} catch (NullPointerException n) {
url = childData.get("url").getAsString();