-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
131 lines (103 loc) · 3.19 KB
/
app.rb
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# encoding: UTF-8
$LOAD_PATH.unshift(File.expand_path("vendor/ft-0.0.3/lib", File.dirname(__FILE__)))
require "sinatra/base"
require "sequel"
require "json"
Tilt.register 'md', Tilt::RDiscountTemplate
DB = Sequel.connect("fusiontables:///")
API_KEY = "AIzaSyDGFlbdQqjeLGeLVk_9stEtLOv9hSNN2Sw"
FusionTables::Connection::URL = URI.parse("https://www.googleapis.com/fusiontables/v1/query")
FusionTables::Connection::API_URL = API_KEY
TABLES = {
# :industrias => 1731573, #la tabla posta
:industrias => '15E8qU0EgyybVf1ghfgYvHjAiZDRsLYRP2BL-kqg'.to_sym,
# :basurales => 1413418,
:basurales =>'1pwtB3qV624D6v4z0LtseR3zrmcaSR4LFbrPhVhQ'.to_sym,
# :asentamientos => 1874853,
:asentamientos => '1QktJ0shGoudW9By5ivsNY-SssDsn99ZWvg_jFqA'.to_sym,
# :relocalizaciones => 1809291,
:relocalizaciones => '1ATG8zFuuoa6xrhEc6CaxnQd7pyHc6zTr60VOiLA'.to_sym,
# :reportes => 1875969,
:reportes => '1eZOCmU84b4dh9KLISSYu75e_Te4HK8uEC3mp26A'.to_sym,
}
Industrias = DB[TABLES[:industrias]]
Basurales = DB[TABLES[:basurales]]
Asentamientos = DB[TABLES[:asentamientos]]
Reportes = DB[TABLES[:reportes]]
Relocalizaciones = DB[TABLES[:relocalizaciones]]
class NilClass
def empty?; true; end
end
class QPR < Sinatra::Base
helpers do
def root(path)
File.expand_path(path, File.dirname(__FILE__))
end
include Rack::Utils
alias_method :h, :escape_html
def join_cols(row, name)
row.keys.grep(/^#{name}_\d+$/).map do |key|
row[key] unless row[key].empty?
end.compact.join("<br>\n")
end
def yesno(value)
if value == "1" || value == "SI"
"Sí"
else
"No"
end
end
end
set :app_file, __FILE__
WWW = /^(https?:\/\/)www\./
COM = /^(https?:\/\/)(.+?)\.com\.ar/
before do
if request.url =~ WWW
redirect(request.url.sub(WWW, '\1'), 301)
end
if request.url =~ COM
redirect(request.url.sub(COM, '\1\2.org.ar'), 301)
end
end
get "/" do
@rubros = File.read(root("data/rubros")).split("\n") + [nil]
@clasificaciones = [
"Consolidado",
"No consolidado",
"Dinámico",
"No consolidado con asentamiento",
"Consolidado con asentamiento"
]
erb(:"index")
end
get "/contenido/:page" do |page|
erb(:"contenido/#{page}")
end
get "/preguntas-frecuentes" do
@sections = {}
%w(semaforo-industrias).each do |section|
@sections[section] = render(:md, :"faq/#{section}", :layout => false)
end
erb(:"faq", :layout => true)
end
get "/industrias/:curt" do |curt|
@industria = Industrias.where(:curt => curt).first
erb(:"industria")
end
get "/basurales/:id" do |id|
@basural = Basurales.where(:id => id).first
erb(:"basural")
end
get "/asentamientos/:id" do |id|
@asentamiento = Asentamientos.where(:id => id).first
@relocalizaciones = Relocalizaciones.where(:id => id).all
erb(:"asentamiento")
end
get "/industrias-semaforo.js" do
rows = Industrias.select(:semaforo_riesgo, :semaforo_legal, :razon_social).all.map do |hash|
hash.values
end
response["Cache-Control"] = "public, max-age=86400"
%Q{QPR.industrias = {semaforo: #{rows.to_json}};}
end
end