Blame view

script/sample-profiles 4.83 KB
21b4f0bc   Antonio Terceiro   Separating the sa...
1
#!/usr/bin/env ruby
b0c41ba1   Victor Costa   rails3: fix sampl...
2
# encoding: utf-8
21b4f0bc   Antonio Terceiro   Separating the sa...
3
require File.dirname(__FILE__) + '/../config/environment'
27ab82a7   Joenio Costa   Refactoring sampl...
4
include Noosfero::SampleDataHelper
21b4f0bc   Antonio Terceiro   Separating the sa...
5

27ab82a7   Joenio Costa   Refactoring sampl...
6
categories = $environment.categories
21b4f0bc   Antonio Terceiro   Separating the sa...
7
8

places = [
6a8fe6bb   Aurelio A. Heckert   Add state for som...
9
  { :country=>'BR', :state=>'Bahia',        :city=>'Salvador',
21b4f0bc   Antonio Terceiro   Separating the sa...
10
    :lat=>-12.94032, :lng=>-38.58398  },
6a8fe6bb   Aurelio A. Heckert   Add state for som...
11
12
13
  { :country=>'BR', :state=>'Bahia',        :city=>'Feira de Santana',
    :lat=>-12.25547, :lng=>-38.95430  },
  { :country=>'BR', :state=>'São Paulo',    :city=>'São Paulo',
21b4f0bc   Antonio Terceiro   Separating the sa...
14
    :lat=>-23.54894, :lng=>-46.63881  },
6a8fe6bb   Aurelio A. Heckert   Add state for som...
15
16
17
  { :country=>'BR', :state=>'Rio de Janeiro', :city=>'Petrópolis',
    :lat=>-22.50462, :lng=>-43.18232  },
  { :country=>'AR', :state=>'A.C.',         :city=>'Buenos Aires',
21b4f0bc   Antonio Terceiro   Separating the sa...
18
    :lat=>-34.61088, :lng=>-58.39782  },
6a8fe6bb   Aurelio A. Heckert   Add state for som...
19
  { :country=>'AR', :state=>'Buenos Aires', :city=>'Mar del Plata',
21b4f0bc   Antonio Terceiro   Separating the sa...
20
    :lat=>-37.98317, :lng=>-57.59513  },
6a8fe6bb   Aurelio A. Heckert   Add state for som...
21
  { :country=>'MX', :state=>'Guerrero',     :city=>'Acapulco',
21b4f0bc   Antonio Terceiro   Separating the sa...
22
    :lat=>16.86369,  :lng=>-99.88151  },
6a8fe6bb   Aurelio A. Heckert   Add state for som...
23
  { :country=>'US', :state=>'California',   :city=>'Los Angeles',
21b4f0bc   Antonio Terceiro   Separating the sa...
24
    :lat=>34.02307,  :lng=>-118.24310 },
6a8fe6bb   Aurelio A. Heckert   Add state for som...
25
26
  { :country=>'US', :state=>'Florida',      :city=>'Jacksonville',
    :lat=>30.33217,  :lng=>-81.65566 },
21b4f0bc   Antonio Terceiro   Separating the sa...
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  { :country=>'IT', :city=>'Roma',
    :lat=>41.89512,  :lng=>12.48184   },
  { :country=>'IN', :city=>'Mumbai',
    :lat=>19.01798,  :lng=>72.85583   },
  { :country=>'CN', :city=>'Shanghai',
    :lat=>31.23041,  :lng=>121.47308  },
  { :country=>'JP', :city=>'Tokyo',
    :lat=>35.68964,  :lng=>139.69116  },
  { :country=>'FR', :city=>'Paris',
    :lat=>48.85658,  :lng=>2.351074   },
  { :country=>'BW', :city=>'Sowa',
    :lat=>-20.56891, :lng=>26.22367   }
]

people = []
NAMES = %w[ José João Antonio Paulo Maria Joana Paula Angela ]
SURNAMES = %w[ Silva Santos Abreu Oliveira Machado Bonfim  ]
print "Creating users: "
for name in NAMES
  for surname in SURNAMES
    full_name = [name, surname].join(' ')
27ab82a7   Joenio Costa   Refactoring sampl...
48
    user = User.new({
21b4f0bc   Antonio Terceiro   Separating the sa...
49
50
51
52
      :login => full_name.to_slug,
      :email => full_name.to_slug + '@localhost.localdomain',
      :password => 'test',
      :password_confirmation => 'test',
27ab82a7   Joenio Costa   Refactoring sampl...
53
      :environment => $environment,
21b4f0bc   Antonio Terceiro   Separating the sa...
54
    })
27ab82a7   Joenio Costa   Refactoring sampl...
55
56
57
58
    save user do
      user.person.name = full_name
      place = places[rand(places.length)]
      user.person.data[:country] = place[:country]
6a8fe6bb   Aurelio A. Heckert   Add state for som...
59
      user.person.state = place[:state]
27ab82a7   Joenio Costa   Refactoring sampl...
60
61
62
63
      user.person.city = place[:city]
      user.person.lat = place[:lat] + (rand/100)-0.005
      user.person.lng = place[:lng] + (rand/100)-0.005
      user.person.save!
