Commit 79a857e7 by Son Do Hong

Merge branch 'feature/import_jobs' into 'master'

Feature/import jobs

See merge request !3
parents f5b0ef08 05c8d277
...@@ -34,3 +34,7 @@ ...@@ -34,3 +34,7 @@
/yarn-error.log /yarn-error.log
yarn-debug.log* yarn-debug.log*
.yarn-integrity .yarn-integrity
config/settings.local.yml
config/settings/*.local.yml
config/environments/*.local.yml
...@@ -32,6 +32,8 @@ gem "nokogiri" ...@@ -32,6 +32,8 @@ gem "nokogiri"
gem "mechanize" gem "mechanize"
gem "rubysl-open-uri" gem "rubysl-open-uri"
gem "whenever", require: false gem "whenever", require: false
gem "activerecord-import"
gem "config"
group :development, :test do group :development, :test do
# Call "byebug" anywhere in the code to stop execution and get a debugger console # Call "byebug" anywhere in the code to stop execution and get a debugger console
......
...@@ -45,6 +45,8 @@ GEM ...@@ -45,6 +45,8 @@ GEM
activerecord (6.0.1) activerecord (6.0.1)
activemodel (= 6.0.1) activemodel (= 6.0.1)
activesupport (= 6.0.1) activesupport (= 6.0.1)
activerecord-import (1.0.3)
activerecord (>= 3.2)
activestorage (6.0.1) activestorage (6.0.1)
actionpack (= 6.0.1) actionpack (= 6.0.1)
activejob (= 6.0.1) activejob (= 6.0.1)
...@@ -76,8 +78,13 @@ GEM ...@@ -76,8 +78,13 @@ GEM
chronic (0.10.2) chronic (0.10.2)
coderay (1.1.2) coderay (1.1.2)
concurrent-ruby (1.1.5) concurrent-ruby (1.1.5)
config (2.0.0)
activesupport (>= 4.2)
deep_merge (~> 1.2, >= 1.2.1)
dry-schema (~> 1.0)
connection_pool (2.2.2) connection_pool (2.2.2)
crass (1.0.5) crass (1.0.5)
deep_merge (1.2.1)
devise (4.7.1) devise (4.7.1)
bcrypt (~> 3.0) bcrypt (~> 3.0)
orm_adapter (~> 0.1) orm_adapter (~> 0.1)
...@@ -86,6 +93,36 @@ GEM ...@@ -86,6 +93,36 @@ GEM
warden (~> 1.2.3) warden (~> 1.2.3)
domain_name (0.5.20190701) domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0) unf (>= 0.0.5, < 1.0.0)
dry-configurable (0.9.0)
concurrent-ruby (~> 1.0)
dry-core (~> 0.4, >= 0.4.7)
dry-container (0.7.2)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1, >= 0.1.3)
dry-core (0.4.9)
concurrent-ruby (~> 1.0)
dry-equalizer (0.3.0)
dry-inflector (0.2.0)
dry-initializer (3.0.2)
dry-logic (1.0.5)
concurrent-ruby (~> 1.0)
dry-core (~> 0.2)
dry-equalizer (~> 0.2)
dry-schema (1.4.1)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.8, >= 0.8.3)
dry-core (~> 0.4)
dry-equalizer (~> 0.2)
dry-initializer (~> 3.0)
dry-logic (~> 1.0)
dry-types (~> 1.2)
dry-types (1.2.1)
concurrent-ruby (~> 1.0)
dry-container (~> 0.3)
dry-core (~> 0.4, >= 0.4.4)
dry-equalizer (~> 0.2, >= 0.2.2)
dry-inflector (~> 0.1, >= 0.1.2)
dry-logic (~> 1.0, >= 1.0.2)
erubi (1.9.0) erubi (1.9.0)
ffi (1.11.3) ffi (1.11.3)
globalid (0.4.2) globalid (0.4.2)
...@@ -246,9 +283,11 @@ PLATFORMS ...@@ -246,9 +283,11 @@ PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
activerecord-import
bootsnap (>= 1.4.2) bootsnap (>= 1.4.2)
byebug byebug
capybara (>= 2.15) capybara (>= 2.15)
config
devise devise
jbuilder (~> 2.7) jbuilder (~> 2.7)
listen (>= 3.0.5, < 3.2) listen (>= 3.0.5, < 3.2)
......
...@@ -3,3 +3,8 @@ require_relative "application" ...@@ -3,3 +3,8 @@ require_relative "application"
# Initialize the Rails application. # Initialize the Rails application.
Rails.application.initialize! Rails.application.initialize!
# # Rails.logger = Logger.new(STDOUT)
# # config.logger = ActiveSupport::Logger.new("log/#{Rails.env}.log")
# Rails.logger = Logger.new(STDOUT)
# Rails.logger.level = Logger::DEBUG
# Rails.logger.datetime_format = "%Y-%m-%d %H:%M:%S"
Config.setup do |config|
# Name of the constant exposing loaded settings
config.const_name = 'Settings'
# Ability to remove elements of the array set in earlier loaded settings file. For example value: '--'.
#
# config.knockout_prefix = nil
# Overwrite an existing value when merging a `nil` value.
# When set to `false`, the existing value is retained after merge.
#
# config.merge_nil_values = true
# Overwrite arrays found in previously loaded settings file. When set to `false`, arrays will be merged.
#
# config.overwrite_arrays = true
# Load environment variables from the `ENV` object and override any settings defined in files.
#
# config.use_env = false
# Define ENV variable prefix deciding which variables to load into config.
#
# config.env_prefix = 'Settings'
# What string to use as level separator for settings loaded from ENV variables. Default value of '.' works well
# with Heroku, but you might want to change it for example for '__' to easy override settings from command line, where
# using dots in variable names might not be allowed (eg. Bash).
#
# config.env_separator = '.'
# Ability to process variables names:
# * nil - no change
# * :downcase - convert to lower case
#
# config.env_converter = :downcase
# Parse numeric values as integers instead of strings.
#
# config.env_parse_values = true
# Validate presence and type of specific config values. Check https://github.com/dry-rb/dry-validation for details.
#
# config.schema do
# required(:name).filled
# required(:age).maybe(:int?)
# required(:email).filled(format?: EMAIL_REGEX)
# end
end
import_job:
csv_file: db/Venjob.csv
This source diff could not be displayed because it is too large. You can view the blob instead.
class CreateCompanies < ActiveRecord::Migration[6.0] class CreateCompanies < ActiveRecord::Migration[6.0]
def change def change
create_table :companies do |t| create_table :companies do |t|
t.string :email, null: false, default: "" t.string :email
t.text :description t.text :description
t.string :address t.string :address
t.string :url t.string :url
......
...@@ -27,7 +27,7 @@ ActiveRecord::Schema.define(version: 2019_12_05_082359) do ...@@ -27,7 +27,7 @@ ActiveRecord::Schema.define(version: 2019_12_05_082359) do
end end
create_table "companies", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "companies", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "email", default: "", null: false t.string "email"
t.text "description" t.text "description"
t.string "address" t.string "address"
t.string "url" t.string "url"
......
require "csv"
namespace :job do
desc "Import CSV file into database"
task import_csv: :environment do
csv_file = Settings.import_job.csv_file
CSV.foreach(csv_file, headers: true) do |row|
company_params = {
email: row["contact email"],
name: row["company name"],
address: row["company address"],
code: row["company id"]
}
company = Company.find_or_initialize_by(code: row["company id"])
company.update(company_params)
job_params = {
title: row["name"],
description: row["description"],
position: row["level"],
salary: row["salary"],
requirement: row["requirement"]
}
job = Job.find_or_initialize_by(title: row["name"], company_id: company.id)
job.update(job_params)
rescue
import_logger = ActiveSupport::Logger.new("log/import.log")
import_logger.error "Skip #{row}"
next
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment