Skip to content

Instantly share code, notes, and snippets.

@sh4869
Created November 13, 2016 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sh4869/0029e8650303a45bd06a152a542154a6 to your computer and use it in GitHub Desktop.
Save sh4869/0029e8650303a45bd06a152a542154a6 to your computer and use it in GitHub Desktop.
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