linkedindata 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/linkedindata.rb +72 -7
  3. metadata +8 -10
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bfd623725b05bee10c9876abb55628a0a2e28a06
4
+ data.tar.gz: 1a4b6a558e726171b2ac9171af396e5de836c3cf
5
+ SHA512:
6
+ metadata.gz: b71648311c07547c5fabcb1461581c8835e3ab38cab52e6f9c64828361bb27cf047d2cb3ae9dee609479bff34cd678e26d47a883df69c8bdc5019c470577a220
7
+ data.tar.gz: 27eed0c38444ca889ca331443aa4d78702bc21a07f47603ec66f39e1ad811f5a7d10633f5919bb7603cba322c45039198abd1e8e46ba48bba5d2d656fc397b18
data/lib/linkedindata.rb CHANGED
@@ -1,12 +1,20 @@
1
1
  require 'mechanize'
2
2
  require 'linkedin-scraper'
3
3
  require 'json'
4
+ require 'nokogiri'
5
+ require 'open-uri'
4
6
 
5
7
  class LinkedinData
6
- def initialize(input)
7
- @input = input
8
- @output = Array.new
9
- @startindex = 10
8
+ def initialize(input, todegree)
9
+ @input = input
10
+ @output = Array.new
11
+ @startindex = 10
12
+ @degree = 0
13
+ if todegree == nil
14
+ @to_degree = 0
15
+ else
16
+ @to_degree = todegree
17
+ end
10
18
  end
11
19
 
12
20
  # Searches for links on Google
@@ -47,17 +55,75 @@ class LinkedinData
47
55
 
48
56
  # Scrapes profile and makes JSON
49
57
  def scrape(url)
58
+ flag = 0
59
+ @output.each do |o|
60
+ if o[:profile_url] == url
61
+ flag = 1
62
+ if @degree < o[:degree]
63
+ o[:degree] = @degree
64
+ end
65
+ end
66
+ end
67
+
50
68
  profile = Linkedin::Profile.get_profile(url)
51
69
 
52
70
  if profile
53
71
  profile.current_companies.each do |c|
54
- c.merge!(:skills => profile.skills, :certifications => profile.certifications, :languages => profile.languages, :name => profile.first_name + " " + profile.last_name)
72
+ c.merge!(:skills => profile.skills, :certifications => profile.certifications, :languages => profile.languages, :name => profile.first_name + " " + profile.last_name, :location => profile.location, :area => profile.country, :industry => profile.industry, :picture => profile.picture, :organizations => profile.organizations, :groups => profile.groups, :education => profile.education, :websites => profile.websites, :profile_url => url, :degree => @degree, :current => "Yes")
73
+
74
+ if profile.picture
75
+ path = profile.picture.split("/")
76
+ if !File.file?("public/uploads/pictures/" + path[path.length-1].chomp.strip)
77
+ `wget -P public/uploads/pictures #{profile.picture}`
78
+ end
79
+ c.merge!(:pic_path => "public/uploads/pictures/" + path[path.length-1].chomp.strip)
80
+ end
81
+
55
82
  @output.push(c)
56
83
  end
57
84
 
58
85
  profile.past_companies.each do |c|
59
- c.merge!(:skills => profile.skills, :certifications => profile.certifications, :languages => profile.languages, :name => profile.first_name + " " + profile.last_name)
86
+ c.merge!(:skills => profile.skills, :certifications => profile.certifications, :languages => profile.languages, :name => profile.first_name + " " + profile.last_name, :location => profile.location, :area => profile.country, :industry => profile.industry, :picture => profile.picture, :organizations => profile.organizations, :groups => profile.groups, :education => profile.education, :websites => profile.websites, :profile_url => url, :degree => @degree, :current => "No")
60
87
  @output.push(c)
88
+
89
+ if profile.picture
90
+ path = profile.picture.split("/")
91
+ if !File.file?("public/uploads/pictures/" + path[path.length-1].chomp.strip)
92
+ `wget -P public/uploads/pictures #{profile.picture}`
93
+ end
94
+ c.merge!(:pic_path => "public/uploads/pictures/" + path[path.length-1].chomp.strip)
95
+ end
96
+ end
97
+
98
+ # Clean up directories
99
+ pics = Dir["public/uploads/*.jpg.*"]
100
+ pics.each do |p|
101
+ File.delete(p)
102
+ end
103
+ getRelated(url)
104
+ end
105
+ end
106
+
107
+ # Gets related profiles listed on side of the page
108
+ def getRelated(url)
109
+ if @degree < @to_degree
110
+ html = Nokogiri::HTML(open(url))
111
+ html.css("li.with-photo").each do |l|
112
+ plink = l.css("a")[0]['href'].split("?")
113
+
114
+ # Check to be sure not already saved
115
+ flag = 0
116
+ @output.each do |o|
117
+ if o[:profile_url] == plink[0]
118
+ flag = 1
119
+ end
120
+ end
121
+
122
+ if flag == 0
123
+ @degree += 1
124
+ scrape(plink[0])
125
+ @degree -= 1
126
+ end
61
127
  end
62
128
  end
63
129
  end
@@ -68,4 +134,3 @@ class LinkedinData
68
134
  return JSON.pretty_generate(@output)
69
135
  end
70
136
  end
71
-
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linkedindata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
5
- prerelease:
4
+ version: 0.0.6
6
5
  platform: ruby
7
6
  authors:
8
7
  - M. C. McGrath
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-02-25 00:00:00.000000000 Z
11
+ date: 2014-05-24 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Scrapes all LinkedIn profiles including terms you specify.
15
14
  email: shidash@shidash.com
@@ -18,30 +17,29 @@ extensions: []
18
17
  extra_rdoc_files: []
19
18
  files:
20
19
  - lib/linkedindata.rb
21
- homepage: https://github.com/Shidash/LinkedInData
20
+ homepage: https://github.com/transparencytoolkit/linkedindata
22
21
  licenses:
23
22
  - GPL
23
+ metadata: {}
24
24
  post_install_message:
25
25
  rdoc_options: []
26
26
  require_paths:
27
27
  - lib
28
28
  required_ruby_version: !ruby/object:Gem::Requirement
29
- none: false
30
29
  requirements:
31
- - - ! '>='
30
+ - - '>='
32
31
  - !ruby/object:Gem::Version
33
32
  version: '0'
34
33
  required_rubygems_version: !ruby/object:Gem::Requirement
35
- none: false
36
34
  requirements:
37
- - - ! '>='
35
+ - - '>='
38
36
  - !ruby/object:Gem::Version
39
37
  version: '0'
40
38
  requirements: []
41
39
  rubyforge_project:
42
- rubygems_version: 1.8.23
40
+ rubygems_version: 2.0.14
43
41
  signing_key:
44
- specification_version: 3
42
+ specification_version: 4
45
43
  summary: Get all LinkedIn profiles including terms you specify
46
44
  test_files: []
47
45
  has_rdoc: