lothianbusestimetable 0.1.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/lothianbusestimetable.rb +157 -67
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4f7f7c0e1ed96b68f78ef7f9bddf81375b8ecd2
|
4
|
+
data.tar.gz: a6e0bdb8b9ca8f2c0599033de6d07c8937afa21b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 942477a77c162efcca923b19bcd46d24c71ac60a9a5ba1309aafdae6b8b1c98dbbd66f2c2aa0caeb5ab02fcac30f079f9cffd23cdcde5e0de8ce674a7c7efb12
|
7
|
+
data.tar.gz: 1f530cbb5f9f553557794c7ee82a7adb1b37ed688e86c17298b20855524e9100515fad05ff8aeb3052036e4cb01486e4053e74ad8b6202d06290836e306d7230
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -37,59 +37,86 @@ class LothianBusesTimetable
|
|
37
37
|
|
38
38
|
table = doc.root.element('//table')
|
39
39
|
|
40
|
-
prev_col = ''
|
40
|
+
prev_col, prev_bus_stop = '', ''
|
41
41
|
a0 = []
|
42
|
+
|
43
|
+
tablebreak = 0
|
42
44
|
|
43
45
|
# get the destinations
|
44
46
|
# inbound and outbound
|
45
47
|
table.xpath('tr').each do |tr|
|
46
48
|
|
47
49
|
# get the name
|
48
|
-
|
50
|
+
tds = tr.xpath('td')#.map(&:unescape)
|
49
51
|
|
50
|
-
|
52
|
+
a = tds.flat_map {|x| r = x.xpath('.//text()').map(&:unescape); r.any? ? r : ''}
|
51
53
|
|
52
|
-
|
54
|
+
next unless a.any?
|
53
55
|
|
54
|
-
|
56
|
+
col1 = a.shift.strip.gsub(',','')
|
57
|
+
|
58
|
+
if col1 =~ /^Service (\w?\d+(?:\s*\/\s*\w?\d+)?)/ then
|
55
59
|
|
56
60
|
a0 << {service: $1}
|
61
|
+
tablebreak = 0
|
57
62
|
|
58
|
-
elsif prev_col =~ /^Service \w?\d
|
59
|
-
|
63
|
+
elsif prev_col =~ /^Service \w?\d+(?:\s*\/\s*\w?\d+)?/
|
64
|
+
|
60
65
|
a0.last.merge!(timetable: col1)
|
61
66
|
a0 << {}
|
62
|
-
|
67
|
+
|
68
|
+
elsif col1.empty? and prev_col.empty? and a.length <= 1
|
69
|
+
a0 << {}
|
70
|
+
next
|
63
71
|
elsif col1.empty? and a.length > 1
|
72
|
+
|
73
|
+
tablebreak += 1 if a0.last and a0.last.any?
|
64
74
|
next
|
65
75
|
elsif col1.empty? or a.length <= 1
|
66
76
|
|
67
|
-
|
68
|
-
if prev_col.empty? or prev_col.length <= 1 and a0.last and a0.last.any? then
|
77
|
+
tablebreak += 1 if a0.last and a0.last.any?
|
78
|
+
if (prev_col.empty? or prev_col.length <= 1) and a0.last and a0.last.any? then
|
79
|
+
|
80
|
+
if a0.last.keys.first == col1 and prev_col.empty? and a0.last.keys.length > 1 then
|
69
81
|
|
70
|
-
|
82
|
+
a0 << {}
|
83
|
+
end
|
71
84
|
|
72
85
|
else
|
73
86
|
|
74
87
|
prev_col = ''
|
75
88
|
end
|
76
|
-
|
89
|
+
|
77
90
|
else
|
78
91
|
|
79
|
-
if a.any? and a.length >
|
92
|
+
if a.any? and a.length > 2 and a0.last and col1.length < 40 then
|
93
|
+
|
94
|
+
if a0.last.keys.last == col1 and prev_col.empty? and a0.last.keys.length > 1 then
|
95
|
+
|
96
|
+
a0 << {}
|
97
|
+
end
|
80
98
|
|
81
99
|
next if col1.empty?
|
82
100
|
h = a0.last
|
83
|
-
|
101
|
+
|
102
|
+
tablebreak = 0 if h.empty?
|
84
103
|
if h.has_key? col1 then
|
85
|
-
|
104
|
+
|
105
|
+
if tablebreak == 0 then
|
106
|
+
col1 = col1 + ' [R]'
|
107
|
+
h[col1] = a
|
108
|
+
else
|
109
|
+
h[col1].concat a.take(19)
|
110
|
+
end
|
86
111
|
else
|
87
|
-
h[col1] = a
|
112
|
+
h[col1] = a.take(19)
|
88
113
|
end
|
89
114
|
|
115
|
+
|
90
116
|
else
|
91
117
|
|
92
|
-
|
118
|
+
tablebreak += 1
|
119
|
+
|
93
120
|
next
|
94
121
|
end
|
95
122
|
end
|
@@ -97,55 +124,17 @@ class LothianBusesTimetable
|
|
97
124
|
prev_col = col1
|
98
125
|
|
99
126
|
end
|
100
|
-
|
101
|
-
|
102
|
-
master =
|
103
|
-
service: '',
|
104
|
-
weekday: {desc: '', inbound: {}, outbound: {}},
|
105
|
-
saturday: {desc: '', inbound: {}, outbound: {}},
|
106
|
-
sunday: {desc: '', inbound: {}, outbound: {}}
|
107
|
-
}
|
108
|
-
|
109
|
-
h = a0.shift
|
110
|
-
|
111
|
-
master[:service] = h[:service]
|
112
|
-
master[:weekday][:desc] = h[:timetable]
|
113
|
-
|
114
|
-
h = a0.shift
|
115
|
-
|
116
|
-
master[:weekday][:inbound] = h
|
117
|
-
h = a0.shift
|
118
|
-
|
119
|
-
master[:weekday][:outbound] = h
|
120
|
-
|
121
|
-
h = a0.shift
|
122
|
-
h = a0.shift until h.any?
|
123
|
-
|
124
|
-
master[:saturday][:desc] = h[:timetable]
|
125
|
-
h = a0.shift
|
126
|
-
master[:saturday][:inbound] = h
|
127
|
-
h = a0.shift
|
128
|
-
master[:saturday][:outbound] = h
|
129
|
-
|
130
|
-
h = a0.shift
|
127
|
+
#puts 'a0: ' + a0.inspect
|
128
|
+
|
129
|
+
master = build_timetable(a0)
|
131
130
|
|
132
|
-
|
133
|
-
|
134
|
-
h = a0.shift until h.any?
|
135
|
-
master[:sunday][:desc] = h[:timetable]
|
136
|
-
h = a0.shift
|
137
|
-
master[:sunday][:inbound] = h
|
138
|
-
h = a0.shift
|
139
|
-
master[:sunday][:outbound] = h
|
140
|
-
|
141
|
-
end
|
142
|
-
|
131
|
+
#puts 'master: ' + master.inspect
|
143
132
|
|
144
133
|
master.to_a[1..-1].each do |key, timetable|
|
145
134
|
|
146
135
|
timetable.to_a[1..-1].each do |direction, printed_rows|
|
147
136
|
|
148
|
-
next unless printed_rows
|
137
|
+
next unless printed_rows
|
149
138
|
|
150
139
|
# find the interval gaps
|
151
140
|
|
@@ -164,6 +153,7 @@ class LothianBusesTimetable
|
|
164
153
|
end
|
165
154
|
|
166
155
|
|
156
|
+
|
167
157
|
# sanitise the times (where short hand times are
|
168
158
|
# given i.e. minutes only)
|
169
159
|
|
@@ -210,7 +200,6 @@ class LothianBusesTimetable
|
|
210
200
|
|
211
201
|
gap_times = gaps.zip(periods)
|
212
202
|
|
213
|
-
|
214
203
|
intervaltimes = gap_times.map do |i, desc|
|
215
204
|
|
216
205
|
intervals = []
|
@@ -222,6 +211,7 @@ class LothianBusesTimetable
|
|
222
211
|
new_rows = every_hourlyset_interval printed_rows, i
|
223
212
|
else
|
224
213
|
interval = desc[/then (?:at least )?every (\d+) mins(?: until)?/,1]
|
214
|
+
|
225
215
|
new_rows = every_interval printed_rows, i, interval
|
226
216
|
end
|
227
217
|
|
@@ -271,11 +261,86 @@ class LothianBusesTimetable
|
|
271
261
|
|
272
262
|
private
|
273
263
|
|
264
|
+
def build_timetable(a0)
|
265
|
+
|
266
|
+
master = {
|
267
|
+
service: '',
|
268
|
+
weekday: {desc: '', inbound: {}, outbound: {}},
|
269
|
+
saturday: {desc: '', inbound: {}, outbound: {}},
|
270
|
+
sunday: {desc: '', inbound: {}, outbound: {}}
|
271
|
+
}
|
272
|
+
|
273
|
+
h = a0.shift
|
274
|
+
|
275
|
+
master[:service] = h[:service]
|
276
|
+
h = a0.shift until h.any? #
|
277
|
+
master[:weekday][:desc] = h[:timetable]
|
278
|
+
|
279
|
+
#h = a0.shift
|
280
|
+
h = a0.shift until h.any? and not h[:service]
|
281
|
+
|
282
|
+
master[:weekday][:inbound] = h
|
283
|
+
h = a0.shift
|
284
|
+
a0.reject! {|x| x.empty?}
|
285
|
+
|
286
|
+
|
287
|
+
if a0.first and a0.first.any? then
|
288
|
+
|
289
|
+
#h = a0.shift
|
290
|
+
h = a0.shift until h.any?
|
291
|
+
|
292
|
+
master[:weekday][:outbound] = h unless h.has_key? :timetable
|
293
|
+
|
294
|
+
h = a0.shift unless h.has_key? :timetable
|
295
|
+
|
296
|
+
|
297
|
+
if h and a0.any? and h[:timetable] != 'Public Holiday Timetable' then
|
298
|
+
|
299
|
+
h = a0.shift until h.any?
|
300
|
+
|
301
|
+
master[:saturday][:desc] = h[:timetable]
|
302
|
+
h = a0.shift until h.any? and not h[:service]
|
303
|
+
master[:saturday][:inbound] = h
|
304
|
+
h = a0.shift
|
305
|
+
|
306
|
+
return master unless a0.any?
|
307
|
+
h = a0.shift until h.any?
|
308
|
+
|
309
|
+
master[:saturday][:outbound] = h unless h.has_key? :timetable
|
310
|
+
|
311
|
+
|
312
|
+
h = a0.shift until h.any?
|
313
|
+
|
314
|
+
if h and a0.any? then
|
315
|
+
h = a0.shift
|
316
|
+
h = a0.shift until h.any?
|
317
|
+
master[:sunday][:desc] = h[:timetable]
|
318
|
+
h = a0.shift
|
319
|
+
h = a0.shift until h.any?
|
320
|
+
|
321
|
+
master[:sunday][:inbound] = h
|
322
|
+
h = a0.shift until h.any?
|
323
|
+
master[:sunday][:outbound] = h
|
324
|
+
|
325
|
+
end
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
return master
|
330
|
+
end
|
331
|
+
|
274
332
|
def every_hourlyset_interval(rows, i)
|
275
333
|
|
276
334
|
rows.map do |k,v|
|
277
|
-
|
278
|
-
|
335
|
+
|
336
|
+
# some limited bus stops don't apply
|
337
|
+
next unless v.detect {|x| x =~ /^\d{2} *$/}
|
338
|
+
|
339
|
+
# the next statement caters for special journey entries which happen at
|
340
|
+
# limited times of the day
|
341
|
+
|
342
|
+
i -= 19 if v.length < i
|
343
|
+
|
279
344
|
start_i = i - 1
|
280
345
|
|
281
346
|
start_i -= 1 while v[start_i] =~ /^(?:\d{2}|-|\||[A-Z]|) *$/
|
@@ -291,7 +356,7 @@ class LothianBusesTimetable
|
|
291
356
|
prev_time = t1
|
292
357
|
|
293
358
|
t2 = t1
|
294
|
-
|
359
|
+
|
295
360
|
j = i + 1
|
296
361
|
j += 1 until v[j] =~ /^\d{4}/
|
297
362
|
|
@@ -321,15 +386,40 @@ class LothianBusesTimetable
|
|
321
386
|
end
|
322
387
|
|
323
388
|
def every_interval(rows, i, interval=60)
|
324
|
-
|
389
|
+
# todo 26-Aug-2017
|
390
|
+
# here we will add
|
325
391
|
return unless interval
|
326
392
|
|
327
393
|
rows.map do |k,v|
|
394
|
+
|
395
|
+
next unless v.is_a? Array
|
328
396
|
|
329
397
|
times = []
|
330
398
|
|
331
|
-
next unless v[i-1]
|
399
|
+
next unless v[i-1]
|
400
|
+
|
401
|
+
if v[i-1] =~ /^\d{2} *$/ then
|
402
|
+
|
403
|
+
j = i - 1
|
404
|
+
j -= 1 until v[j] =~ /^\d{4}/
|
405
|
+
|
406
|
+
t0 = Time.strptime(v[j], "%H%M")
|
407
|
+
prev_time = t0
|
408
|
+
|
409
|
+
(j+1..i-1).each do |k|
|
410
|
+
|
411
|
+
s = "%02d%s" % [t0.hour, v[k]]
|
412
|
+
new_time = Time.strptime(s, "%H%M")
|
413
|
+
new_time += (60 * 60) if new_time < prev_time
|
414
|
+
prev_time = new_time
|
415
|
+
|
416
|
+
#times << new_time.strftime("%H%M")
|
417
|
+
v[k] = new_time.strftime("%H%M")
|
418
|
+
|
419
|
+
end
|
420
|
+
end
|
332
421
|
|
422
|
+
next unless v[i-1] =~ /^\d{4} *$/
|
333
423
|
t = Time.strptime(v[i-1], "%H%M") #if v[i-1] =~ /^\d{4}$/
|
334
424
|
|
335
425
|
while t + (60 * interval.to_i) < Time.strptime(v[i+1], "%H%M") do
|
@@ -337,7 +427,7 @@ class LothianBusesTimetable
|
|
337
427
|
times << t.strftime("%H%M")
|
338
428
|
end
|
339
429
|
|
340
|
-
[k,times]
|
430
|
+
[k, times ]
|
341
431
|
end.compact
|
342
432
|
end
|
343
433
|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lothianbusestimetable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
K7yWGJq+eGl34xrLaucvTbO8Ua3rHayCkBzgfx5LVcch22Axj8quw+YGsPnhuosr
|
32
32
|
BHdCmx9eUF/TKg==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2017-08-
|
34
|
+
date: 2017-08-29 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: nokorexi
|
metadata.gz.sig
CHANGED
Binary file
|