sample-profiles
3.8 KB
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
71
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/environment'
include Noosfero::SampleDataHelper
categories = $environment.categories
places = [
  { :country=>'BR', :city=>'Salvador',
    :lat=>-12.94032, :lng=>-38.58398  },
  { :country=>'BR', :city=>'São Paulo',
    :lat=>-23.54894, :lng=>-46.63881  },
  { :country=>'BR', :city=>'Rio de Janeiro',
    :lat=>-22.90353, :lng=>-43.20958  },
  { :country=>'AR', :city=>'Buenos Aires',
    :lat=>-34.61088, :lng=>-58.39782  },
  { :country=>'AR', :city=>'Mar del Plata',
    :lat=>-37.98317, :lng=>-57.59513  },
  { :country=>'MX', :city=>'Acapulco',
    :lat=>16.86369,  :lng=>-99.88151  },
  { :country=>'US', :city=>'Los Angeles',
    :lat=>34.02307,  :lng=>-118.24310 },
  { :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(' ')
    user = User.new({
      :login => full_name.to_slug,
      :email => full_name.to_slug + '@localhost.localdomain',
      :password => 'test',
      :password_confirmation => 'test',
      :environment => $environment,
    })
    save user do
      user.person.name = full_name
      place = places[rand(places.length)]
      user.person.data[:country] = place[:country]
      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!
      categories.rand.people << user.person
      categories.rand.people << user.person
    end
  end
end
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
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
guest = User.new({
  :login => "guest",
  :email => 'guest@localhost.localdomain',
  :password => 'test',
  :password_confirmation => 'test',
  :environment => $environment,
})
save guest do
  5.times do
    communities.rand.add_admin(guest.person)
    communities.rand.add_member(guest.person)
  end
end
done
print "Activating users: "
User.all(:conditions => ["login NOT LIKE '%%_template'"]).each do |user|
  user.activate
  print '.'
end
done
people = $environment.people
print "Creating some friendships: "
rand(people.size * 3).times do
  from = people.rand
  to = people.rand
  if from != to && !from.friends.include?(to)
    task = AddFriend.new(:requestor => to, :target => from)
    save task do
      task.finish
    end
  end
  print '.'
end
done
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(' ')
    community = Community.new(:name => name, :environment => $environment)
    save community do
      communities << community
      rand(10).times do
        community.add_member(people.rand)
      end
      categories.rand.communities << community
      categories.rand.communities << community
    end
  end
end
done