-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_convert.rb
More file actions
49 lines (32 loc) · 971 Bytes
/
user_convert.rb
File metadata and controls
49 lines (32 loc) · 971 Bytes
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
require 'nokogiri'
require 'pry'
require 'json'
require 'xmlsimple'
class DataConvert
def initialize
t = Time.now
count = 0
refactored_hash = []
File.foreach("/media/dilum/96648732-125e-4b47-aa00-74d25da99130/Data/Users.xml").with_index do |line, line_num|
noko = Nokogiri::XML(line)
if line.include? "Location"
hash = {}
hash['Id'] = noko.at("row")['Id']
hash['Location'] = noko.at("row")['Location']
hash['Reputation'] = noko.at("row")['Reputation']
hash['Age'] = noko.at("row")['Age']
hash['DisplayName'] = noko.at("row")['DisplayName']
refactored_hash << hash
hash = nil
end
noko = nil
count = count + 1
p count
end
puts Time.now - t
p count
File.write('/media/dilum/96648732-125e-4b47-aa00-74d25da99130/Data/Users.json', JSON.pretty_generate(refactored_hash))
puts Time.now - t
end
end
data = DataConvert.new