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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#!/usr/bin/ruby
#------------------------------------------------------------------------------
#
# Taginfo source: Projects
#
# parse.rb
#
#------------------------------------------------------------------------------
#
# Copyright (C) 2014 Jochen Topf <jochen@remote.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
#------------------------------------------------------------------------------
require 'pp'
require 'json'
require 'sqlite3'
#------------------------------------------------------------------------------
dir = ARGV[0] || '.'
db = SQLite3::Database.new(dir + '/taginfo-projects.db')
#------------------------------------------------------------------------------
projects = db.execute("SELECT id, fetch_json FROM projects WHERE fetch_result='OK' ORDER BY id")
projects.each do |id, json|
puts " #{id}..."
begin
data = JSON.parse(json, { :symbolize_names => true, :create_additions => false })
db.transaction do |db|
db.execute("UPDATE projects SET data_format=?, data_url=? WHERE id=?", data[:data_format], data[:data_url], id)
if data[:data_updated]
db.execute("UPDATE projects SET data_updated=? WHERE id=?", data[:data_updated], id)
end
if data[:project]
p = data[:project]
db.execute("UPDATE projects SET name=?, description=?, project_url=?, doc_url=?, icon_url=?, contact_name=?, contact_email=? WHERE id=?",
p[:name],
p[:description],
p[:project_url],
p[:doc_url],
p[:icon_url],
p[:contact_name],
p[:contact_email],
id
)
end
if data[:tags]
data[:tags].each do |d|
db.execute("INSERT INTO project_tags (project_id, key, value, description, doc_url, icon_url) VALUES (?, ?, ?, ?, ?, ?)",
id,
d[:key],
d[:value],
d[:description],
d[:doc_url],
d[:icon_url]
);
end
end
end
rescue JSON::ParserError
db.execute("UPDATE projects SET fetch_result='PARSE_ERROR' WHERE id=?", id)
end
end
#-- THE END -------------------------------------------------------------------
|