Skip to content

Commit

Permalink
redo everything
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Kulp committed Apr 22, 2017
1 parent 7255a4b commit b764ae1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 53 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ don't code? [use the web version](https://product-hunt-upvotes.herokuapp.com/).
1. ```$ gem install hunting_season```

## how it works
1. run the script (```$ ruby producthunt.rb```)
1. run the script (```$ ruby client.rb```)
2. input your [Developer Token](https://www.producthunt.com/v1/oauth/applications)
2. input a featured product's URL
3. csv file of upvoters will save in the same directory as the script file
3. CSV file of upvoters will save in the same directory as the script file
51 changes: 51 additions & 0 deletions client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'hunting_season' # product hunt api
require 'csv' # write to CSV

class UpvoteDownloader

def initialize
puts "what's your product hunt developer token?"
@client = ProductHunt::Client.new(gets.chomp)
clear

puts "enter a product hunt URL, ie 'https://www.producthunt.com/posts/fomo-3'"
@slug = gets.chomp.split("/posts/")[1]
clear
end

def clear
system 'clear'
end

def run
puts "looking for post..."
post = @client.all_posts("search[slug]" => @slug)[0]

abort "post with slug '#{@slug}' not found, please try again." if post.nil?
puts "found post..."

get_and_show_voters(post)
end

def get_and_show_voters(post, voters = [])
vote_count = post['votes_count']
puts "processing #{vote_count} votes..."

pages = (vote_count.to_f / 50).ceil
pages.times do |page|
voters << post.votes(per_page: 50, page: page+1, order: 'asc')
voters.flatten!
puts "finished #{voters.count} votes..."
end

output = voters.flatten.uniq.map {|v| v['user']['twitter_username']}.compact.each_slice(1).map {|x| p x} # split users into rows
File.open("#{post['name'].downcase}_voters.csv", "w") {|f| f.write(output.inject([]) { |csv, row| csv << CSV.generate_line(row) }.join(""))}
clear

puts "done!\nyour CSV export is in the same folder as this file.\npowered by: www.ryanckulp.com"
end

end

# run
UpvoteDownloader.new.run
51 changes: 0 additions & 51 deletions producthunt.rb

This file was deleted.

0 comments on commit b764ae1

Please sign in to comment.