855b73d2   Rodrigo Souto   Fixing crashes on...
64
65
      if categories.present?
        2.times do
b0c41ba1   Victor Costa   rails3: fix sampl...
66
          category = categories.sample
c795cd5d   juniorsilva   script-sample-dat...
67
          user.person.add_category category unless category.people.include?(user.person)
855b73d2   Rodrigo Souto   Fixing crashes on...
68
69
        end
      end
27ab82a7   Joenio Costa   Refactoring sampl...
70
    end
21b4f0bc   Antonio Terceiro   Separating the sa...
71
72
  end
end
27ab82a7   Joenio Costa   Refactoring sampl...
73
74
75
76
77
78
79
80
81
82
ze = User.new({
  :login => "ze",
  :email => 'root@localhost.localdomain',
  :password => 'test',
  :password_confirmation => 'test',
  :environment => $environment,
})
save ze do
  $environment.add_admin(ze.person)
end
21b4f0bc   Antonio Terceiro   Separating the sa...
83

27ab82a7   Joenio Costa   Refactoring sampl...
84
85
86
87
88
89
90
91
92
93
admin = User.new({
  :login => "adminuser",
  :email => 'adminuser@localhost.localdomain',
  :password => 'admin',
  :password_confirmation => 'admin',
  :environment => $environment,
})
save admin do
  $environment.add_admin(admin.person)
end
6fba3990   Daniela Feitosa   Merge commit 'ref...
94
95
96
97
98
99
100
101

guest = User.new({
  :login => "guest",
  :email => 'guest@localhost.localdomain',
  :password => 'test',
  :password_confirmation => 'test',
  :environment => $environment,
})
855b73d2   Rodrigo Souto   Fixing crashes on...
102
103
save guest

1de7c12e   Joenio Costa   Fixing users acti...
104
105
106
done

print "Activating users: "
a1dad6ba   Braulio Bhavamitra   rails4: replace :...
107
User.where("login NOT LIKE '%%_template'").each do |user|
1de7c12e   Joenio Costa   Fixing users acti...
108
109
110
  user.activate
  print '.'
end
27ab82a7   Joenio Costa   Refactoring sampl...
111
done
21b4f0bc   Antonio Terceiro   Separating the sa...
112

27ab82a7   Joenio Costa   Refactoring sampl...
113
people = $environment.people
21b4f0bc   Antonio Terceiro   Separating the sa...
114
115
print "Creating some friendships: "
rand(people.size * 3).times do
b0c41ba1   Victor Costa   rails3: fix sampl...
116
117
  from = people.sample
  to = people.sample
21b4f0bc   Antonio Terceiro   Separating the sa...
118
  if from != to && !from.friends.include?(to)
27ab82a7   Joenio Costa   Refactoring sampl...
119
120
121
122
    task = AddFriend.new(:requestor => to, :target => from)
    save task do
      task.finish
    end
21b4f0bc   Antonio Terceiro   Separating the sa...
123
124
125
  end
  print '.'
end
27ab82a7   Joenio Costa   Refactoring sampl...
126
done
21b4f0bc   Antonio Terceiro   Separating the sa...
127
128
129
130
131
132
133
134
135


communities = []
VERBS = ['Save', 'I like', 'Use']
STUFF = ['Free Software', 'Organic food', 'the wales', 'the environment']
print "Creating communities: "
for verb in VERBS
  for stuff in STUFF
    name = [verb, stuff].join(' ')
27ab82a7   Joenio Costa   Refactoring sampl...
136
    community = Community.new(:name => name, :environment => $environment)
6a8fe6bb   Aurelio A. Heckert   Add state for som...
137
138
139
140
141
142
    if rand(2)==1 # not all communities must have a place
      place = places[rand(places.length)]
      community.data[:country] = place[:country]
      community.state = place[:state]
      community.city = place[:city]
    end
27ab82a7   Joenio Costa   Refactoring sampl...
143
144
145
    save community do
      communities << community
      rand(10).times do
b0c41ba1   Victor Costa   rails3: fix sampl...
146
        person = people.sample
855b73d2   Rodrigo Souto   Fixing crashes on...
147
148
149
150
        community.add_member(person) unless community.members.include?(person)
      end
      if categories.present?
        2.times do
b0c41ba1   Victor Costa   rails3: fix sampl...
151
          category = categories.sample
c795cd5d   juniorsilva   script-sample-dat...
152
          community.add_category category unless category.communities.include?(community)
855b73d2   Rodrigo Souto   Fixing crashes on...
153
        end
27ab82a7   Joenio Costa   Refactoring sampl...
154
      end
21b4f0bc   Antonio Terceiro   Separating the sa...
155
    end
21b4f0bc   Antonio Terceiro   Separating the sa...
156
157
  end
end
855b73d2   Rodrigo Souto   Fixing crashes on...
158
159

5.times do
b0c41ba1   Victor Costa   rails3: fix sampl...
160
  community = communities.sample
855b73d2   Rodrigo Souto   Fixing crashes on...
161
162
163
164
  community.add_member(guest.person) unless community.members.include?(guest.person)
  community.add_admin(guest.person) unless community.admins.include?(guest.person)
end

27ab82a7   Joenio Costa   Refactoring sampl...
165
done