Created
November 4, 2014 01:10
-
-
Save dialupnoises/b4087b6eb071a86fdbf1 to your computer and use it in GitHub Desktop.
TIPPING CULTURE
This file contains hidden or 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
| require 'json' | |
| comments = JSON.parse(File.open('comments.json', 'r').read) | |
| tips = [] | |
| collections = [] | |
| custom_tips = [] | |
| custom_collections = [] | |
| send = /^(.+?), (.+?) wants to send you a Bitcoin tip for ([\d,\.]+) (.+?)\./ | |
| collect = /^The Bitcoin tip for ([\d,\.]+) (.+?) has been collected by \*(.+?)\*/ | |
| custom_send = /^(.+?), (.+?) wants to send you a Bitcoin tip for .+? (.+?) \(([\d\.,]+) (.+?)\/.+?\)/ | |
| custom_collect = /^The Bitcoin tip for .+? (.+?) \(([\d,\.]+) (.+?)\/.+?\) has been collected by \*(.+?)\*./ | |
| comments.each do |comment| | |
| next if comment['body'].empty? | |
| match = send.match comment['body'] | |
| if match | |
| receiver = match[1].gsub('/u/', '') | |
| sender = match[2] | |
| amount = match[3].gsub(',', '').to_f | |
| unit = match[4].split[0] | |
| tips.push "#{receiver},#{sender},#{amount},#{unit},#{comment['date']}" | |
| elsif (match = collect.match comment['body']) | |
| receiver = match[3] | |
| amount = match[1].gsub(',', '').to_f | |
| unit = match[2].split[0] | |
| collections.push "#{receiver},#{amount},#{unit},#{comment['date']}" | |
| elsif (match = custom_send.match comment['body']) | |
| receiver = match[1].gsub('/u/', '') | |
| sender = match[2] | |
| custom_unit = match[3] | |
| amount = match[4].gsub(',', '').to_f | |
| real_unit = match[5] | |
| custom_tips.push "#{receiver},#{sender},#{amount},#{real_unit},#{custom_unit},#{comment['date']}" | |
| elsif (match = custom_collect.match comment['body']) | |
| custom_unit = match[1] | |
| amount = match[2].gsub(',', '').to_f | |
| real_unit = match[3] | |
| receiver = match[4] | |
| custom_collections.push "#{receiver},#{amount},#{real_unit},#{custom_unit},#{comment['date']}" | |
| else | |
| puts comment['body'] + "\n" | |
| end | |
| end | |
| File.open('tips.csv', 'w') do |f| | |
| f.write "Receiver,Sender,Amount,Unit,Date\n" | |
| f.write tips.join("\n") | |
| end | |
| File.open('custom_tips.csv', 'w') do |f| | |
| f.write "Receiver,Sender,Amount,Real Unit,Custom Unit,Date\n" | |
| f.write custom_tips.join("\n") | |
| end | |
| File.open('collections.csv', 'w') do |f| | |
| f.write "Receiver,Amount,Unit,Date\n" | |
| f.write collections.join("\n") | |
| end | |
| File.open('custom_collections.csv', 'w') do |f| | |
| f.write "Receiver,Amount,Real Unit,Custom Unit,Date\n" | |
| f.write custom_collections.join("\n") | |
| end |
This file contains hidden or 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
| require 'redd' | |
| require 'json' | |
| require 'openssl' | |
| OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE | |
| client = Redd::Client::Unauthenticated.new({user_agent: 'changetip analyze/1.0'}) | |
| changetip = client.user('changetip') | |
| comments = [] | |
| last_fetch_amount = nil | |
| until (not comments.last.nil?) and comments.length > 1000 do | |
| if comments.length == 0 | |
| comments = client.get_user_comments(changetip, { limit: 100, sort: :new }).things | |
| else | |
| comments = comments.concat client.get_user_comments(changetip, { after: "t1_" + comments.last.id, limit: 100, count: comments.length, sort: :new }).things | |
| end | |
| puts "#{comments.length} fetched" | |
| puts "last id: #{comments.last.id}" | |
| break if not last_fetch_amount.nil? and last_fetch_amount == comments.length | |
| last_fetch_amount = comments.length | |
| end | |
| comment_bodies = [] | |
| comments.each do |comment| | |
| comment_bodies.push({ | |
| body: comment.body, | |
| date: comment.attributes[:created_utc] | |
| }) | |
| end | |
| File.open('comments.json', 'w') do |f| | |
| f.write JSON.generate(comment_bodies) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment