This repository has been archived by the owner on Jun 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
70 lines (61 loc) · 1.82 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
# -*- coding: utf-8 -*-
require 'rubygems'
require 'bundler'
Bundler.require
desc "импорт данных из csv"
task :import do
require './app'
require 'csv'
require 'open-uri'
CSV.parse(open('https://docs.google.com/spreadsheet/pub?key=0Au0stnPml5jIdHhSZl9NQTdtMHpqdWFCYk9SWm55cXc&single=true&gid=0&output=csv').read, headers: true) do |row|
brand_hash = {
title: row[0],
translit: row[1],
country: row[2],
year: row[3],
founder: row[4],
ceo: row[5],
site: row[7],
page_title: row[8],
meta_description: row[9],
meta_keywords: row[10],
slug: Russian::translit(row[0]).downcase.gsub(/\s/,'-')
}
brand_hash[:desc] = row[11].gsub(/CATALOG_URL/,"/catalog-#{brand_hash[:slug]}")
brand = Brand.create(brand_hash)
puts "Бренд: #{brand.title}"
row[6].split(',').map(&:strip).map do |title|
if category = Category.first(title: title)
category
else
Category.create(title: title, slug: Russian::translit(title).downcase.gsub(/\s/,'-'))
end
end.each do |category|
Categorization.create(brand: brand, category: category)
end
if row[12]
catalog_hash = {
page_title: row[12],
meta_description: row[13],
meta_keywords: row[14],
title: row[15],
text: row[16],
brand: brand
}
catalog = Catalog.create(catalog_hash)
puts "Каталог Бренда: #{catalog.title}"
end
end
end
desc "очистка базы"
task :clean do
require './app'
puts "Clean brands: #{Brand.count}"
Brand.destroy
puts "Clean categories: #{Category.count}"
Category.destroy
puts "Clean HBTM table: #{Categorization.count}"
Categorization.destroy
puts "Clean catalogs: #{Catalog.count}"
Catalog.destroy
end