This repository was archived by the owner on Mar 25, 2022. It is now read-only.
forked from mickgortenmulder/senhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyze.rb
More file actions
51 lines (42 loc) · 1.34 KB
/
analyze.rb
File metadata and controls
51 lines (42 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'paralleldots'
require 'awesome_print'
require 'elasticsearch'
require 'json'
class MoodAnalyzer
def initialize
@client = Elasticsearch::Client.new log: true
file = File.read('input.json')
videos = JSON.parse(file)
@videos2 = videos["value"][0..2]
end
def convert_videos
converted_hash = Hash.new { |hash,key| hash[key] = Hash.new }
@videos2.each do |video|
name = video["Title"]
# print
# ap "New video available: #{name}"
# ap "Link: #{video["VideoUrl"]}"
# video["CommentList"].each do |comment|
# ap "#{name} comment: #{comment}"
# end
# ap emotion(comment)
converted_hash[name][:description] = video["Description"]
converted_hash[name][:link] = video["VideoUrl"]
converted_hash[name][:input] = video["CommentList"][0..9]
# hash[name][:mood] = emotion(subhash[:comments].join(","))
converted_hash[name][:mood] = "test"
converted_hash[name][:converted_time] = Time.now
end
converted_hash
end
def elastic_insert
mood_hash = convert_videos
mood_hash.each do |video_name,video_info|
puts video_name
puts video_info
@client.index index: 'mood-analyzer', type: 'my-video-mood', id: 1, body: { title: video_name, info: video_info }
end
end
end
analyzer = MoodAnalyzer.new
analyzer.elastic_insert