Class: GoogleProfiles

Inherits:
Object
  • Object
show all
Includes:
Searchy
Defined in:
lib/esearchy/SocialNetworks/googleprofiles.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Searchy

#clean, #fix, #hash_url, #maxhits=, #print_emails, #search_depth, #search_docs, #search_emails, #search_office_xml, #search_pdfs, #search_txts

Constructor Details

#initialize(maxhits = 0, start = 0) ⇒ GoogleProfiles

Returns a new instance of GoogleProfiles.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/esearchy/SocialNetworks/googleprofiles.rb', line 11

def initialize(maxhits = 0, start = 0)
  @start = start
  @totalhits = maxhits
  @emails = []
  @people = []
  @company_name = nil
  @r_urls = Queue.new
  @r_docs = Queue.new
  @r_pdfs = Queue.new
  @r_txts = Queue.new
  @r_officexs = Queue.new
  @lock = Mutex.new
  @threads = []
end

Instance Attribute Details

#company_nameObject

Returns the value of attribute company_name.



25
26
27
# File 'lib/esearchy/SocialNetworks/googleprofiles.rb', line 25

def company_name
  @company_name
end

#emailsObject

Returns the value of attribute emails.



25
26
27
# File 'lib/esearchy/SocialNetworks/googleprofiles.rb', line 25

def emails
  @emails
end

#peopleObject

Returns the value of attribute people.



25
26
27
# File 'lib/esearchy/SocialNetworks/googleprofiles.rb', line 25

def people
  @people
end

Instance Method Details

#enquire_person(profile) ⇒ Object



77
78
79
# File 'lib/esearchy/SocialNetworks/googleprofiles.rb', line 77

def enquire_person(profile)
  # TO DO: parse profile to obtain more information
end

#parse(html) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/esearchy/SocialNetworks/googleprofiles.rb', line 81

def parse(html)
  @totalhits= html.scan(/<\/b> of[ about | ]\
<b>(.*)<\/b> from/)[0][0].gsub(",","").to_i if @totalhits == 0
  html.scan(/<h2 class=r><a href="([0-9A-Z\
a-z:\\\/?&=@+%.;"'()_-]+)" class=l>([\w\s]*) -/).each do |profile|
    @domain = @query.match(/@/) ? @query : ("@" + @query)
    name,last = profile[1].split(" ") 
    @people << [name,last]
    @emails << "#{name.split(' ')[0]}.#{last.split(' ')[0]}#{@domain}"
    @emails << "#{name[0,1]}#{last.split(' ')[0]}#{@domain}"
    #@emails.concat(fix(search_person(name,last)))
    @emails.uniq!
    print_emails(@emails)
  end
end

#search(query) ⇒ Object



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
# File 'lib/esearchy/SocialNetworks/googleprofiles.rb', line 27

def search(query)
  @query = query
  http = Net::HTTP.new("www.google.com",80)
  begin
    http.start do |http|
      request = Net::HTTP::Get.new( "/cse?q=site:www.google.com+intitle:%22Google+" +
                                    "Profile%22+%22Companies+I%27ve+worked+for%22+%22at+" + 
                                    CGI.escape(@company_name) + 
                                    "%22&hl=en&cof=&num=100&filter=0" +   
                                    "&safe=off&start=#{@start}",
                                     {'User-Agent' => UserAgent::fetch})
      response = http.request(request)
      case response
      when Net::HTTPSuccess, Net::HTTPRedirection
        parse(response.body)
        @start = @start + 100
        if @totalhits > @start
          ESearchy::LOG.puts "Searching #{self.class} from #{@start-100} to #{@start}"
          parse(response.body)
          search_emails(response.body.gsub(/<em>|<\/em>/,""))
          sleep(ESearchy::DELAY)
          search(query)
        else
          ESearchy::LOG.puts "Searching #{self.class} from #{@start-100} to #{@start}"
          parse(response.body)
          search_emails(response.body.gsub(/<em>|<\/em>/,""))
        end
      else
        return response.error!
      end
    end
  rescue Net::HTTPFatalError
    ESearchy::LOG.puts "Error: Something went wrong with the HTTP request"
  end
  @start = 0
end

#search_person(name, last) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/esearchy/SocialNetworks/googleprofiles.rb', line 64

def search_person(name,last)
  email = []
  # Search Yahoo
  y = Yahoo.new(50)
  y.search("first:\"#{name}\" last:\"#{last}\"")
  emails.concat(y.emails).uniq!
  # Search Google
  #g = Google.new(50)
  #g.search("#{name} #{last}")
  #emails.concat(g.emails).uniq!
  return emails
end