Skip to content

Instantly share code, notes, and snippets.

@sh4869
Created Nov 13, 2016
Embed
What would you like to do?
require 'open-uri'
require 'csv'
require 'json'
miteru_datas = []
json_text = "["
CSV.foreach("tweets.csv",encoding:"UTF-8:UTF-8") do |tweet|
text = tweet[5]
if !text.to_s.start_with?("RT") && text.to_s.include?("#miteru")
page_url = tweet[9].split(",").last
begin
title = OpenURI.open_uri(page_url).read.scan(/<title>(.*?)<\/title>/)[0][0].force_encoding("UTF-8")
rescue => e
title = ""
end
tweet_url = "https://twitter.com/statues/" + tweet[0].to_s
tweet_data = {"url" => page_url,"title" => title, "tweet_url" => tweet_url}
begin
puts tweet_data.to_json
miteru_datas.push(tweet_data)
rescue => e
puts e
end
end
end
json_text += "]"
puts json_text
puts miteru_datas.to_json
open("miteru_tweet.json","w") do |io|
JSON.dump(miteru_datas.to_json,io)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment