use of twitter4j.conf.ConfigurationBuilder in project ud381 by udacity.
the class TweetSpout method open.
@Override
public void open(Map map, TopologyContext topologyContext, SpoutOutputCollector spoutOutputCollector) {
// create the buffer to block tweets
queue = new LinkedBlockingQueue<String>(1000);
SentimentAnalyzer.init();
// save the output collector for emitting tuples
collector = spoutOutputCollector;
// build the config with credentials for twitter 4j
ConfigurationBuilder config = new ConfigurationBuilder().setOAuthConsumerKey(custkey).setOAuthConsumerSecret(custsecret).setOAuthAccessToken(accesstoken).setOAuthAccessTokenSecret(accesssecret);
// create the twitter stream factory with the config
TwitterStreamFactory fact = new TwitterStreamFactory(config.build());
// get an instance of twitter stream
twitterStream = fact.getInstance();
// See
FilterQuery tweetFilterQuery = new FilterQuery();
tweetFilterQuery.locations(new double[][] { new double[] { -124.848974, 24.396308 }, new double[] { -66.885444, 49.384358 } });
tweetFilterQuery.language(new String[] { "en" });
// provide the handler for twitter stream
twitterStream.addListener(new TweetListener());
twitterStream.filter(tweetFilterQuery);
// start the sampling of tweets
twitterStream.sample();
}
use of twitter4j.conf.ConfigurationBuilder in project Ardent by adamint.
the class Ardent method main.
public static void main(String[] args) throws Exception {
new DefaultAudioPlayerManager();
Logger root1 = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
root1.setLevel(Level.OFF);
for (String s : args) {
if (s.contains("premium"))
premiumBot = true;
}
if (!testingBot) {
spotifyApi = Api.builder().clientId("471f277107704e3b89d489284b65c6c6").clientSecret(IOUtils.toString(new FileInputStream(new File("/root/Ardent/spotifysecret.key")))).redirectURI("https://ardentbot.tk").build();
SpotifyTokenRefresh spotifyTokenRefresh = new SpotifyTokenRefresh();
spotifyTokenRefresh.run();
globalExecutorService.scheduleAtFixedRate(spotifyTokenRefresh, 10, 10, TimeUnit.MINUTES);
} else
spotifyApi = Api.DEFAULT_API;
if (!testingBot) {
dbPassword = IOUtils.toString(new FileReader(new File("/root/Ardent/v2password.key")));
botsDiscordPwToken = IOUtils.toString(new FileReader(new File("/root/Ardent/botsdiscordpw.key")));
discordBotsOrgToken = IOUtils.toString(new FileReader(new File("/root/Ardent/discordbotsorg.key")));
} else {
try {
dbPassword = IOUtils.toString(new FileReader(new File("C:\\Users\\AMR\\Desktop\\Ardent\\v2password.key")));
discordBotsOrgToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjE2OTkwNDMyNDk4MDI0NDQ4MCIsImlhdCI6MTQ5MzMyNDM1OX0.LQ97UtslzaM5Qo__gkihOX5afaZA5z3TjMjSovMzDTI";
} catch (Exception ex) {
dbPassword = IOUtils.toString(new FileReader(new File("/root/Ardent/.key")));
}
}
Database.setup();
Cursor<HashMap> apiKeys = r.db("data").table("api_keys").run(connection);
apiKeys.forEach((outside) -> {
outside.forEach((uId, uValue) -> {
String id = (String) uId;
String value = (String) uValue;
if (id.equalsIgnoreCase("mashape"))
mashapeKey = value;
else if (id.equalsIgnoreCase("google"))
GOOGLE_API_KEY = value;
else if (id.equalsIgnoreCase("node0"))
node0Url = value;
else if (id.equalsIgnoreCase("node1"))
node1Url = value;
else if (id.equalsIgnoreCase("cleverbotuser"))
cleverbotUser = value;
else if (id.equalsIgnoreCase("cleverbotkey"))
cleverbotKey = value;
else if (id.equalsIgnoreCase("premiumbottoken"))
premiumBotToken = value;
else if (id.equalsIgnoreCase("testbottoken"))
testBotToken = value;
else if (id.equalsIgnoreCase("googlesecret"))
clientSecret = value;
else if (id.equalsIgnoreCase("twitch"))
twitch = value;
});
});
ShardManager.register(shardCount);
BotlistUpdater updater = new BotlistUpdater();
globalExecutorService.scheduleAtFixedRate(updater, 0, 1, TimeUnit.HOURS);
StuckVoiceConnection playerStuckDaemon = new StuckVoiceConnection();
globalExecutorService.scheduleAtFixedRate(playerStuckDaemon, 10, 10, TimeUnit.SECONDS);
UpdatePremiumMembers updatePremiumMembers = new UpdatePremiumMembers();
globalExecutorService.scheduleAtFixedRate(updatePremiumMembers, 0, 1, TimeUnit.MINUTES);
ProfileUpdater profileUpdater = new ProfileUpdater();
globalExecutorService.scheduleWithFixedDelay(profileUpdater, 1, 5, TimeUnit.MINUTES);
if (!premiumBot) {
SparkServer.setup();
/*Class currentClass = new Object() {
}.getClass().getEnclosingClass();
premiumProcess = Runtime.getRuntime().exec("java -jar " + currentClass.getProtectionDomain().getCodeSource().getLocation()
.getPath() + " -premium");*/
} else {
CheckIfPremiumGuild checkIfPremiumGuild = new CheckIfPremiumGuild();
globalExecutorService.scheduleAtFixedRate(checkIfPremiumGuild, 1, 5, TimeUnit.MINUTES);
}
GoogleSearch.setup(GOOGLE_API_KEY);
int status = Unirest.post("https://cleverbot.io/1.0/create").field("user", cleverbotUser).field("key", cleverbotKey).field("nick", "ardent").asString().getStatus();
if (status != 200)
new BotException("Unable to connect to cleverbot!");
WebsiteDaemon websiteDaemon = new WebsiteDaemon();
globalExecutorService.scheduleAtFixedRate(websiteDaemon, 5, 15, TimeUnit.SECONDS);
PermissionsDaemon permissionsDaemon = new PermissionsDaemon();
globalExecutorService.scheduleAtFixedRate(permissionsDaemon, 0, 60, TimeUnit.SECONDS);
GuildDaemon guildDaemon = new GuildDaemon();
globalExecutorService.scheduleAtFixedRate(guildDaemon, 0, 10, TimeUnit.SECONDS);
MuteDaemon muteDaemon = new MuteDaemon();
globalExecutorService.scheduleAtFixedRate(muteDaemon, 1, 5, TimeUnit.SECONDS);
RankableDaemon rankableDaemon = new RankableDaemon();
globalExecutorService.scheduleAtFixedRate(rankableDaemon, 0, 1, TimeUnit.MINUTES);
Music.checkMusicConnections();
globalExecutorService.scheduleAtFixedRate(() -> {
Shard[] shards = ShardManager.getShards();
for (int i = 0; i < shards.length; i++) {
Shard shard = shards[i];
if ((System.currentTimeMillis() - shard.getLAST_EVENT()) > 20000) {
shard.jda.getRegisteredListeners().forEach(shard.jda::removeEventListener);
int finalI = i;
globalExecutorService.schedule(() -> {
shard.jda.shutdown(false);
try {
shards[finalI] = new Shard(testingBot, finalI, shardCount);
} catch (Exception e) {
new BotException(e);
}
}, 3, TimeUnit.SECONDS);
}
}
}, 60, 15, TimeUnit.SECONDS);
if (!testingBot) {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true).setOAuthConsumerKey("Fi9IjqqsGmOXqjR5uYK8YM2Pr").setOAuthConsumerSecret(IOUtils.toString(new FileReader(new File("/root/Ardent/twitterconsumersecret.key")))).setOAuthAccessToken("818984879018954752-aCzxyML6Xp0QcRpq5sjoe8wfp0sjVDt").setOAuthAccessTokenSecret(IOUtils.toString(new FileReader(new File("/root/Ardent/twitteroauthsecret.key"))));
TwitterFactory tf = new TwitterFactory(cb.build());
twitter = tf.getInstance();
}
java.util.logging.Logger.getLogger("org.apache.http").setLevel(java.util.logging.Level.OFF);
java.util.logging.Logger.getLogger("org.apache.http.wire").setLevel(java.util.logging.Level.OFF);
java.util.logging.Logger.getLogger("org.apache.http.headers").setLevel(java.util.logging.Level.OFF);
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) org.slf4j.LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
root.setLevel(Level.OFF);
try {
transport = GoogleNetHttpTransport.newTrustedTransport();
dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
jsonFactory = JacksonFactory.getDefaultInstance();
sheetsApi = getSheetsService();
globalExecutorService.schedule(() -> {
try {
triviaSheet = sheetsApi.spreadsheets().values().get("1qm27kGVQ4BdYjvPSlF0zM64j7nkW4HXzALFNcan4fbs", "A2:C").execute();
} catch (IOException e) {
new BotException(e);
}
List<List<Object>> values = triviaSheet.getValues();
values.forEach(row -> {
String category = (String) row.get(0);
String q = (String) row.get(1);
String answerUnparsed = (String) row.get(2);
TriviaQuestion triviaQuestion = new TriviaQuestion();
triviaQuestion.setQuestion(q);
triviaQuestion.setCategory(category);
for (String answer : answerUnparsed.split("~")) {
triviaQuestion.withAnswer(answer);
}
Trivia.triviaQuestions.add(triviaQuestion);
});
}, 30, TimeUnit.SECONDS);
} catch (Exception e) {
e.printStackTrace();
}
started = true;
}
use of twitter4j.conf.ConfigurationBuilder in project asterixdb by apache.
the class TwitterUtil method getTwitterStream.
public static TwitterStream getTwitterStream(Map<String, String> configuration) {
ConfigurationBuilder cb = getAuthConfiguration(configuration);
TwitterStreamFactory factory = new TwitterStreamFactory(cb.build());
return factory.getInstance();
}
use of twitter4j.conf.ConfigurationBuilder in project asterixdb by apache.
the class TwitterUtil method getAuthConfiguration.
private static ConfigurationBuilder getAuthConfiguration(Map<String, String> configuration) {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true);
cb.setJSONStoreEnabled(true);
String oAuthConsumerKey = configuration.get(AuthenticationConstants.OAUTH_CONSUMER_KEY);
String oAuthConsumerSecret = configuration.get(AuthenticationConstants.OAUTH_CONSUMER_SECRET);
String oAuthAccessToken = configuration.get(AuthenticationConstants.OAUTH_ACCESS_TOKEN);
String oAuthAccessTokenSecret = configuration.get(AuthenticationConstants.OAUTH_ACCESS_TOKEN_SECRET);
cb.setOAuthConsumerKey(oAuthConsumerKey);
cb.setOAuthConsumerSecret(oAuthConsumerSecret);
cb.setOAuthAccessToken(oAuthAccessToken);
cb.setOAuthAccessTokenSecret(oAuthAccessTokenSecret);
configureProxy(cb, configuration);
return cb;
}
use of twitter4j.conf.ConfigurationBuilder in project asterixdb by apache.
the class TwitterUtil method getTwitterService.
public static Twitter getTwitterService(Map<String, String> configuration) {
ConfigurationBuilder cb = getAuthConfiguration(configuration);
TwitterFactory tf = null;
try {
tf = new TwitterFactory(cb.build());
} catch (Exception e) {
if (LOGGER.isLoggable(Level.WARNING)) {
StringBuilder builder = new StringBuilder();
builder.append("Twitter Adapter requires the following config parameters\n");
builder.append(AuthenticationConstants.OAUTH_CONSUMER_KEY + "\n");
builder.append(AuthenticationConstants.OAUTH_CONSUMER_SECRET + "\n");
builder.append(AuthenticationConstants.OAUTH_ACCESS_TOKEN + "\n");
builder.append(AuthenticationConstants.OAUTH_ACCESS_TOKEN_SECRET + "\n");
LOGGER.warning(builder.toString());
LOGGER.warning("Unable to configure Twitter adapter due to incomplete/incorrect authentication credentials");
LOGGER.warning("For details on how to obtain OAuth authentication token, visit https://dev.twitter.com/oauth" + "/overview/application-owner-access-tokens");
}
}
Twitter twitter = tf.getInstance();
return twitter;
}
Aggregations