Commit 39a4ebdb8ed10766f75bfba94cf0775eb3593982
1 parent
d2e34303
Exists in
master
and in
29 other branches
ActionItem261: adding script to extract data from sies database
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1644 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
1 changed file
with
58 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,58 @@ |
1 | +$LOAD_PATH.unshift('/usr/share/rails/activerecord/lib') | |
2 | +$LOAD_PATH.unshift('/usr/share/rails/activesupport/lib') | |
3 | + | |
4 | +require 'activerecord' | |
5 | +require 'active_support' | |
6 | + | |
7 | +LIMIT = 5 | |
8 | + | |
9 | +ActiveRecord::Base.establish_connection( | |
10 | + :adapter => 'mysql', | |
11 | + :host => 'localhost', | |
12 | + :database => 'farejador', | |
13 | + :username => 'root', | |
14 | + :password => 'root' | |
15 | +) | |
16 | + | |
17 | +class Enterprise < ActiveRecord::Base | |
18 | + set_table_name 'cons_dadosbasicos' | |
19 | +end | |
20 | + | |
21 | +class Category < ActiveRecord::Base | |
22 | + set_table_name 'lista_produtos' | |
23 | +end | |
24 | + | |
25 | +class Dumper | |
26 | + def initialize | |
27 | + @seq = 0 | |
28 | + @seqs = {} | |
29 | + end | |
30 | + | |
31 | + def pretty(str, alt = nil) | |
32 | + if alt.nil? | |
33 | + str | |
34 | + else | |
35 | + str + ' (' + alt + ')' | |
36 | + end | |
37 | + end | |
38 | + | |
39 | + def dump(cat, parent = nil) | |
40 | + | |
41 | + @seqs[cat] = @seq | |
42 | + puts "cat#{@seq} = Category.create!(:name => #{pretty(cat.nome, cat.nome_alt).inspect}, :parent => #{parent ? 'cat' + @seqs[parent].to_s : 'nil' })" | |
43 | + @seq = @seq + 1 | |
44 | + | |
45 | + Category.find(:all, :conditions => { :id_mae => cat.id }).each do |child| | |
46 | + dump(child, cat) | |
47 | + end | |
48 | + | |
49 | + end | |
50 | + | |
51 | +end | |
52 | + | |
53 | +dumper = Dumper.new | |
54 | +Category.find(:all, :conditions => 'id_mae is null or id_mae = -1').each do |cat| | |
55 | + dumper.dump(cat, nil) | |
56 | +end | |
57 | + | |
58 | +# puts Enterprise.find(:all, :limit => LIMIT).to_xml | ... | ... |