whos_dated_who 0.3.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/.travis.yml +5 -1
- data/lib/whos_dated_who/bing_client.rb +8 -5
- data/lib/whos_dated_who/biography.rb +2 -1
- data/lib/whos_dated_who/cli.rb +11 -9
- data/lib/whos_dated_who/client.rb +1 -8
- data/lib/whos_dated_who/importer.rb +23 -13
- data/lib/whos_dated_who/parser.rb +46 -28
- data/lib/whos_dated_who/version.rb +1 -1
- data/spec/fixtures/{scarlett-johansson.resp → scarlett_johansson.resp} +0 -0
- data/spec/spec_helper.rb +14 -4
- data/spec/support/fixture_helpers.rb +13 -0
- data/spec/whos_dated_who/parser_spec.rb +8 -4
- data/whos_dated_who.gemspec +2 -0
- metadata +35 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5246ad18e26101327c9f7648c893fae3b1fdc1b
|
4
|
+
data.tar.gz: 33b92cf602bb0c9678dcc4432913bc41378df622
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9581d74ca3ee89f125966ea3244cfb441279b90b3870d3fa8ebcf8d8f2459a40b0dd4c1a895e021e28a75fa6b017d34f8f4d47735190647926bd7b024401b2c5
|
7
|
+
data.tar.gz: 888aa209ec8573b714293ac4989df7d1014897f83957589d0343ce9071fcf25cdcc30d381400672baf73819436e7ee797e5f75218e8f5a17b4a2f91327cc81c6
|
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
module WhosDatedWho
|
3
3
|
class BingClient
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
def initialize(type = 'Web', num_results = 10, api_key = API_KEY)
|
8
|
-
@api_key = api_key
|
4
|
+
def initialize(type = 'Web', num_results = 10, api_key = nil)
|
5
|
+
@api_key = api_key || ENV['BING_API_KEY'] || config[:bing_api_key]
|
9
6
|
@client = Bing.new(@api_key, num_results, type)
|
10
7
|
end
|
11
8
|
|
12
9
|
def search(query)
|
13
10
|
@client.search(query)
|
14
11
|
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def config
|
16
|
+
@config ||= YAML.load_file(File.expand_path('~/.whos_dated_who.yml'))
|
17
|
+
end
|
15
18
|
end
|
16
19
|
end
|
@@ -4,6 +4,7 @@ class Biography < Hashie::Trash
|
|
4
4
|
include Hashie::Extensions::IgnoreUndeclared
|
5
5
|
|
6
6
|
@split_on_comma = ->(i) { i.is_a?(Array) ? i : i.split(', ') }
|
7
|
+
@parse_date = ->(i) { Date.parse(i) }
|
7
8
|
|
8
9
|
property :first_name
|
9
10
|
property :middle_name
|
@@ -12,7 +13,7 @@ class Biography < Hashie::Trash
|
|
12
13
|
property :full_name_at_birth
|
13
14
|
property :other_names # array
|
14
15
|
property :age, transform_with: ->(i) { i.to_i }
|
15
|
-
property :born_on, from: :date_of_birth, transform_with:
|
16
|
+
property :born_on, from: :date_of_birth, transform_with: @parse_date
|
16
17
|
property :born_at, from: :birthplace
|
17
18
|
property :height
|
18
19
|
property :weight
|
data/lib/whos_dated_who/cli.rb
CHANGED
@@ -11,23 +11,24 @@ module WhosDatedWho
|
|
11
11
|
desc 'query', 'Return the relationship status of a celebrity'
|
12
12
|
def query(name)
|
13
13
|
result = Client.new.fetch(name)
|
14
|
-
|
14
|
+
status = [
|
15
|
+
result[:relationship_status], result[:current_relationship][:human]
|
16
|
+
].join(': ')
|
17
|
+
|
18
|
+
puts status
|
15
19
|
puts result[:current_relationship][:dates].join(', ')
|
16
20
|
end
|
17
21
|
|
18
|
-
desc 'explore', 'Return the relationship status of everyone
|
22
|
+
desc 'explore', 'Return the relationship status of everyone in celebs.yml'
|
19
23
|
def explore
|
20
|
-
|
21
|
-
celebs = my_celebs
|
22
|
-
celebs.each do |celeb|
|
24
|
+
my_celebs.map do |celeb|
|
23
25
|
puts "Processing #{celeb}..."
|
24
26
|
begin
|
25
|
-
|
27
|
+
Client.new.fetch(celeb)
|
26
28
|
rescue
|
27
29
|
puts "Error processing #{celeb}"
|
28
30
|
end
|
29
|
-
end
|
30
|
-
results
|
31
|
+
end.compact
|
31
32
|
end
|
32
33
|
|
33
34
|
desc 'import_mine', 'Import my favorites into RethinkDB'
|
@@ -37,7 +38,8 @@ module WhosDatedWho
|
|
37
38
|
|
38
39
|
desc 'import_maxim', 'Import maxim hot 100'
|
39
40
|
def import_maxim
|
40
|
-
|
41
|
+
# TODO
|
42
|
+
# resp = Faraday.get('http://www.maxim.com/hot100/2014')
|
41
43
|
end
|
42
44
|
|
43
45
|
private
|
@@ -4,15 +4,8 @@ module WhosDatedWho
|
|
4
4
|
bing_results = BingClient.new.search("#{name} site:dating.famousfix.com")
|
5
5
|
url = bing_results.first[:Web].first[:Url]
|
6
6
|
resp = Faraday.get(url)
|
7
|
-
if resp.success?
|
8
|
-
Parser.new.parse(resp.body)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
7
|
|
14
|
-
|
15
|
-
name.gsub(/\s/, '-').downcase
|
8
|
+
resp.success? && Parser.new.parse(resp.body)
|
16
9
|
end
|
17
10
|
end
|
18
11
|
end
|
@@ -4,28 +4,38 @@ module WhosDatedWho
|
|
4
4
|
attr_reader :conn, :logger, :table_name
|
5
5
|
|
6
6
|
def initialize(db, table_name)
|
7
|
-
@conn
|
8
|
-
@logger
|
7
|
+
@conn = r.connect(host: 'localhost', db: db || 'celebs')
|
8
|
+
@logger = Logger.new(STDOUT)
|
9
9
|
@table_name = table_name
|
10
10
|
end
|
11
11
|
|
12
12
|
def fetch_and_import(celebs)
|
13
13
|
celebs.each do |celeb|
|
14
|
-
|
15
|
-
|
16
|
-
result = Client.new.fetch(celeb)
|
17
|
-
logger.info "Importing #{celeb} to #{table_name}"
|
18
|
-
import(result)
|
19
|
-
rescue
|
20
|
-
first_name, last_name = celeb.split
|
21
|
-
r.table("missing_#{table_name}").insert(first_name: first_name, last_name: last_name).run(conn)
|
22
|
-
logger.error("Error importing #{celeb}, added to missing")
|
23
|
-
end
|
14
|
+
logger.info "Fetching #{celeb}"
|
15
|
+
import_celeb(celeb)
|
24
16
|
end
|
25
17
|
end
|
26
18
|
|
27
|
-
|
19
|
+
private
|
20
|
+
|
21
|
+
def import_celeb(celeb)
|
22
|
+
result = Client.new.fetch(celeb)
|
23
|
+
logger.info "Importing #{celeb} to #{table_name}"
|
24
|
+
create(result)
|
25
|
+
rescue
|
26
|
+
logger.error("Error importing #{celeb}, added to missing")
|
27
|
+
add_to_missing_celebs(celeb)
|
28
|
+
end
|
29
|
+
|
30
|
+
def create(results)
|
28
31
|
r.table(table_name).insert(JSON.parse(results.to_json)).run(conn)
|
29
32
|
end
|
33
|
+
|
34
|
+
def add_to_missing_celebs(celeb)
|
35
|
+
first_name, last_name = celeb.split
|
36
|
+
r.table("missing_#{table_name}").insert(
|
37
|
+
first_name: first_name, last_name: last_name
|
38
|
+
).run(conn)
|
39
|
+
end
|
30
40
|
end
|
31
41
|
end
|
@@ -17,48 +17,66 @@ module WhosDatedWho
|
|
17
17
|
private
|
18
18
|
|
19
19
|
def extract_bio
|
20
|
-
result =
|
20
|
+
result = parse_bio(@doc.css('#rcol .cbox-nopad:nth-child(3)'))
|
21
21
|
result[:description] = @doc.css('#wikitext').text
|
22
22
|
|
23
|
-
bio = @doc.css('#rcol .cbox-nopad:nth-child(3)')
|
24
|
-
bio.css('.posl, .posr').each do |el|
|
25
|
-
if el.matches?('.posl')
|
26
|
-
@key = el.content
|
27
|
-
else
|
28
|
-
key = normalize_bio_key(@key)
|
29
|
-
if el.css('div').size > 0
|
30
|
-
result[key] = [] unless result[key]
|
31
|
-
result[key] = el.children.map(&:content).reject do |c|
|
32
|
-
c.empty? || c =~ /^\s\(/
|
33
|
-
end
|
34
|
-
else
|
35
|
-
value = el.content.rstrip
|
36
|
-
if respond_to?("parse_#{key}".to_sym, true)
|
37
|
-
result[key] = send("parse_#{key}", value)
|
38
|
-
else
|
39
|
-
result[key] = value
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
23
|
@biography = Biography.new(result.symbolize_keys)
|
46
24
|
end
|
47
25
|
|
48
26
|
def extract_current_relationship
|
49
27
|
current = @doc.css('.pbox.datebox')
|
50
28
|
relationship = {}
|
29
|
+
|
51
30
|
relationship[:human] = current.css('div.padb10:first').text
|
52
31
|
relationship[:dates] = current.css('ul li').map(&:content)
|
53
32
|
result[:current_relationship] = relationship
|
54
|
-
|
55
|
-
result[:status] =
|
56
|
-
result[:status] = :rumored if relationship[:human] =~ /rumored/
|
57
|
-
result[:status] = :dating if relationship[:human] =~ /dating/
|
58
|
-
result[:status] = :single if relationship[:human] =~ /single/
|
33
|
+
|
34
|
+
result[:status] = parse_relationship_status(relationship)
|
59
35
|
relationship
|
60
36
|
end
|
61
37
|
|
38
|
+
def list?(el)
|
39
|
+
el.css('div').size > 0
|
40
|
+
end
|
41
|
+
|
42
|
+
def parse_bio(bio)
|
43
|
+
bio.css('.posl, .posr').each_with_object({}) do |el, result|
|
44
|
+
if el.matches?('.posl')
|
45
|
+
@key = el.content
|
46
|
+
else
|
47
|
+
key = normalize_bio_key(@key)
|
48
|
+
result[key] = list?(el) ? parse_list(el) : parse_content(el, key)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def parse_list(el)
|
54
|
+
el.children.map(&:content).reject do |c|
|
55
|
+
c.empty? || c =~ /^\s\(/
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def parse_content(el, key)
|
60
|
+
value = el.content.rstrip
|
61
|
+
if respond_to?("parse_#{key}".to_sym, true)
|
62
|
+
send("parse_#{key}", value)
|
63
|
+
else
|
64
|
+
value
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def parse_relationship_status(relationship)
|
69
|
+
case relationship[:human]
|
70
|
+
when /married/ then :married
|
71
|
+
when /engaged/ then :engaged
|
72
|
+
when /rumored/ then :rumored
|
73
|
+
when /dating/ then :dating
|
74
|
+
when /single/ then :single
|
75
|
+
else
|
76
|
+
:unknown
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
62
80
|
def extract_past_relationships
|
63
81
|
end
|
64
82
|
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
@@ -1,16 +1,26 @@
|
|
1
|
+
require 'simplecov'
|
1
2
|
require 'coveralls'
|
2
|
-
|
3
|
+
|
4
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
5
|
+
SimpleCov::Formatter::HTMLFormatter,
|
6
|
+
Coveralls::SimpleCov::Formatter
|
7
|
+
]
|
8
|
+
SimpleCov.start do
|
9
|
+
add_filter 'spec'
|
10
|
+
end
|
3
11
|
|
4
12
|
require 'pry'
|
5
13
|
require 'whos_dated_who'
|
6
14
|
|
15
|
+
Dir[File.expand_path('..', __FILE__) + '/support/**/*.rb'].each do |f|
|
16
|
+
require(f)
|
17
|
+
end
|
18
|
+
|
7
19
|
RSpec.configure do |config|
|
8
20
|
config.filter_run :focus
|
9
21
|
config.run_all_when_everything_filtered = true
|
10
22
|
|
11
|
-
if config.files_to_run.one?
|
12
|
-
config.default_formatter = 'doc'
|
13
|
-
end
|
23
|
+
config.default_formatter = 'doc' if config.files_to_run.one?
|
14
24
|
|
15
25
|
config.profile_examples = 10
|
16
26
|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module FixtureHelpers
|
2
|
+
def fixture_response(name)
|
3
|
+
File.read(fixture_file("#{name}.resp"))
|
4
|
+
end
|
5
|
+
|
6
|
+
def fixture_file(filename)
|
7
|
+
File.expand_path("../../fixtures/#{filename}", __FILE__)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.include(FixtureHelpers)
|
13
|
+
end
|
@@ -3,9 +3,9 @@ require 'spec_helper'
|
|
3
3
|
module WhosDatedWho
|
4
4
|
describe Parser do
|
5
5
|
let(:parser) { Parser.new }
|
6
|
+
|
6
7
|
before do
|
7
|
-
|
8
|
-
parser.parse(body)
|
8
|
+
parser.parse(fixture_response(:scarlett_johansson))
|
9
9
|
@result = parser.result.biography
|
10
10
|
end
|
11
11
|
|
@@ -42,7 +42,7 @@ module WhosDatedWho
|
|
42
42
|
[
|
43
43
|
:other_names, :brand_endorsements, :websites, :brothers, :sisters,
|
44
44
|
:friends, :pets, :favorite_movies, :favorite_places, :favorite_foods,
|
45
|
-
:favorite_colors, :favorite_accessories
|
45
|
+
:favorite_colors, :favorite_accessories, :distinctive_features
|
46
46
|
].each do |key|
|
47
47
|
expect(@result[key]).to be_kind_of(Array)
|
48
48
|
end
|
@@ -56,10 +56,14 @@ module WhosDatedWho
|
|
56
56
|
expect(@result.pets.size).to eq(2)
|
57
57
|
expect(@result.favorite_movies).to include(/Heat/)
|
58
58
|
expect(@result.favorite_places).to include('London')
|
59
|
+
expect(@result.distinctive_features).to include(/Lips/)
|
60
|
+
expect(@result.distinctive_features).to include(/Husky Voice/)
|
59
61
|
end
|
60
62
|
|
61
63
|
it 'gets a description' do
|
62
|
-
expect(@result.description).to match(
|
64
|
+
expect(@result.description).to match(
|
65
|
+
/American actress, model, and singer/
|
66
|
+
)
|
63
67
|
end
|
64
68
|
end
|
65
69
|
end
|
data/whos_dated_who.gemspec
CHANGED
@@ -32,4 +32,6 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_development_dependency 'pry-rescue'
|
33
33
|
spec.add_development_dependency 'coveralls'
|
34
34
|
spec.add_development_dependency 'rethinkdb'
|
35
|
+
spec.add_development_dependency 'awesome_print'
|
36
|
+
spec.add_development_dependency 'rubocop'
|
35
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whos_dated_who
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Perez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -192,6 +192,34 @@ dependencies:
|
|
192
192
|
- - ">="
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: awesome_print
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: rubocop
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ">="
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
type: :development
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - ">="
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
195
223
|
description: Unofficial API for whosdatedwho.com
|
196
224
|
email:
|
197
225
|
- adrianperez.deb@gmail.com
|
@@ -202,6 +230,7 @@ extra_rdoc_files: []
|
|
202
230
|
files:
|
203
231
|
- ".gitignore"
|
204
232
|
- ".rspec"
|
233
|
+
- ".rubocop.yml"
|
205
234
|
- ".travis.yml"
|
206
235
|
- Gemfile
|
207
236
|
- LICENSE.txt
|
@@ -218,8 +247,9 @@ files:
|
|
218
247
|
- lib/whos_dated_who/parser.rb
|
219
248
|
- lib/whos_dated_who/version.rb
|
220
249
|
- spec/acceptance/whos_dated_who_spec.rb
|
221
|
-
- spec/fixtures/
|
250
|
+
- spec/fixtures/scarlett_johansson.resp
|
222
251
|
- spec/spec_helper.rb
|
252
|
+
- spec/support/fixture_helpers.rb
|
223
253
|
- spec/whos_dated_who/client_spec.rb
|
224
254
|
- spec/whos_dated_who/parser_spec.rb
|
225
255
|
- whos_dated_who.gemspec
|
@@ -249,8 +279,9 @@ specification_version: 4
|
|
249
279
|
summary: Unofficial API for whosdatedwho.com
|
250
280
|
test_files:
|
251
281
|
- spec/acceptance/whos_dated_who_spec.rb
|
252
|
-
- spec/fixtures/
|
282
|
+
- spec/fixtures/scarlett_johansson.resp
|
253
283
|
- spec/spec_helper.rb
|
284
|
+
- spec/support/fixture_helpers.rb
|
254
285
|
- spec/whos_dated_who/client_spec.rb
|
255
286
|
- spec/whos_dated_who/parser_spec.rb
|
256
287
|
has_rdoc:
|