From 73dbd6c0d85288e2f8bace1e25284fc77929876f Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Wed, 17 May 2017 17:38:14 -0700 Subject: [PATCH] Implemented Pinboard.in integration. --- .idea/modules/mobibot.iml | 166 ++++++++++-------- build.gradle | 2 +- kobalt/src/Build.kt | 3 +- mobibot.ipr | 42 ++++- properties/log4j.properties | 3 - properties/mobibot.properties | 6 +- .../net/thauvin/erik/mobibot/ReleaseInfo.java | 4 +- .../net/thauvin/erik/mobibot/EntryLink.java | 4 +- .../net/thauvin/erik/mobibot/Mobibot.java | 67 +++---- .../{DeliciousPoster.java => Pinboard.java} | 70 +++++--- .../java/net/thauvin/erik/mobibot/Utils.java | 2 +- version.properties | 2 +- 12 files changed, 214 insertions(+), 157 deletions(-) rename src/main/java/net/thauvin/erik/mobibot/{DeliciousPoster.java => Pinboard.java} (67%) diff --git a/.idea/modules/mobibot.iml b/.idea/modules/mobibot.iml index 15c67f6..0856423 100644 --- a/.idea/modules/mobibot.iml +++ b/.idea/modules/mobibot.iml @@ -1,5 +1,5 @@ - + @@ -18,62 +18,40 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -83,25 +61,59 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 6572b46..20ce201 100644 --- a/build.gradle +++ b/build.gradle @@ -70,7 +70,7 @@ dependencies { compile 'net.objecthunter:exp4j:0.4.8' compile 'org.twitter4j:twitter4j-core:4.0.6' - compile 'net.sf.delicious-java:delicious:1.14' + compile 'net.thauvin.erik:pinboard-poster:0.9.1' compile files('lib/owm-japis-2.5.0.5.jar') diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index 7980dba..3362210 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -14,6 +14,7 @@ import java.io.FileInputStream import java.util.* val bs = buildScript { + repos(localMaven()) } val mainClassName = "net.thauvin.erik.mobibot.Mobibot" @@ -72,7 +73,7 @@ val p = project { compile("net.objecthunter:exp4j:0.4.8") compile("org.twitter4j:twitter4j-core:4.0.6") - compile("net.sf.delicious-java:delicious:1.14") + compile("net.thauvin.erik:pinboard-poster:0.9.1") compile(file("lib/owm-japis-2.5.0.5.jar")) diff --git a/mobibot.ipr b/mobibot.ipr index a59e8d0..df5896c 100644 --- a/mobibot.ipr +++ b/mobibot.ipr @@ -357,6 +357,24 @@ + + + + + + + + + + + + + + + + + + @@ -420,13 +438,13 @@ - + - + - + @@ -447,6 +465,24 @@ + + + + + + + + + + + + + + + + + + diff --git a/properties/log4j.properties b/properties/log4j.properties index 201ab08..78b2948 100644 --- a/properties/log4j.properties +++ b/properties/log4j.properties @@ -11,8 +11,5 @@ log4j.appender.stderr.target=System.err log4j.logger.org.apache.commons.httpclient=FATAL log4j.logger.httpclient.wire=FATAL -# Print only messages of priority FATAL or above in the package net.sf.jweather -log4j.category.net.sf.jweather=FATAL - # Print only messages of priority FATAL or above in the package net.thauvin.erik.mobibot log4j.category.net.thauvin.erik.mobibot=FATAL diff --git a/properties/mobibot.properties b/properties/mobibot.properties index 9c007bc..130b9f1 100644 --- a/properties/mobibot.properties +++ b/properties/mobibot.properties @@ -21,11 +21,9 @@ tell-max-days=5 tell-max-size=50 # -# Credentials for: http://del.icio.us/ +# Credentials for: http://pinboard.in/ # -#delicious-user= -#delicious-pwd= -#declicious-api-endpoint=https://api.pinboard.in/v1/ +#pinboard-api-token=user\:TOKEN # diff --git a/src/generated/java/net/thauvin/erik/mobibot/ReleaseInfo.java b/src/generated/java/net/thauvin/erik/mobibot/ReleaseInfo.java index 52cb9a2..7115878 100644 --- a/src/generated/java/net/thauvin/erik/mobibot/ReleaseInfo.java +++ b/src/generated/java/net/thauvin/erik/mobibot/ReleaseInfo.java @@ -18,12 +18,12 @@ public final class ReleaseInfo { public final static String PROJECT = "mobibot"; public final static LocalDateTime BUILDDATE = - LocalDateTime.ofInstant(Instant.ofEpochMilli(1494906988487L), ZoneId.systemDefault()); + LocalDateTime.ofInstant(Instant.ofEpochMilli(1495067438992L), ZoneId.systemDefault()); public final static int MAJOR = 0; public final static int MINOR = 7; public final static int PATCH = 1; public final static String PRERELEASE = "beta"; - public final static String BUILDMETA = "020"; + public final static String BUILDMETA = "021"; /** * The full version string. diff --git a/src/main/java/net/thauvin/erik/mobibot/EntryLink.java b/src/main/java/net/thauvin/erik/mobibot/EntryLink.java index 555c2ae..d8bf472 100644 --- a/src/main/java/net/thauvin/erik/mobibot/EntryLink.java +++ b/src/main/java/net/thauvin/erik/mobibot/EntryLink.java @@ -206,11 +206,11 @@ public class EntryLink implements Serializable { } /** - * Returns the tags formatted for del.icio.us. + * Returns the tags formatted for pinboard.in * * @return The tags as a comma-delimited string. */ - public final String getDeliciousTags() { + public final String getPinboardTags() { final StringBuilder tags = new StringBuilder(nick); for (final Object tag : this.tags) { diff --git a/src/main/java/net/thauvin/erik/mobibot/Mobibot.java b/src/main/java/net/thauvin/erik/mobibot/Mobibot.java index b844841..7227054 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Mobibot.java +++ b/src/main/java/net/thauvin/erik/mobibot/Mobibot.java @@ -32,7 +32,6 @@ package net.thauvin.erik.mobibot; import com.rometools.rome.io.FeedException; -import del.icio.us.DeliciousConstants; import net.thauvin.erik.mobibot.modules.*; import net.thauvin.erik.semver.Version; import org.apache.commons.cli.*; @@ -167,22 +166,16 @@ public class Mobibot extends PircBot { // The default tags/categories. private String defaultTags = ""; - - // The del.icio.us posts handler. - private DeliciousPoster delicious = null; - // The feed URL. private String feedURL = ""; - // The ident message. private String identMsg = ""; - // The ident nick. private String identNick = ""; - // The NickServ ident password. private String identPwd = ""; - + // The pinboard posts handler. + private Pinboard pinboard = null; // Today's date. private String today = Utils.today(); @@ -356,10 +349,8 @@ public class Mobibot extends PircBot { final String identPwd = p.getProperty("ident", ""); final String tags = p.getProperty("tags", ""); - // Get the del.icio.us properties - final String dname = p.getProperty("delicious-user"); - final String dpwd = p.getProperty("delicious-pwd"); - final String dapi = p.getProperty("declicious-api-endpoint", DeliciousConstants.API_ENDPOINT); + // Get the pinboard properties + final String pinApiToken = p.getProperty("pinboard-api-token"); // Create the bot final Mobibot bot = new Mobibot(server, port, nickname, channel, logsDir); @@ -380,8 +371,8 @@ public class Mobibot extends PircBot { bot.setFeedURL(feedURL); bot.setBacklogsUrl(backlogsURL); - // Set the del.icio.us authentication - bot.setDeliciousAuth(dapi, dname, dpwd); + // Set the pinboard authentication + bot.setPinboardAuth(pinApiToken); // Load the modules properties MODULES.stream().filter(AbstractModule::hasProperties).forEach( @@ -1044,8 +1035,8 @@ public class Mobibot extends PircBot { final EntryLink entry = entries.get(index); send(channel, Utils.buildLink(index, entry)); - if (delicious != null) { - delicious.addPost(entry); + if (pinboard != null) { + pinboard.addPost(entry); } saveEntries(isBackup); @@ -1152,8 +1143,8 @@ public class Mobibot extends PircBot { final EntryLink entry = entries.get(index); if (entry.getLogin().equals(login) || isOp(sender)) { - if (delicious != null) { - delicious.deletePost(entry); + if (pinboard != null) { + pinboard.deletePost(entry); } entries.remove(index); @@ -1169,8 +1160,8 @@ public class Mobibot extends PircBot { final EntryLink entry = entries.get(index); entry.setTitle(cmd.substring(1).trim()); - if (delicious != null) { - delicious.updatePost(entry.getLink(), entry); + if (pinboard != null) { + pinboard.updatePost(entry.getLink(), entry); } send(channel, Utils.buildLink(index, entry)); @@ -1189,8 +1180,8 @@ public class Mobibot extends PircBot { entry.setLink(link); - if (delicious != null) { - delicious.updatePost(oldLink, entry); + if (pinboard != null) { + pinboard.updatePost(oldLink, entry); } send(channel, Utils.buildLink(index, entry)); @@ -1239,8 +1230,8 @@ public class Mobibot extends PircBot { if (entry.getLogin().equals(login) || isOp(sender)) { entry.setTags(cmd); - if (delicious != null) { - delicious.updatePost(entry.getLink(), entry); + if (pinboard != null) { + pinboard.updatePost(entry.getLink(), entry); } send(channel, Utils.buildTags(index, entry)); @@ -1439,7 +1430,7 @@ public class Mobibot extends PircBot { private void recapResponse(final String sender, final boolean isPrivate) { if (this.recap.size() > 0) { for (final String recap : this.recap) { - send(sender, recap, isPrivate); + send(sender, recap, isPrivate); } } else { send(sender, "Sorry, nothing to recap.", true); @@ -1491,19 +1482,6 @@ public class Mobibot extends PircBot { send(sender, message, false); } - /** - * Sets the del.icio.us authentication. - * - * @param apiEndPoint The API end point. - * @param username The del.icio.us user name. - * @param password The del.icio.us password. - */ - private void setDeliciousAuth(final String apiEndPoint, final String username, final String password) { - if (Utils.isValidString(username) && Utils.isValidString(password)) { - delicious = new DeliciousPoster(apiEndPoint, username, password, ircServer); - } - } - /** * Sets the feed URL. * @@ -1541,6 +1519,17 @@ public class Mobibot extends PircBot { } } + /** + * Sets the pinboard authentication. + * + * @param apiToken The API token + */ + private void setPinboardAuth(final String apiToken) { + if (Utils.isValidString(apiToken)) { + pinboard = new Pinboard(this, apiToken, ircServer); + } + } + /** * Sets the default tags/categories. * diff --git a/src/main/java/net/thauvin/erik/mobibot/DeliciousPoster.java b/src/main/java/net/thauvin/erik/mobibot/Pinboard.java similarity index 67% rename from src/main/java/net/thauvin/erik/mobibot/DeliciousPoster.java rename to src/main/java/net/thauvin/erik/mobibot/Pinboard.java index 2d14f71..ff1638d 100644 --- a/src/main/java/net/thauvin/erik/mobibot/DeliciousPoster.java +++ b/src/main/java/net/thauvin/erik/mobibot/Pinboard.java @@ -1,5 +1,5 @@ /* - * DeliciousPoster.java + * Pinboard.java * * Copyright (c) 2004-2017, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. @@ -31,32 +31,46 @@ */ package net.thauvin.erik.mobibot; -import del.icio.us.Delicious; +import net.thauvin.erik.pinboard.PinboardPoster; import javax.swing.*; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Date; +import java.util.logging.ConsoleHandler; +import java.util.logging.Level; +import java.util.logging.Logger; /** - * The class to handle posts to del.icio.us. + * The class to handle posts to pinbard.in. * * @author Erik C. Thauvin - * @created Mar 5, 2005 + * @created 2017-05-17 * @since 1.0 */ -class DeliciousPoster { - private final Delicious delicious; +class Pinboard { private final String ircServer; + private final PinboardPoster pinboard; /** - * Creates a new {@link DeliciousPoster} instance. + * Creates a new {@link Pinboard} instance. * - * @param apiEndPoint The API end point. - * @param username The del.icio.us user name. - * @param password The del.icio.us password. + * @param bot The bot's instance. + * @param apiToken The API end point. * @param ircServer The IRC server. */ - public DeliciousPoster(final String apiEndPoint, final String username, final String password, final String ircServer) { - delicious = new Delicious(username, password, apiEndPoint); + public Pinboard(final Mobibot bot, final String apiToken, final String ircServer) { + pinboard = new PinboardPoster(apiToken); this.ircServer = ircServer; + + if (bot.getLogger().isDebugEnabled()) { + final ConsoleHandler consoleHandler = new ConsoleHandler(); + consoleHandler.setLevel(Level.FINE); + final Logger logger = pinboard.getLogger(); + logger.addHandler(consoleHandler); + logger.setLevel(Level.FINE); + } } /** @@ -69,11 +83,11 @@ class DeliciousPoster { @Override protected Boolean doInBackground() throws Exception { - return delicious.addPost(entry.getLink(), + return pinboard.addPin(entry.getLink(), entry.getTitle(), postedBy(entry), - entry.getDeliciousTags(), - entry.getDate()); + entry.getPinboardTags(), + formatDate(entry.getDate())); } }; @@ -92,13 +106,23 @@ class DeliciousPoster { @Override protected Boolean doInBackground() throws Exception { - return delicious.deletePost(link); + return pinboard.deletePin(link); } }; worker.execute(); } + /** + * Format a date to a UTC timestamp. + * + * @param date The date. + * @return The date in {@link DateTimeFormatter#ISO_INSTANT} format. + */ + private String formatDate(final Date date) { + return ZonedDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()).format(DateTimeFormatter.ISO_INSTANT); + } + /** * Returns he del.icio.us extended attribution line. * @@ -121,19 +145,19 @@ class DeliciousPoster { protected Boolean doInBackground() throws Exception { if (!oldUrl.equals(entry.getLink())) { - delicious.deletePost(oldUrl); + pinboard.deletePin(oldUrl); - return delicious.addPost(entry.getLink(), + return pinboard.addPin(entry.getLink(), entry.getTitle(), postedBy(entry), - entry.getDeliciousTags(), - entry.getDate()); + entry.getPinboardTags(), + formatDate(entry.getDate())); } else { - return delicious.addPost(entry.getLink(), + return pinboard.addPin(entry.getLink(), entry.getTitle(), postedBy(entry), - entry.getDeliciousTags(), - entry.getDate(), + entry.getPinboardTags(), + formatDate(entry.getDate()), true, true); } diff --git a/src/main/java/net/thauvin/erik/mobibot/Utils.java b/src/main/java/net/thauvin/erik/mobibot/Utils.java index a20f18c..2610f20 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Utils.java +++ b/src/main/java/net/thauvin/erik/mobibot/Utils.java @@ -140,7 +140,7 @@ final public class Utils { * @return The entry's tags. */ static String buildTags(final int entryIndex, final EntryLink entry) { - return (Commands.LINK_CMD + (entryIndex + 1) + "T: " + entry.getDeliciousTags().replaceAll(",", ", ")); + return (Commands.LINK_CMD + (entryIndex + 1) + "T: " + entry.getPinboardTags().replaceAll(",", ", ")); } /** diff --git a/version.properties b/version.properties index de1e7c5..f372b5b 100644 --- a/version.properties +++ b/version.properties @@ -5,4 +5,4 @@ version.major=0 version.minor=7 version.patch=1 version.prerelease=beta -version.buildmeta=020 \ No newline at end of file +version.buildmeta=021 \ No newline at end of file