Created
November 13, 2016 12:16
-
-
Save sh4869/0029e8650303a45bd06a152a542154a6 to your computer and use it in GitHub Desktop.
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
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