Last active
April 30, 2016 03:08
-
-
Save zakuroishikuro/05dbf0ffd9b3790dc654 to your computer and use it in GitHub Desktop.
Googleからダウンロードできる検索履歴のjsonを全て表示するやつ
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
# https://history.google.com/history/ | |
# 上のリンクのギアアイコンからダウンロードできる検索履歴のzipを全て表示するやつ | |
require 'kconv' | |
require 'json' | |
require 'cgi' | |
zip_path = ARGV[0] | |
raise "Googleからダウンロードした.zipファイルを指定してください。" unless /検索-20.*\.zip/ === zip_path | |
def get_jsons_in_zip(zip_path) | |
`unzip -c #{zip_path} *.json`.toutf8.each_line.select{|line| /^{/ === line} | |
end | |
def parse(json) | |
JSON.parse(json)["event"].map do |item| | |
query = item["query"] | |
time = Time.at *query["id"][0]["timestamp_usec"].to_i.divmod(1000000) | |
text = CGI.unescapeHTML query["query_text"] | |
{time:time, text:text} | |
end | |
end | |
queries = get_jsons_in_zip(zip_path).map(&method(:parse)).flatten | |
queries.group_by{|q| q[:time].strftime("%Y年%m月")}.sort.each do |month, queries| | |
puts "# #{month} #{queries.size}件", queries.map{|q| q[:text] }.join(" / "), "" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment