fake_friends 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/dev/pull_from_twitter.rb +116 -0
- data/dev/usernames.yml +202 -0
- data/fake_friends.gemspec +30 -0
- data/lib/fake_friends.rb +80 -0
- data/lib/fake_friends/users.yml +6943 -0
- data/lib/fake_friends/version.rb +3 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5159c5ac6e51192def23c97dd3df200b58422654
|
4
|
+
data.tar.gz: a06642226fda12364617bbcee70f2ba2c839a20a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 63557e8211a9989bcd04b22bc39c8e5a38378077769b7113dbe6728663b9224069f907d2a35842d02280005db4a566bed49da647215e824c5403de2430da4595
|
7
|
+
data.tar.gz: f5cf11ef7c29b67e25b16b4653b3c5802f78909e169d90491f76574b7efb17b33fcb90c1eee750d3ebd0a9591ff999a675ce895f1b074de28ae9758d78310e70
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jake Romer
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# FakeFriends
|
2
|
+
|
3
|
+
A ruby gem for generating consistent fake user data (for demoing social networking apps.)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'fake_friends'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install fake_friends
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Instructions on the way.
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'twitter'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
# TODO: Method to pull a user from Twitter directly into FakeFriend.find_by(username)
|
5
|
+
|
6
|
+
puts 'Enter your Twitter API credentials (get some @ dev.twitter.com).'
|
7
|
+
print 'consumer key: '
|
8
|
+
twitter_cons_key = gets.chomp
|
9
|
+
print 'consumer secret: '
|
10
|
+
twitter_cons_sec = gets.chomp
|
11
|
+
print 'oauth token: '
|
12
|
+
twitter_auth_tok = gets.chomp
|
13
|
+
print 'oauth token secret: '
|
14
|
+
twitter_auth_sec = gets.chomp
|
15
|
+
|
16
|
+
Twitter.configure do |config|
|
17
|
+
config.consumer_key = twitter_cons_key
|
18
|
+
config.consumer_secret = twitter_cons_sec
|
19
|
+
config.oauth_token = twitter_auth_tok
|
20
|
+
config.oauth_token_secret = twitter_auth_sec
|
21
|
+
end
|
22
|
+
|
23
|
+
# returns array of non-retweets with time and text
|
24
|
+
def posts(twitter_username, count)
|
25
|
+
options = { count: count, exclude_replies: true }
|
26
|
+
|
27
|
+
Twitter.user_timeline(twitter_username, options)
|
28
|
+
.delete_if{ |t| t.retweeted || (t.text =~ /^RT\s@/) } # remove retweets
|
29
|
+
.map do |tweet|
|
30
|
+
{ time: tweet.created_at, text: tweet.text }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
number_of_users_to_pull = 100
|
36
|
+
number_of_posts_to_pull = 50
|
37
|
+
|
38
|
+
usernames = 'usernames.yml'
|
39
|
+
users = File.open(usernames, 'r'){|file| YAML.load(file, usernames) }
|
40
|
+
users = users.sample(number_of_users_to_pull)
|
41
|
+
friends = {}
|
42
|
+
|
43
|
+
users.each_with_index do |u, i|
|
44
|
+
## Ensure user exists and tweets are public
|
45
|
+
if Twitter.user?(u)
|
46
|
+
unless Twitter.user(u).protected?
|
47
|
+
|
48
|
+
# load user
|
49
|
+
user = Twitter.user(u)
|
50
|
+
|
51
|
+
# pull 100 posts
|
52
|
+
posts = posts(u, number_of_posts_to_pull)
|
53
|
+
|
54
|
+
# get urls if they exist
|
55
|
+
begin
|
56
|
+
expanded_url = user.attrs[:entities][:url][:urls].first[:expanded_url]
|
57
|
+
rescue
|
58
|
+
expanded_url = nil
|
59
|
+
end
|
60
|
+
|
61
|
+
begin
|
62
|
+
display_url = user.attrs[:entities][:url][:urls].first[:display_url]
|
63
|
+
rescue
|
64
|
+
display_url = nil
|
65
|
+
end
|
66
|
+
|
67
|
+
# populate friends hash
|
68
|
+
friends[u] = {
|
69
|
+
name: user.name,
|
70
|
+
location: user.location,
|
71
|
+
description: user.description,
|
72
|
+
url: { expanded: expanded_url, display: display_url },
|
73
|
+
image: user.profile_image_url,
|
74
|
+
posts: posts
|
75
|
+
}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# write to file as yaml
|
80
|
+
users_lib = '../lib/fake_friends/users.yml'
|
81
|
+
File.open(users_lib, 'w'){|f| f.write(friends.to_yaml) }
|
82
|
+
puts "loaded #{i+1}: #{u}"
|
83
|
+
|
84
|
+
if number_of_users_to_pull <= 75
|
85
|
+
# Twitter API limit: 15 per 15 minutes
|
86
|
+
if (i+1 % 15 == 0)
|
87
|
+
puts "taking a 15-minute power nap to stay within Twitter API rate limits..."
|
88
|
+
|
89
|
+
clock =<<-SHELL
|
90
|
+
MIN=15
|
91
|
+
for i in $(seq $(($MIN*60)) -1 1);
|
92
|
+
do
|
93
|
+
printf "\r%02d:%02d:%02d" $((i/3600)) $(( (i/60)%60)) $((i%60));
|
94
|
+
sleep 1;
|
95
|
+
done
|
96
|
+
SHELL
|
97
|
+
|
98
|
+
system(clock)
|
99
|
+
puts ""
|
100
|
+
end
|
101
|
+
else
|
102
|
+
puts "taking a 1-minute power nap to stay within Twitter API rate limits..."
|
103
|
+
|
104
|
+
clock =<<-SHELL
|
105
|
+
MIN=1
|
106
|
+
for i in $(seq $(($MIN*60)) -1 1);
|
107
|
+
do
|
108
|
+
printf "\r%02d:%02d:%02d" $((i/3600)) $(( (i/60)%60)) $((i%60));
|
109
|
+
sleep 1;
|
110
|
+
done
|
111
|
+
SHELL
|
112
|
+
|
113
|
+
system(clock)
|
114
|
+
puts ""
|
115
|
+
end
|
116
|
+
end
|
data/dev/usernames.yml
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
---
|
2
|
+
- idiot
|
3
|
+
- lukasoppermann
|
4
|
+
- claudioguglieri
|
5
|
+
- mizko
|
6
|
+
- jesseddy
|
7
|
+
- lepinski
|
8
|
+
- ryanAmurphy
|
9
|
+
- mozato
|
10
|
+
- nicklacke
|
11
|
+
- ChrisFarina78
|
12
|
+
- lepetitogre
|
13
|
+
- jpadilla_
|
14
|
+
- mocabyte
|
15
|
+
- sjoerd_dijkstra
|
16
|
+
- snowshade
|
17
|
+
- macvhustle
|
18
|
+
- jitachi
|
19
|
+
- _pedropinho
|
20
|
+
- herrhaase
|
21
|
+
- markwienands
|
22
|
+
- meghanglass
|
23
|
+
- gravityonmars
|
24
|
+
- rizwanjavaid
|
25
|
+
- gabrielvaldivia
|
26
|
+
- ogvidius
|
27
|
+
- alagoon
|
28
|
+
- brianmaloney
|
29
|
+
- mds
|
30
|
+
- eugeneeweb
|
31
|
+
- edmondyang
|
32
|
+
- alek_djuric
|
33
|
+
- poopsplat
|
34
|
+
- Anotherdagou
|
35
|
+
- Chakintosh
|
36
|
+
- alexivanichkin
|
37
|
+
- faridelnasire
|
38
|
+
- meddeg
|
39
|
+
- jordyvdboom
|
40
|
+
- kolage
|
41
|
+
- ormanclark
|
42
|
+
- maiklam
|
43
|
+
- hsinyo23
|
44
|
+
- DesignerDusko
|
45
|
+
- keryilmaz
|
46
|
+
- damenleeturks
|
47
|
+
- jcarlosweb
|
48
|
+
- petrangr
|
49
|
+
- OskarLevinson
|
50
|
+
- odaymashalla
|
51
|
+
- devstrong
|
52
|
+
- danro
|
53
|
+
- dorinvancea
|
54
|
+
- victorerixon
|
55
|
+
- denykhoung
|
56
|
+
- zainiafzan
|
57
|
+
- rob_thomas10
|
58
|
+
- WhatTheFerguson
|
59
|
+
- BillSKenney
|
60
|
+
- mufaddal_mw
|
61
|
+
- ed_lea
|
62
|
+
- Rafa3mil
|
63
|
+
- mambows
|
64
|
+
- de_ascanio
|
65
|
+
- nyeauls
|
66
|
+
- SiskaFlaurensia
|
67
|
+
- YoungCutlass
|
68
|
+
- psdesignuk
|
69
|
+
- yayteejay
|
70
|
+
- ZanderSays
|
71
|
+
- bluesix
|
72
|
+
- leevigraham
|
73
|
+
- dotgridline
|
74
|
+
- bassamology
|
75
|
+
- uxpiper
|
76
|
+
- mekal
|
77
|
+
- simobenso
|
78
|
+
- _scottburgess
|
79
|
+
- stevedesigner
|
80
|
+
- sur4dye
|
81
|
+
- arjunchetna
|
82
|
+
- davidsasda
|
83
|
+
- yashi_el
|
84
|
+
- jayrobinson
|
85
|
+
- buryaknick
|
86
|
+
- RussellBishop
|
87
|
+
- andrewabogado
|
88
|
+
- shanehudson
|
89
|
+
- finchjke
|
90
|
+
- chris_witko
|
91
|
+
- IsaryAmairani
|
92
|
+
- craigrcoles
|
93
|
+
- kkusaa
|
94
|
+
- ZacharyZorbas
|
95
|
+
- jonkspr
|
96
|
+
- iamjamie
|
97
|
+
- jsngr
|
98
|
+
- timothycd
|
99
|
+
- borges_marcos
|
100
|
+
- rahmeen
|
101
|
+
- claudiu_cons
|
102
|
+
- wiljanslofstra
|
103
|
+
- joshhemsley
|
104
|
+
- decarola
|
105
|
+
- ethanzhang
|
106
|
+
- nastya_mane
|
107
|
+
- bublienko
|
108
|
+
- ralph_lam
|
109
|
+
- divya
|
110
|
+
- feliperibeiros
|
111
|
+
- psaikali
|
112
|
+
- calvintennant
|
113
|
+
- brampitoyo
|
114
|
+
- calebogden
|
115
|
+
- mdsisto
|
116
|
+
- motherfuton
|
117
|
+
- fran_mchamy
|
118
|
+
- bu7921
|
119
|
+
- prekesh
|
120
|
+
- emmeffess
|
121
|
+
- kojourin
|
122
|
+
- sweetdelisa
|
123
|
+
- sajtoo
|
124
|
+
- chadengle
|
125
|
+
- renatolz
|
126
|
+
- fabioChannel
|
127
|
+
- thibaud_be
|
128
|
+
- phillapier
|
129
|
+
- xripunov
|
130
|
+
- JeffChausse
|
131
|
+
- sgaurav_baghel
|
132
|
+
- dpmachado
|
133
|
+
- angelceballos
|
134
|
+
- ntfblog
|
135
|
+
- evil_trout
|
136
|
+
- Mr_Stezz
|
137
|
+
- nckjrvs
|
138
|
+
- andyisonline
|
139
|
+
- paul_irish
|
140
|
+
- marakasina
|
141
|
+
- iamlouisbullock
|
142
|
+
- renbyrd
|
143
|
+
- saulihirvi
|
144
|
+
- lukejones
|
145
|
+
- muringa
|
146
|
+
- michaelmartinho
|
147
|
+
- zulsdesign
|
148
|
+
- jjmpsp
|
149
|
+
- temonehm
|
150
|
+
- ultragex
|
151
|
+
- areus
|
152
|
+
- salvafc
|
153
|
+
- aaronbushnell
|
154
|
+
- baliomega
|
155
|
+
- dnezkumar
|
156
|
+
- mtolokonnikov
|
157
|
+
- _mrdidi
|
158
|
+
- grigy
|
159
|
+
- helderleal
|
160
|
+
- ninjad3m0
|
161
|
+
- jayman
|
162
|
+
- jacksonlatka
|
163
|
+
- cacestgang
|
164
|
+
- imfine_thankyou
|
165
|
+
- gilbertglee
|
166
|
+
- nicollerich
|
167
|
+
- LucasPerdidao
|
168
|
+
- 2fockus
|
169
|
+
- antongenkin
|
170
|
+
- ky
|
171
|
+
- BeStrangers
|
172
|
+
- shalt0ni
|
173
|
+
- pkhoosh
|
174
|
+
- the_purplebunny
|
175
|
+
- brianmacco
|
176
|
+
- dvidsilva
|
177
|
+
- sta1ex
|
178
|
+
- CrafterSama
|
179
|
+
- kirkouimet
|
180
|
+
- djsherman
|
181
|
+
- marshallchen_
|
182
|
+
- flashmurphy
|
183
|
+
- mkalalang
|
184
|
+
- anoff
|
185
|
+
- WillsB3
|
186
|
+
- nimaa
|
187
|
+
- andreas_pr
|
188
|
+
- FreelanceNathan
|
189
|
+
- alexdraeth
|
190
|
+
- joki4
|
191
|
+
- fffabs
|
192
|
+
- dbox
|
193
|
+
- hugocornejo
|
194
|
+
- BhargavJoshee
|
195
|
+
- charlesrpratt
|
196
|
+
- lisovsky
|
197
|
+
- antonyzotov
|
198
|
+
- arpitnj
|
199
|
+
- S0ufi4n3
|
200
|
+
- mrettenbacher
|
201
|
+
- g3d
|
202
|
+
---
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fake_friends/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fake_friends"
|
8
|
+
spec.version = FalseFriends::VERSION
|
9
|
+
spec.authors = ["Jake Romer"]
|
10
|
+
spec.email = ["jake@jakeromer.com"]
|
11
|
+
spec.description = %q{A simple fake user generator}
|
12
|
+
spec.summary = %q{Generates fake users with consistent
|
13
|
+
attributes, up to 30 from local dictionary,
|
14
|
+
up to 100 pulling fresh data using the Twitter gem}
|
15
|
+
spec.homepage = "http://github.com/jmromer/FakeFriends"
|
16
|
+
spec.license = "MIT"
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
# TO BE ADDED
|
23
|
+
# spec.add_runtime_dependency "twitter", "~> 4.8.1"
|
24
|
+
|
25
|
+
spec.add_development_dependency "twitter", "~> 4.8.1"
|
26
|
+
# spec.add_development_dependency "rspec"
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
29
|
+
spec.add_development_dependency "rake"
|
30
|
+
end
|
data/lib/fake_friends.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
begin
|
2
|
+
require "fake_friends/version"
|
3
|
+
require 'yaml'
|
4
|
+
rescue LoadError
|
5
|
+
end
|
6
|
+
|
7
|
+
module FakeFriends
|
8
|
+
|
9
|
+
class FakeFriend
|
10
|
+
attr_reader :username, :name, :location, :description, :url, :posts
|
11
|
+
|
12
|
+
# Friend.gather(n)
|
13
|
+
# returns an array of n user objects
|
14
|
+
def self.gather(n)
|
15
|
+
users_to_create = FakeFriend.list.keys.sample(n)
|
16
|
+
users_to_create.map{ |username| FakeFriend.new(username) }
|
17
|
+
end
|
18
|
+
|
19
|
+
# FakeFriend.find_by(options)
|
20
|
+
#
|
21
|
+
# options <hash>
|
22
|
+
# id: n <int>
|
23
|
+
# position in the users list, 1-100
|
24
|
+
#
|
25
|
+
# username: str <string>
|
26
|
+
# twitter username
|
27
|
+
#
|
28
|
+
# Example: FakeFriend.find_by(id: 100)
|
29
|
+
# => #<User:0x007ff0f286e2d8 ...>
|
30
|
+
#
|
31
|
+
# returns the requested user object
|
32
|
+
|
33
|
+
def self.find_by(options)
|
34
|
+
if options[:id] && options[:id].between?(1, FakeFriend.list.count)
|
35
|
+
username = FakeFriend.list.keys[options[:id]-1]
|
36
|
+
FakeFriend.new(username)
|
37
|
+
elsif options[:username] && FakeFriend.list.keys.include?(options[:username])
|
38
|
+
FakeFriend.new(options[:username])
|
39
|
+
else
|
40
|
+
raise ArgumentError, "Requested user not found in library."
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# FakeFriend.new(username)
|
45
|
+
#
|
46
|
+
# username <string>
|
47
|
+
# twitter username
|
48
|
+
#
|
49
|
+
# returns user object
|
50
|
+
|
51
|
+
def initialize(username)
|
52
|
+
@username = username
|
53
|
+
@name = FakeFriend.list[username][:name]
|
54
|
+
@location = FakeFriend.list[username][:location]
|
55
|
+
@description = FakeFriend.list[username][:description]
|
56
|
+
@url = FakeFriend.list[username][:url]
|
57
|
+
@posts = FakeFriend.list[username][:posts]
|
58
|
+
end
|
59
|
+
|
60
|
+
# avatar_url(size)
|
61
|
+
# returns the user's uiFaces url in the closest available size
|
62
|
+
def avatar_url(size)
|
63
|
+
valid_sizes = [128, 64, 48, 24]
|
64
|
+
size = valid_sizes.min { |a,b| (size-a).abs <=> (size-b).abs }
|
65
|
+
"https://s3.amazonaws.com/uifaces/faces/twitter/#{username}/#{size}.jpg"
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
mydir = File.expand_path(File.dirname(__FILE__))
|
70
|
+
libary_file = mydir + '/fake_friends/users.yml'
|
71
|
+
@friends_list = File.open(libary_file, 'r'){|f| YAML.load(f) }
|
72
|
+
|
73
|
+
def self.list
|
74
|
+
@friends_list
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
|