Class: GatherCompanies

Inherits:
Base
  • Object
show all
Defined in:
lib/whos_using_what/data_gatherers/gather_companies.rb

Overview

meant to be able to be used as long-running process to save company data to DB

Instance Attribute Summary

Attributes inherited from Base

#set_paths

Instance Method Summary collapse

Methods inherited from Base

set_paths

Constructor Details

#initializeGatherCompanies

Returns a new instance of GatherCompanies.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/whos_using_what/data_gatherers/gather_companies.rb', line 10

def initialize

  @indeed_api_client = IndeedApiClient.new

  @@mongo_client = MongoHelper.get_mongo_connection

  @@companies_coll = @@mongo_client['companies']

  @li_config = YAML.load_file(File.expand_path("../../config/linkedin.env", __FILE__))

  @@linkedin_client = LinkedinClient.new @li_config["api_key"], @li_config["api_secret"], @li_config["user_token"], @li_config["user_secret"], @li_config["url"]


end

Instance Method Details

#load_companies_from_indeedObject



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
# File 'lib/whos_using_what/data_gatherers/gather_companies.rb', line 25

def load_companies_from_indeed

  num_iterations = 20
  increment = 20
  cnt = 15

  while cnt <= num_iterations do

    keyword = "ruby"
    city_state = "pleasant hill, ca"

    json_resp = @indeed_api_client.perform_search keyword, city_state, increment, (increment * (cnt-1)) + 1

    json_resp['results'].each do |job|

      if  @@companies_coll.find_one({'name' => job['company']}) != nil
        next
      end

      company = {}

      company['locations'] = {
          values: [
              {
                  address: {
                      city: job['city'],
                      state: job['state'],
                      country: job['country']
                  }
              }
          ]
      }
      company['name']= job['company']
      company['languages'] =
          {
              keyword.to_s => job['url']
          }


      @@companies_coll.insert company

    end
    cnt += cnt
  end

end

#load_companies_to_db(num_iterations, cur_start_position, facet_location_code) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/whos_using_what/data_gatherers/gather_companies.rb', line 72

def load_companies_to_db num_iterations, cur_start_position, facet_location_code

  company_size_codes = "C,D,E,F,G,H,I"
  increment = 10
  cnt = 1

  while cnt <= num_iterations do
    puts cur_start_position.to_s

    params = {
        "start" => cur_start_position.to_s
    }

    resp = @@linkedin_client.query_companies facet_location_code, company_size_codes, params
    docs = resp['companies'].values[3]
    if docs != nil
      docs.each do |doc|
        puts doc
        @@companies_coll.insert(doc)
      end
    end

    cur_start_position = cur_start_position + increment

    cnt = cnt + 1

    sleep_seconds = rand(3-9)
    puts "sleeping for: " << sleep_seconds.to_s << " seconds"
    sleep(sleep_seconds)

  end
end