/** * First param is the slack api key * Second param is a boolean if you want to use mock data * * @param args https://api.slack.com/docs/oauth-test-tokens * @throws IOException */ public static void main(String[] args) throws IOException { if (args.length == 0) { throw new IllegalStateException("You need to pass a Slack token as the first arg. See https://api.slack.com/web"); } boolean runLocally = Boolean.parseBoolean(args[1]); if (runLocally) { System.out.println("Running using local mock data"); } String slackToken = args[0]; Scraper scraper = new Scraper.Factory().newInstance(slackToken, runLocally); LocalDateTime start = LocalDateTime.now(); LocalDateTime end = LocalDateTime.now().minusDays(6); List<ChannelHistory.Message> messages = scraper.scrape(start, end).collect(Collectors.toList()); messages.forEach(System.out::println); System.out.println("Total was: " + messages.size()); }
@NotNull private Scraper newLiveServiceInstance(String slackToken) { Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://slack.com/api/") .addConverterFactory(GsonConverterFactory.create()) .build(); SlackWebService slackWebService = retrofit.create(SlackWebService.class); SlackHistoryFetcher slackHistoryFetcher = SlackHistoryFetcher.from(slackWebService, slackToken); return new Scraper(slackHistoryFetcher); }
/** * @param args https://api.slack.com/docs/oauth-test-tokens * @throws IOException */ public static void main(String[] args) throws IOException { if (args.length == 0) { throw new IllegalStateException("You need to pass a Slack token as the first arg. See https://api.slack.com/web"); } String slackToken = args[0]; Scraper scraper = new Scraper.Factory().newInstance(slackToken); ArticleEditor articleEditor = new ArticleEditor.Factory().newInstance(); LocalDateTime start = LocalDateTime.now(); LocalDateTime end = LocalDateTime.now().minusDays(6); Stream<ChannelHistory.Message> messageStream = scraper.scrape(start, end); Stream<Article> articleStream = articleEditor.generateArticle(messageStream); articleStream.forEach(System.out::println); }
@NotNull private Scraper newMockServiceInsstance(String slackToken) { SlackWebService slackWebService = new MockSlackWebService(); SlackHistoryFetcher slackHistoryFetcher = SlackHistoryFetcher.from(slackWebService, slackToken); return new Scraper(slackHistoryFetcher); }
/** * @param args https://api.slack.com/docs/oauth-test-tokens * @throws IOException */ public static void main(String[] args) throws IOException { if (args.length == 0) { throw new IllegalStateException("You need to pass a Slack token as the first arg. See https://api.slack.com/web"); } String slackToken = args[0]; Scraper scraper = new Scraper.Factory().newInstance(slackToken); HtmlGenerator htmlGenerator = new HtmlGenerator.Factory().newInstance(); ArticleEditor articleEditor = new ArticleEditor.Factory().newInstance(); LocalDateTime start = LocalDateTime.now(); LocalDateTime end = LocalDateTime.now().minusDays(6); Stream<ChannelHistory.Message> messageStream = scraper.scrape(start, end); Stream<Article> articleStream = articleEditor.generateArticle(messageStream); String html = htmlGenerator.generate(articleStream); System.out.println(html); Files.write(Paths.get("./build/enews-debug.html"), html.getBytes()); } }
@Override public Response handleRequest(Request input, Context context) { String slackToken = input.getSlackToken(); String mailChimpApiKey = input.getMailChimpApiKey(); Scraper scraper = new Scraper.Factory().newInstance(slackToken); HtmlGenerator htmlGenerator = new HtmlGenerator.Factory().newInstance(); NewsletterPublisher newsletterPublisher = new NewsletterPublisher.Factory().newInstance(mailChimpApiKey); ArticleEditor articleEditor = new ArticleEditor.Factory().newInstance(); LocalDateTime start = LocalDateTime.now(); LocalDateTime end = LocalDateTime.now().minusDays(6); Stream<ChannelHistory.Message> messageStream = scraper.scrape(start, end); Stream<Article> articleStream = articleEditor.generateArticle(messageStream); String html = htmlGenerator.generate(articleStream); LocalDateTime atLocalDateTime = LocalDateTime.now().plusDays(1).plusHours(1); newsletterPublisher.publish(html, atLocalDateTime); // Time warp campaigns have to be 24 hours in the future // The scheduling is completely hidden here and is a TODO // - because if someone set up a cron job they cannot *fully* control the time right now JsonObject jsonObject = new JsonObject(); jsonObject.add("message", new JsonPrimitive("complete!")); return new Response(jsonObject.getAsJsonObject().toString()); } }
/** * @param args https://api.slack.com/docs/oauth-test-tokens, https://us5.admin.mailchimp.com/account/api/ * @throws IOException */ public static void main(String[] args) throws IOException { if (args.length == 0 || args.length < 2) { throw new IllegalStateException("You need to pass a Slack token as the first arg and MailChimp API token as the second."); } String slackToken = args[0]; String mailChimpToken = args[1]; Scraper scraper = new Scraper.Factory().newInstance(slackToken); HtmlGenerator htmlGenerator = new HtmlGenerator.Factory().newInstance(); ArticleEditor articleEditor = new ArticleEditor.Factory().newInstance(); NewsletterPublisher newsletterPublisher = new NewsletterPublisher.Factory().newInstance(mailChimpToken); LocalDateTime start = LocalDateTime.now(); LocalDateTime end = LocalDateTime.now().minusDays(6); Stream<ChannelHistory.Message> messageStream = scraper.scrape(start, end); Stream<Article> articleStream = articleEditor.generateArticle(messageStream); String html = htmlGenerator.generate(articleStream); LocalDateTime atLocalDateTime = LocalDateTime.now().plusDays(1).plusHours(1); newsletterPublisher.publish(html, atLocalDateTime); // Time warp campaigns have to be 24 hours in the future // The scheduling is completely hidden here and is a TODO // - because if someone set up a cron job they cannot *fully* control the time right now } }