-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdoga.rb
More file actions
executable file
·263 lines (204 loc) · 5.02 KB
/
doga.rb
File metadata and controls
executable file
·263 lines (204 loc) · 5.02 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#!/usr/bin/ruby
#
# Author: Ramon Antonio Parada <ramon@bigpress.net>
#
require 'net/http'
require 'rexml/document'
require 'cgi'
require 'ftools'
#http://www.xunta.es/Dog/Dog2009.nsf/FichaContenido/B576?OpenDocument
#"A".upto("Z") do |l|
#['a','b','c','ch','d','e','f','g','h','i','j','k','l','m','n','�','o','p','q','r','s','t','u','v','w','x','y','z'].each do |l|
class Cache
# save as marshalize.rb in /usr/local/lib/ruby/1.8/ and then require 'marshalize'
TMP_DIR = "/Library/Caches/"
def marshal(filename,data=nil)
Dir.chdir(TMP_DIR) do
if data != nil
open(filename, "w") { |f| Marshal.dump(data, f) }
elsif File.exists?(filename)
open(filename) { |f| Marshal.load(f) }
end
end
end
def marshal_destroy(filename)
Dir.chdir(TMP_DIR) do
if File.exists?(filename)
File.delete(filename)
else
return "File does not exists."
end
end
end
def marshal_clone(data)
filename = srand.to_s << '.tmp'
marshal(filename,data)
h = marshal(filename)
marshal_destroy(filename)
return h
end
def Cache.get(url)
if !Cache.existe(url)
data = Cache.write(url)
else
data = Cache.read(url)
end
if data.size == 0
data = Cache.write(url)
end
return data
end
def Cache.write(url)
response = Net::HTTP.get_response(URI.parse(url))
data = response.body
#response.class Net::HTTPOK
#response.code 200
print "write: "+url+" code:"+response.code+" size:"+data.size.to_s+"\n"
if data.size == 0
print "size:0"
#Process.exit
end
if data == ""
print "size:0b"
#Process.exit
end
filename = "/home/rap/cache/"+CGI::escape(url)
my_file = File.new(filename, File::CREAT|File::TRUNC|File::RDWR, 0644)
my_file.puts data
return data
end
def Cache.existe(url)
filename = "/home/rap/cache/"+CGI::escape(url)
existe = File.exists?(filename)
return existe
end
def Cache.read(url)
filename = "/home/rap/cache/"+CGI::escape(url)
data=IO.read(filename)
errortext = "ERRO DE ACCESO"
if data.include? errortext
print "error "
return ""
end
return data
end
def Cache.read2(url)
filename = "/home/rap/cache/"+CGI::escape(url)
begin
file = File.new("readfile.rb", "r")
while (line = file.gets)
puts "#{counter}: #{line}"
counter = counter + 1
end
file.close
rescue => err
puts "Exception: #{err}"
err
end
end
end
class Doga
#print data1
#"/Dog/Dog2008.nsf/TablaMes/38F66?OpenDocument"
#mes
def Doga.getDiario()
url1 = "http://www.xunta.es/Dog/dogpriv.nsf/TablaContenido/50A6?OpenDocument"
data1 = Cache.get(url1)
#r1 = Regexp.new('^a-z+:\\s+\w+') #=> /^a-z+:\s+\w+/
# r2 = Regexp.new('cat', true) #=> /cat/i
regex1 =/\/Dog\/Dog([0-9][0-9][0-9][0-9]).nsf\/TablaMes\/([A-Z0-9]*)\?OpenDocument/i
results1 = data1.scan(regex1)
#p results1.size
#results1.each { |result|
# print result[0]
# print result[1]
# print "-1\n"
#}
return results1
end
#dia
#2000
#10B46
def Doga.getMes(id1, id2)
url2 = "http://www.xunta.es/Dog/Dog"+id1+".nsf/TablaMes/"+id2+"?OpenDocument"
data2 = Cache.get(url2)
regex2 = /\/Dog\/Dog([0-9][0-9][0-9][0-9]).nsf\/IndiceSumario\/([A-Z0-9]*)\?OpenDocument/i
results2 = data2.scan(regex2)
#p results2.size
#results2.each { |result|
# print result[0]
# print result[1]
# print "-2\n"
#}
return results2
end
#seccions
#2000
#115D2
def Doga.getDia(id1, id2)
url3 = "http://www.xunta.es/Dog/Dog"+id1+".nsf/IndiceSumario/"+id2+"?OpenDocument"
data3 = Cache.get(url3)
regex3 = /\/Dog\/Dog([0-9][0-9][0-9][0-9]).nsf\/FichaSeccion\/([A-Z0-9]*)\?OpenDocument\"/i
results3 = data3.scan(regex3)
#p results3.size
#results3.each { |result|
# print result[0]
# print result[1]
# print "-3\n"
#}
return results3
end
#fichas
#2000
#1160A
def Doga.getSeccion(id1, id2)
url4 = "http://www.xunta.es/Dog/Dog"+id1+".nsf/FichaSeccion/"+id2+"?OpenDocument"
data4 = Cache.get(url4)
regex4 = /\/Dog\/Dog([0-9][0-9][0-9][0-9]).nsf\/FichaContenido\/([A-Z0-9]*)\?OpenDocument/i
results4 = data4.scan(regex4)
#p results4.size
#results4.each { |result|
#print result[0]
# print result[1]
# print "-4\n"
#}
return results4
end
#ficha
#http://www.xunta.es/Dog/Dog2007.nsf/FichaContenido/305DE?OpenDocument
def Doga.getFicha(id1, id2)
url5 = "http://www.xunta.es/Dog/Dog"+id1+".nsf/FichaContenido/"+id2+"?OpenDocument"
data5 = Cache.get(url5)
end
end
#diario -> meses
meses = Doga.getDiario
#meses -> dias
dias = Array.new
meses.each { |mes|
print "Mes "+mes[0]+" "+mes[1]
auxdias = Doga.getMes(mes[0], mes[1])
print " Dias "+auxdias.size.to_s+"\n"
dias = dias | auxdias
}
#dias -> secciones
secciones = Array.new
dias.each { |dia|
print "Dia "+dia[0]+" "+dia[1]
auxsecciones = Doga.getDia(dia[0], dia[1])
print " Secciones "+auxsecciones.size.to_s+"\n"
secciones = secciones | auxsecciones
}
#secciones -> fichas
fichas = Array.new
secciones.each { |seccion|
print "Seccion "+seccion[0]+" "+seccion[1]
auxfichas = Doga.getSeccion(seccion[0], seccion[1])
print " Fichas "+auxfichas.size.to_s+"\n"
fichas = fichas | auxfichas
}
#fichas
fichas.each { |ficha|
print "Ficha "+ficha[0]+" "+ficha[1]+"\n"
Doga.getFicha(ficha[0], ficha[1])
}