minor update, more code optimization
This commit is contained in:
parent
930306a581
commit
1ce343d523
@ -1,5 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
*** GENERATED FROM project.xml - DO NOT EDIT ***
|
||||
*** EDIT ../build.xml INSTEAD ***
|
||||
@ -21,8 +20,6 @@ is divided into following sections:
|
||||
|
||||
-->
|
||||
<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="twitter_techsupportgore_bot-impl">
|
||||
<property name="kotlin.lib" value="C:\Users\louis\AppData\Roaming\NetBeans\8.2\kotlinc\lib"/>
|
||||
<typedef classpath="${kotlin.lib}/kotlin-ant.jar" resource="org/jetbrains/kotlin/ant/antlib.xml"/>
|
||||
<fail message="Please build using Ant 1.8.0 or higher.">
|
||||
<condition>
|
||||
<not>
|
||||
@ -276,7 +273,6 @@ is divided into following sections:
|
||||
<include name="*"/>
|
||||
</dirset>
|
||||
</src>
|
||||
<withKotlin/>
|
||||
<classpath>
|
||||
<path path="@{classpath}"/>
|
||||
</classpath>
|
||||
|
@ -32,7 +32,7 @@ public final class ConfigFileReader {
|
||||
/**
|
||||
* The config file name.
|
||||
*/
|
||||
private static final String CONFIGFILE = "settings.conf";
|
||||
private static String CONFIGFILE = "settings.conf";
|
||||
|
||||
/**
|
||||
* The properties object.
|
||||
@ -49,6 +49,19 @@ public final class ConfigFileReader {
|
||||
readConfigFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new config file reader that automatically reads the config file,
|
||||
* precising the config file name.
|
||||
*
|
||||
* @param conf the cnfig file path name.
|
||||
* @throws NoSuchFile
|
||||
* @throws NotSufficientRights
|
||||
*/
|
||||
public ConfigFileReader(String conf) throws NoSuchFile, NotSufficientRights {
|
||||
CONFIGFILE = conf;
|
||||
readConfigFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the config file.
|
||||
*
|
||||
|
@ -16,11 +16,7 @@
|
||||
*/
|
||||
package TwitterTechSupportGoreBot;
|
||||
|
||||
import TwitterTechSupportGoreBot.redditHandler.RedditPostImage;
|
||||
import TwitterTechSupportGoreBot.redditHandler.RedditPost;
|
||||
import TwitterTechSupportGoreBot.redditHandler.RedditPostText;
|
||||
import TwitterTechSupportGoreBot.redditHandler.RedditPostLink;
|
||||
import TwitterTechSupportGoreBot.redditHandler.RedditPostVideo;
|
||||
import TwitterTechSupportGoreBot.socialMediaHandler.*;
|
||||
import TwitterTechSupportGoreBot.redditHandler.*;
|
||||
import TwitterTechSupportGoreBot.exceptions.*;
|
||||
@ -31,7 +27,6 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
@ -248,7 +243,7 @@ public class Hypervisor {
|
||||
ajout.setString(10, current.getPermalink());
|
||||
ajout.setBoolean(11, current.isSpoiler());
|
||||
ajout.setString(12, current.getUrl());
|
||||
ajout.setBoolean(13, false);
|
||||
ajout.setBoolean(13, true);
|
||||
ajout.execute();
|
||||
|
||||
}
|
||||
@ -273,49 +268,6 @@ public class Hypervisor {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a post is marked as shared in database.
|
||||
*
|
||||
* @param postId the post id
|
||||
* @return if the post is shared in the database
|
||||
*
|
||||
* @throws SQLException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
private boolean isShared(String postId)
|
||||
throws SQLException, ClassNotFoundException {
|
||||
PreparedStatement recherche = this.connexion.prepareStatement(
|
||||
"SELECT shared FROM " + this.tableName + " "
|
||||
+ "WHERE postId = '" + postId + "'");
|
||||
try (ResultSet resultats = recherche.executeQuery()) {
|
||||
if (resultats.next()) {
|
||||
return resultats.getBoolean("shared");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a post as shared onsocial networks.
|
||||
*
|
||||
* @param postId the post id
|
||||
*
|
||||
* @throws SQLException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
private void setPostAsShared(RedditPost r)
|
||||
throws SQLException, ClassNotFoundException {
|
||||
System.out.println("[+] Post \""
|
||||
+ r.getTitle()
|
||||
+ "\" is about to be shared.");
|
||||
PreparedStatement update = this.connexion.prepareStatement(
|
||||
"UPDATE " + this.tableName + " "
|
||||
+ "SET shared=? "
|
||||
+ "WHERE postId = '" + r.getPostId() + "';");
|
||||
update.setBoolean(1, true);
|
||||
update.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create our working table if it doesn't exists yet.
|
||||
*
|
||||
@ -355,13 +307,11 @@ public class Hypervisor {
|
||||
*/
|
||||
private void computeRedditPost(RedditPost r)
|
||||
throws SQLException, ClassNotFoundException {
|
||||
if (!isShared(r.getPostId()) && !r.isQuarantine()) {
|
||||
if (!isInDatabase(r.getPostId()) && !r.isQuarantine() && r.hasMediaUrl()) {
|
||||
System.out.println(
|
||||
"[*] Computing the post \"" + r.getTitle() + "\"");
|
||||
addRedditPostToDatabase(r);
|
||||
if (r.hasMediaUrl()) {
|
||||
String fileName = saveImage(r.getUrl());
|
||||
setPostAsShared(r);
|
||||
socialMedias.forEach((s) -> {
|
||||
long postRef = s.postImage(
|
||||
formatPost(r.getTitle()), fileName);
|
||||
@ -378,7 +328,6 @@ public class Hypervisor {
|
||||
+ "\" has been shared successfully.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a given text for being posted on the different social networks.
|
||||
|
@ -25,8 +25,10 @@ public class RedditPostImage extends RedditPost {
|
||||
|
||||
public RedditPostImage(String id, String title, boolean quarantine,
|
||||
double score, String postHint, boolean crosspostable,
|
||||
boolean over18, String author, String permalink, boolean spoiler, String url) {
|
||||
super(id, title, quarantine, score, postHint, crosspostable, over18, author, permalink, spoiler, url);
|
||||
boolean over18, String author, String permalink,
|
||||
boolean spoiler, String url) {
|
||||
super(id, title, quarantine, score, postHint,
|
||||
crosspostable, over18, author, permalink, spoiler, url);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,8 +25,10 @@ public class RedditPostLink extends RedditPost {
|
||||
|
||||
public RedditPostLink(String id, String title, boolean quarantine,
|
||||
double score, String postHint, boolean crosspostable,
|
||||
boolean over18, String author, String permalink, boolean spoiler, String url) {
|
||||
super(id, title, quarantine, score, postHint, crosspostable, over18, author, permalink, spoiler, url);
|
||||
boolean over18, String author, String permalink,
|
||||
boolean spoiler, String url) {
|
||||
super(id, title, quarantine, score, postHint,
|
||||
crosspostable, over18, author, permalink, spoiler, url);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,8 +25,10 @@ public class RedditPostText extends RedditPost {
|
||||
|
||||
public RedditPostText(String id, String title, boolean quarantine,
|
||||
double score, String postHint, boolean crosspostable,
|
||||
boolean over18, String author, String permalink, boolean spoiler, String url) {
|
||||
super(id, title, quarantine, score, postHint, crosspostable, over18, author, permalink, spoiler, url);
|
||||
boolean over18, String author, String permalink,
|
||||
boolean spoiler, String url) {
|
||||
super(id, title, quarantine, score, postHint,
|
||||
crosspostable, over18, author, permalink, spoiler, url);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,8 +25,10 @@ public class RedditPostVideo extends RedditPost {
|
||||
|
||||
public RedditPostVideo(String id, String title, boolean quarantine,
|
||||
double score, String postHint, boolean crosspostable,
|
||||
boolean over18, String author, String permalink, boolean spoiler, String url) {
|
||||
super(id, title, quarantine, score, postHint, crosspostable, over18, author, permalink, spoiler, url);
|
||||
boolean over18, String author, String permalink,
|
||||
boolean spoiler, String url) {
|
||||
super(id, title, quarantine, score, postHint,
|
||||
crosspostable, over18, author, permalink, spoiler, url);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user