<commit_before>require 'thor'
require 'redditsherpa/client'
require 'launchy'
require 'pry'
require 'rainbow'

module Redditsherpa
  class CLI < Thor
    include Launchy
    include Rainbow

    desc "search TOPIC", "Search for content on reddit by passing in a topic"
    def search(topic)
      response = client.search(topic)
      result = response[:data][:children]
      puts "***********************************"
      puts Rainbow("Search Results:").magenta.underline.bright
      result.each_with_index do |hash, i|
        unless i == 0
          puts Rainbow(hash[:data][:title]).green
          puts (hash[:data][:description])
          puts "_____________________________________________"
        end
      end
    end

    desc "read SUBREDDIT", "Get the top posts from a given subreddit"
    def read(subreddit)
      puts "reading subreddit..."
      response = client.get_posts(subreddit)
      posts = response[:data][:children]
      i = 1
      @array = []
      posts.take(25).each do |post|
        post = post[:data]
        post_id = post[:id]
        @array << "http://www.reddit.com/r/#{subreddit}/comments/#{post_id}/"
        puts Rainbow("#{i}. " + post[:title]).bright
        puts "#{post[:url]}"
        puts "____________________________________________________________"
        puts Rainbow("Upvotes: #{post[:ups]}").green + "|" + Rainbow("Downvotes: #{post[:downs]}").red + "| Number of Comments #{post[:num_comments]}"
        puts
        i += 1
      end

      puts "To open a page, please enter a topic number after 'open'. Example: open 12"
      puts "To open the comments for a specific topic in terminal, enter 'c' and then the topic number. Example: c 12"

      input = STDIN.gets.chomp!
      if input.include?("open")
        input = input.gsub("open ","")
        target_url = @array[input.to_i]
        puts "Opening #{target_url}..."
        Launchy.open(target_url)<commit_msg>Refactor rainbow and still WIP recursion<commit_after>require 'thor'
require 'redditsherpa/client'
require 'launchy'
require 'rainbow/ext/string'

module Redditsherpa
  class CLI < Thor
    include Launchy

    desc "search TOPIC", "Search for content on reddit by passing in a topic"
    def search(topic)
      response = client.search(topic)
      result = response[:data][:children]
      puts "***********************************"
      puts ("Search Results:").color(:magenta).underline.bright
      result.each_with_index do |hash, i|
        unless i == 0
          puts Rainbow(hash[:data][:title]).bright
          puts (hash[:data][:description])
          puts "_____________________________________________"
        end
      end
    end

    desc "read SUBREDDIT", "Get the top posts from a given subreddit"
    def read(subreddit)
      puts "reading subreddit..."
      response = client.get_posts(subreddit)
      posts = response[:data][:children]
      i = 1
      @array = []
      posts.take(25).each do |post|
        post = post[:data]
        post_id = post[:id]
        @array << "http://www.reddit.com/r/#{subreddit}/comments/#{post_id}/"
        puts ("#{i}. " + post[:title]).bright
        puts "#{post[:url]}"
        puts "____________________________________________________________"
        puts ("Upvotes: #{post[:ups]}").color(:green) + "|" + Rainbow("Downvotes: #{post[:downs]}").color(:red) + "| Number of Comments #{post[:num_comments]}"
        puts
        i += 1
      end

      puts "To open a page, please enter a topic number after 'open'. Example: open 12"
      puts "To open the comments for a specific topic in terminal, enter 'c' and then the topic number. Example: c 12"

      input = STDIN.gets.chomp!
      if input.include?("open")
        input = input.gsub("open ","")
        target_url = @array[input.to_i - 1]
        puts "Opening #{target_url}..."
        Launchy.open(target_url)
{'fraction_non_alphanumeric': 0.14669421487603307, 'fraction_numerical': 0.00490702479338843, 'mean_word_length': 2.8157635467980295, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '202543', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1134, 'n_words': 313}