Created
November 23, 2015 10:11
-
-
Save nanonanomachine/0702734c647f3d7ca5d3 to your computer and use it in GitHub Desktop.
最強に雑なmboxデータelasticsearch取り込み
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 "bundler/setup" | |
require "kconv" | |
Bundler.require | |
client = Elasticsearch::Client.new log: true | |
bulk_requests = Array.new | |
# mbox | |
mboxes = Mbox.open("./gmail.mbox") | |
for i in 0..(mboxes.length-1) | |
begin | |
client.index index: 'gmail', type: 'gmail', id: i, | |
body:{ | |
from: mboxes[i].headers[:from].toutf8, | |
to: mboxes[i].headers[:to].toutf8, | |
body: mboxes[i].content.first.to_s.toutf8.gsub(/(\r\n|\r|\n|\f)/,""), | |
date: DateTime.parse(mboxes[i].headers[:date]) | |
} | |
rescue | |
next | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment