-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ryan Kulp
committed
Apr 22, 2017
1 parent
7255a4b
commit b764ae1
Showing
3 changed files
with
53 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.