-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.rb
77 lines (62 loc) · 1.83 KB
/
test.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
require 'serrano'
require 'bibtex'
require 'json'
require 'GoogleBooks'
# Serrano.configuration do |config|
# config.mailto = "[email protected]"
# end
# title = "Ecocentric and anthropocentric attitudes toward the environment"
# author = "S. Thompson"
# publication = "Journal of Environmental Psychology"
# found_doi = Serrano.works(query: title, query_author: author, sort: 'relevance', order: "desc", format: 'bibtex')['message']['items'].first["DOI"]
# res = Serrano.content_negotiation(ids: found_doi, format: "bibtex")
# puts res
def populate_json(title, author)
data = '{
"itemType" : "book",
"title" : "",
"creators" : [
{
"creatorType" : "author",
"firstName" : "",
"lastName" : ""
}
],
"url" : "",
"tags" : [],
"collections" : [],
"relations" : {}
}'
data_hash = JSON.parse(data)
data_hash["title"] = title
data_hash["creators"][0]["firstName"] = author.split(" ").first
data_hash["creators"][0]["lastName"] = author.split(" ").last
data_hash.to_json
return data_hash
end
title = "A theory of justice"
author = ""
# populated_data = populate_json(title, author)
# puts populated_data
books = GoogleBooks.search("#{title}, #{author}")
books.each do |book|
puts book.title
puts book.authors
puts book.published_date
puts book.publisher
puts book.description
puts book.isbn
puts "----------------"
end
# book = books.first
# i = 0
# while i < 10
# puts books[i].title
# puts books[i].authors
# puts books[i].title
# puts books[i].published_date
# puts books[i].publisher
# # puts books[i].description
# puts books[i].isbn
# i += 1
# end