orcid_album_cover 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/bin/orcid_album_cover +140 -48
- data/images/html-example.png +0 -0
- data/lib/orcid_album_cover/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e1514f3fcaf780a9d850027b903445a78d97629
|
4
|
+
data.tar.gz: 77073a1fe0d2439f9c5ff0b88088b39fcdb12710
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3efe8e91bbb8d68cc9f5b9540f17811ba70dd61e544f3d7295ec67431bdd826ea79bfa5e505703a8f04678c503aa70bf8dd530ba90abe27ce54dafc612c5fe3
|
7
|
+
data.tar.gz: 81eed6c7ece66e83fcb4ae8ea48e7f3395951e9cafe20949a7e1074827bad01cb9feee002aa00cf65ff6121ac30635cb25b8c43c92b0f23fa45150d5a1160629
|
data/README.md
CHANGED
@@ -4,8 +4,14 @@ Via the command line, generate an album cover for your favorite [ORCiD](https://
|
|
4
4
|
|
5
5
|
Don't just talk about your life's work, *show it*!
|
6
6
|
|
7
|
+
## PNG Version
|
8
|
+
|
7
9
|
[![Example Image of Album Cover with much Rock and Roll](./images/example.png)](./images/example.png)
|
8
10
|
|
11
|
+
## HTML Version
|
12
|
+
|
13
|
+
[![Example Album Cover with much Rock and Roll and more Links](./images/html-example.png)](./images/html-example.png)
|
14
|
+
|
9
15
|
## Installation
|
10
16
|
|
11
17
|
$ gem install orcid_album_cover
|
data/bin/orcid_album_cover
CHANGED
@@ -8,8 +8,110 @@ require 'capybara-webkit'
|
|
8
8
|
require 'fileutils'
|
9
9
|
|
10
10
|
module Orcid
|
11
|
-
class
|
11
|
+
class Work
|
12
12
|
include Capybara::DSL
|
13
|
+
attr_reader :title
|
14
|
+
def initialize(document)
|
15
|
+
@document = document
|
16
|
+
end
|
17
|
+
|
18
|
+
def title
|
19
|
+
@title ||= begin
|
20
|
+
title_parts = []
|
21
|
+
title_parts << @document.css('work-title title').text
|
22
|
+
title_parts << @document.css('work-title subtitle').text
|
23
|
+
title_parts.join(': ')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def location
|
28
|
+
@location ||= resolve_doi || find_representative_url || ''
|
29
|
+
end
|
30
|
+
|
31
|
+
def location_not_found?
|
32
|
+
location.to_s.size == 0
|
33
|
+
end
|
34
|
+
|
35
|
+
def location_exists?
|
36
|
+
!location_not_found?
|
37
|
+
end
|
38
|
+
|
39
|
+
def doi
|
40
|
+
find_doi
|
41
|
+
end
|
42
|
+
|
43
|
+
def screenshot_exists?
|
44
|
+
@screenshot_exists
|
45
|
+
end
|
46
|
+
|
47
|
+
def save_screenshot(directory)
|
48
|
+
if location_exists?
|
49
|
+
uri = URI.parse(location)
|
50
|
+
begin
|
51
|
+
Capybara.current_driver = :webkit
|
52
|
+
Capybara.run_server = false
|
53
|
+
Capybara.app_host = "#{uri.scheme}://#{uri.host}"
|
54
|
+
visit(uri.path)
|
55
|
+
page.save_screenshot(File.join(directory, filename))
|
56
|
+
@screenshot_exists = true
|
57
|
+
rescue Capybara::Webkit::InvalidResponseError
|
58
|
+
@screenshot_exists = false
|
59
|
+
# Silently failing is good?
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def filename(prefix = nil)
|
65
|
+
if prefix
|
66
|
+
"#{prefix}-#{location.hash}.png"
|
67
|
+
else
|
68
|
+
"#{location.hash}.png"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
def resolve_doi
|
74
|
+
doi = find_doi
|
75
|
+
return nil if doi.nil?
|
76
|
+
begin
|
77
|
+
response = RestClient.get("http://dx.doi.org/#{doi}", accept: :html) { |resp, request, result| resp }
|
78
|
+
response.headers.fetch(:location)
|
79
|
+
rescue RestClient::Exception
|
80
|
+
nil
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def find_doi
|
85
|
+
@dois ||= []
|
86
|
+
return @dois.first if @dois.first
|
87
|
+
@document.css('work-external-identifier').each do |node|
|
88
|
+
if node.css('work-external-identifier-type').text =~ /^doi$/i
|
89
|
+
doi = node.css('work-external-identifier-id').text
|
90
|
+
if !doi.to_s.empty?
|
91
|
+
if doi =~ /^https?\:/
|
92
|
+
uri = URI.parse(doi)
|
93
|
+
@dois << uri.path.sub(/^\//, '')
|
94
|
+
else
|
95
|
+
@dois << doi
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
return @dois.first
|
101
|
+
end
|
102
|
+
|
103
|
+
def find_representative_url
|
104
|
+
@representative_urls ||= []
|
105
|
+
return @representative_urls.first if @representative_urls.first
|
106
|
+
@document.css('url').each do |node|
|
107
|
+
text = node.text
|
108
|
+
@representative_urls << text if ! text.to_s.empty?
|
109
|
+
end
|
110
|
+
return @representative_urls.first
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
class AlbumCover
|
13
115
|
attr_reader :orcid_profile_id, :host, :person_name
|
14
116
|
def initialize(orcid_profile_id, options = {})
|
15
117
|
@orcid_profile_id = orcid_profile_id
|
@@ -21,9 +123,8 @@ module Orcid
|
|
21
123
|
FileUtils.rm_rf(directory)
|
22
124
|
FileUtils.mkdir_p(directory)
|
23
125
|
find_person_name
|
24
|
-
|
25
|
-
|
26
|
-
find_locations_from_dois
|
126
|
+
find_works
|
127
|
+
guard_no_work_locations
|
27
128
|
screenscrap_locations
|
28
129
|
generate_cropped_files
|
29
130
|
if @format.to_s == 'html'
|
@@ -45,17 +146,21 @@ module Orcid
|
|
45
146
|
template << %(.thumbnail h3 { font-size: 1em; })
|
46
147
|
template << %(</style>)
|
47
148
|
template << "<body>"
|
149
|
+
template << "<h2>#{person_name}</h2>"
|
150
|
+
template << "<h3><a href='https://orcid.org/#{orcid_profile_id}'>#{orcid_profile_id}<h3>"
|
48
151
|
template << %(<ul class="thumbnails">)
|
49
|
-
@
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
152
|
+
@works.each_with_index do |work, index|
|
153
|
+
if work.screenshot_exists?
|
154
|
+
filename = File.join(directory, work.filename("cropped"))
|
155
|
+
template << %(<li class="span4">)
|
156
|
+
template << %(<div class="thumbnail">)
|
157
|
+
template << %(<a href="#{work.location}">)
|
158
|
+
template << %(<img data-src="holder.js/300x300" style="width: 300px height: 300px;" alt="#{work.title}" src="file://#{filename}">)
|
159
|
+
template << %(<h3>#{work.title}</h3>)
|
160
|
+
template << %(</a>)
|
161
|
+
template << %(</div>)
|
162
|
+
template << %(</li>)
|
163
|
+
end
|
59
164
|
end
|
60
165
|
template << "</ul>"
|
61
166
|
template << "</body>"
|
@@ -98,58 +203,45 @@ module Orcid
|
|
98
203
|
document = Nokogiri::XML(response)
|
99
204
|
personal_details = document.css('personal-details')
|
100
205
|
@person_name = ''
|
101
|
-
|
102
|
-
|
206
|
+
credit_name = personal_details.css('credit-name').text
|
207
|
+
if ! credit_name.empty?
|
208
|
+
@person_name = credit_name
|
103
209
|
else
|
104
|
-
|
105
|
-
|
210
|
+
given_name = personal_details.css('given-names').text
|
211
|
+
if ! given_name.empty?
|
212
|
+
@person_name += " #{given_name}"
|
106
213
|
end
|
107
|
-
|
108
|
-
|
214
|
+
family_name = personal_details.css('family-name').text
|
215
|
+
if ! family_name.empty?
|
216
|
+
@person_name += " #{family_name}"
|
109
217
|
end
|
110
218
|
@person_name.strip
|
111
219
|
end
|
112
220
|
end
|
113
221
|
|
114
|
-
def
|
222
|
+
def find_works
|
115
223
|
response = RestClient.get(profile_works_uri, accept: :xml)
|
116
224
|
document = Nokogiri::XML(response)
|
117
|
-
@
|
118
|
-
document.css('
|
119
|
-
|
120
|
-
dois << node.css('work-external-identifier-id').text
|
121
|
-
end
|
122
|
-
dois
|
225
|
+
@works = []
|
226
|
+
document.css('orcid-works orcid-work').each do |work_node|
|
227
|
+
@works << Work.new(work_node)
|
123
228
|
end
|
124
|
-
@dois.uniq!
|
125
|
-
@dois
|
126
229
|
end
|
127
230
|
|
128
|
-
def
|
129
|
-
if @
|
130
|
-
STDERR.puts "No
|
231
|
+
def guard_no_work_locations
|
232
|
+
if @works.empty?
|
233
|
+
STDERR.puts "No works found for ORCID: #{orcid_profile_id}."
|
131
234
|
exit(-1)
|
132
235
|
end
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
@locations = []
|
137
|
-
@dois.each_with_object(@locations) do |doi, mem|
|
138
|
-
response = RestClient.get("http://dx.doi.org/#{doi}", accept: :html) { |resp, request, result| resp }
|
139
|
-
@locations << [doi, response.headers.fetch(:location)]
|
236
|
+
if @works.all? {|work| work.location_not_found? }
|
237
|
+
STDERR.puts "No DOIs nor URIs found for ORCID: #{orcid_profile_id}."
|
238
|
+
exit(-1)
|
140
239
|
end
|
141
|
-
@locations
|
142
240
|
end
|
143
241
|
|
144
242
|
def screenscrap_locations
|
145
|
-
|
146
|
-
|
147
|
-
@locations.each do |doi, location|
|
148
|
-
uri = URI.parse(location)
|
149
|
-
Capybara.app_host = "#{uri.scheme}://#{uri.host}"
|
150
|
-
visit(uri.path)
|
151
|
-
filename = "#{location.hash}.png"
|
152
|
-
page.save_screenshot(File.join(directory, filename))
|
243
|
+
@works.each do |work|
|
244
|
+
work.save_screenshot(directory)
|
153
245
|
end
|
154
246
|
end
|
155
247
|
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orcid_album_cover
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Friesen
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- bootstrap/img/glyphicons-halflings.png
|
114
114
|
- bootstrap/js/bootstrap.min.js
|
115
115
|
- images/example.png
|
116
|
+
- images/html-example.png
|
116
117
|
- lib/orcid_album_cover/version.rb
|
117
118
|
- orcid_album_cover.gemspec
|
118
119
|
homepage: https://github.com/jeremyf/orcid_album_cover
|