-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtemplate.rb
88 lines (51 loc) · 1.7 KB
/
template.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
require 'open-uri'
require 'nokogiri'
require 'mechanize'
require 'json'
require './skraper_addons.rb'
__FILE__ == $0 ? ( REPO_NAME = __FILE__.split(".")[0] ) : ""
class String
include JsonMethods
end
def build_json(arr)
full_array = []
# arr = ["Robotica", "http://journals.cambridge.org/action/displayJournal?jid=ROB"]
if arr[1].split('/')[-1].split('?')[0] == 'displayJournal'
abb = arr[1].split('=')[1]
temp = {
"url" => "#{arr[1]}",
"rss" => "http://journals.cambridge.org/data/rss/feed_#{abb}_rss_2.0.xml",
"index" => "http://journals.cambridge.org/action/displayBackIssues?jid=#{abb}"
}
else
puts "BLEEP! BLOOP! I dont know how to build this entry: #{arr}"
end
full_array = { "name" => arr[0], "url" => temp['url'], "rss" => temp['rss'], "index" => temp['index'] }
p full_array
return full_array
end
def main()
page = Mechanize.new.get 'http://journals.cambridge.org/action/browseJournalsAlphabetically'
journals = page.search('table.all-subjects').search('li').search('a')
# topics_list = []
# for journal in journals
# link = "http://journals.cambridge.org/action/#{journal.attributes["href"].text()}"
# name = journal.text()
# p [name, link]
# topics_list << [name, link]
# end
# final = []
# for t in topics_list
# journal_entry = verify_data(build_json(t))
# final << journal_entry
# end
# puts "VALID JSON? #{final.to_json.valid_json?}"
# output_file = "#{REPO_NAME}_output.json"
# puts "Writing output to file: #{output_file}"
# File.open(output_file,'a').write(final.to_json)
# puts "VERIFYING... All outputs should be quiet"
# for entry in final
# verify_data(entry, false)
# end
end
main()