-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.rb
More file actions
29 lines (24 loc) · 741 Bytes
/
Copy pathexample.rb
File metadata and controls
29 lines (24 loc) · 741 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
# -*- coding: utf-8 -*-
require_relative "paralleldo"
require "open-uri"
days = (1..31).to_a
results = parallel(5, days) do |thread_no, day|
url = "http://en.wikipedia.org/wiki/October_#{day}"
# If wikipedia article in -url- mentions an event
# for the day October -day-, 2000, return a string
# which represents that event
text = open(url).read
pos = text.index("/wiki/2000")
if pos
# Event mentioned in Wikipedia without html tags
text[text.index(" – ", pos)..
text.index("</li>", pos)-1].gsub(" – ", "").gsub(/<[^>]+>/, "")
end
end
puts "Events mentioned in Wikipedia: "
results.each.with_index do |event, index|
day = days[index]
if event
puts "October #{day}, 2000: #{event}"
end
end