pork_sandwich 0.4.4 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +21 -0
- data/VERSION +1 -1
- data/generators/pork_sandwich_migration/templates/migration.rb +2 -1
- data/lib/pork_sandwich/crawler.rb +0 -5
- data/lib/pork_sandwich/puller.rb +4 -7
- data/lib/pork_sandwich/saver.rb +1 -8
- data/lib/pork_sandwich/search.rb +3 -3
- data/lib/pork_sandwich.rb +2 -1
- data/test/puller_test.rb +0 -2
- data/test/saver_test.rb +0 -2
- metadata +1 -2
- data/lib/pork_sandwich/config.rb +0 -3
data/README
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
--README--
|
2
|
+
|
3
|
+
How to get started:
|
4
|
+
|
5
|
+
1. Create a new rails project
|
6
|
+
|
7
|
+
2. Drop this into config/environment.rb (after the Rails::Initializer.run do |config| line, but before the "end" statement of that block)
|
8
|
+
config.gem "pork_sandwich", :version => ">=0.4.5"
|
9
|
+
|
10
|
+
3. rake gems:install
|
11
|
+
or
|
12
|
+
sudo rake gems:install
|
13
|
+
|
14
|
+
4. script/generate pork_sandwich_models
|
15
|
+
|
16
|
+
5. script/generate pork_sandwich_migration
|
17
|
+
|
18
|
+
6. rake db:migrate
|
19
|
+
(may have to comment the seed and with timestamp stuff out in the migration. See recommendations)
|
20
|
+
|
21
|
+
Pork Classes and db Objects can now be referenced throughout your project. See below for a description of the database schema and pulling methods. Happy porking.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.5
|
@@ -122,9 +122,10 @@ class PorkSandwichMigration < ActiveRecord::Migration
|
|
122
122
|
"alter column created_at type timestamp with time zone;"
|
123
123
|
execute "alter table tweet_reactions " +
|
124
124
|
"alter column updated_at type timestamp with time zone;"
|
125
|
-
rescue
|
125
|
+
rescue => e
|
126
126
|
puts e + "\n" + "Migration failed to change timestamp column data types pork_sandwich tables. Attempted to change all timestamp without time zone types to timestamp with time zone types. Tables will still properly process and store time zone data for timestamps, but will not export UTC offset on COPY to."
|
127
127
|
end
|
128
|
+
|
128
129
|
reaction_types = ['retweet', 'mention', 'reply']
|
129
130
|
reaction_types.each do |r|
|
130
131
|
unless Reaction.find_by_reaction_type(r)
|
@@ -58,24 +58,20 @@ module Pork
|
|
58
58
|
end
|
59
59
|
|
60
60
|
SEARCH_CRAWL = lambda do |user, search_query, count|
|
61
|
-
$LOG.info "SEARCH CRAWL"
|
62
61
|
$TWITERATOR.twiterate({:collect_users => true}, {:search_query => search_query}, &SEARCH_ITER)
|
63
62
|
# @users.keys
|
64
63
|
search_query
|
65
64
|
end
|
66
65
|
|
67
66
|
FOLLOWER_IDS_CRAWL = lambda do |user, search_query, count|
|
68
|
-
$LOG.info "FOLLOWER IDS CRAWL"
|
69
67
|
$PULLER.pull({:user_id => user, :collect_users => true}, &FOLLOWER_IDS_PULL)
|
70
68
|
end
|
71
69
|
|
72
70
|
FRIEND_IDS_CRAWL = lambda do |user, search_query, count|
|
73
|
-
$LOG.info "FRIEND IDS CRAWL"
|
74
71
|
$PULLER.pull({:user_id => user, :collect_users => true}, &FRIEND_IDS_PULL)
|
75
72
|
end
|
76
73
|
|
77
74
|
FOLLOWERS_CRAWL = lambda do |user, search_query, count|
|
78
|
-
$LOG.info "FOLLOWERS CRAWL"
|
79
75
|
if not user.db_object
|
80
76
|
user.db_object = $PULLER.pull({:user => user}, &USER_PULL)
|
81
77
|
end
|
@@ -83,7 +79,6 @@ FOLLOWERS_CRAWL = lambda do |user, search_query, count|
|
|
83
79
|
end
|
84
80
|
|
85
81
|
FRIENDS_CRAWL = lambda do |user, search_query, count|
|
86
|
-
$LOG.info "FRIENDS CRAWL"
|
87
82
|
if not user.db_object
|
88
83
|
user.db_object = $PULLER.pull({:user => user}, &USER_PULL)
|
89
84
|
end
|
data/lib/pork_sandwich/puller.rb
CHANGED
@@ -12,19 +12,19 @@ module Pork
|
|
12
12
|
pull_type.call(@user, @auth_object)
|
13
13
|
# rescue Twitter::Unauthorized
|
14
14
|
rescue Twitter::Unavailable
|
15
|
-
|
15
|
+
p "ERROR: Twitter unavailable, trying in 60"
|
16
16
|
sleep 60
|
17
17
|
retry
|
18
18
|
rescue Twitter::NotFound
|
19
|
-
|
19
|
+
p "ERROR: Info target not found, trying to skip"
|
20
20
|
# rescue Crack::ParseError
|
21
21
|
# raise Crack::ParseError
|
22
22
|
rescue Errno::ETIMEDOUT
|
23
|
-
|
23
|
+
p "ERROR: Puller timed out, retrying in 10"
|
24
24
|
sleep 10
|
25
25
|
retry
|
26
26
|
rescue Twitter::InformTwitter
|
27
|
-
|
27
|
+
p "ERROR: Twitter internal error, retrying in 30"
|
28
28
|
sleep 30
|
29
29
|
retry
|
30
30
|
end
|
@@ -37,7 +37,6 @@ end
|
|
37
37
|
|
38
38
|
|
39
39
|
ACCOUNT_INFO = lambda do |user, auth_object|
|
40
|
-
$LOG.info "USER PULL"
|
41
40
|
@pull_data = auth_object.user(user.search)
|
42
41
|
{:pull_data => @pull_data, :db_object => $SAVER.save(@pull_data, &TWITTER_ACCOUNT_SAVE)}
|
43
42
|
end
|
@@ -117,7 +116,6 @@ FRIEND_IDS = lambda do |user, auth_object|
|
|
117
116
|
end
|
118
117
|
|
119
118
|
TWEETS = lambda do |user, auth_object|
|
120
|
-
$LOG.info "USER TWEETS PULL"
|
121
119
|
rules = {:count => 200}
|
122
120
|
if user.twitter_id
|
123
121
|
rules[:user_id] = user.twitter_id
|
@@ -134,7 +132,6 @@ TWEETS = lambda do |user, auth_object|
|
|
134
132
|
end
|
135
133
|
|
136
134
|
TRENDS_PULL = lambda do |rules, auth_object|
|
137
|
-
$LOG.info "TRENDS PULL"
|
138
135
|
Twitter::Trends.current().each do |trend|
|
139
136
|
$SAVER.save({:name => trend.name, :query => trend.query}, &TREND_SAVE)
|
140
137
|
end
|
data/lib/pork_sandwich/saver.rb
CHANGED
@@ -20,7 +20,6 @@ module Pork
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
TWEET_SAVE = lambda do |tweet_to_save, rules|
|
23
|
-
$LOG.debug "TWEET SAVE"
|
24
23
|
tweet = Tweet.new(:text => tweet_to_save.text,
|
25
24
|
:time_of_tweet => tweet_to_save.created_at,
|
26
25
|
:to_user_id_search => tweet_to_save.to_user_id,
|
@@ -49,7 +48,6 @@ TWEET_SAVE = lambda do |tweet_to_save, rules|
|
|
49
48
|
end
|
50
49
|
|
51
50
|
USER_TWEET_SAVE = lambda do |tweet_to_save, rules|
|
52
|
-
$LOG.debug "USER TWEET SAVE"
|
53
51
|
tweet = Tweet.new(:text => tweet_to_save.text,
|
54
52
|
:time_of_tweet => tweet_to_save.created_at,
|
55
53
|
:to_user_id => tweet_to_save.in_reply_to_user_id,
|
@@ -72,7 +70,6 @@ USER_TWEET_SAVE = lambda do |tweet_to_save, rules|
|
|
72
70
|
tweet
|
73
71
|
end
|
74
72
|
TWITTER_ACCOUNT_SAVE = lambda do |twitter_account_to_save, rules|
|
75
|
-
$LOG.debug "TWITTER ACCOUNT SAVE"
|
76
73
|
if twitter_account_to_save.class == Pork::TwitterUser
|
77
74
|
twitter_account_attribute_hash = {:twitter_id => twitter_account_to_save.twitter_id,
|
78
75
|
:screen_name => twitter_account_to_save.twitter_screen_name}
|
@@ -135,7 +132,6 @@ TWITTER_ACCOUNT_SAVE = lambda do |twitter_account_to_save, rules|
|
|
135
132
|
|
136
133
|
end
|
137
134
|
CALL_SAVE = lambda do |call_to_save, rules|
|
138
|
-
$LOG.debug "CALL SAVE"
|
139
135
|
call = Call.new(:query => call_to_save.query,
|
140
136
|
:completed_in => call_to_save.completed_in,
|
141
137
|
:since_id => call_to_save.since_id,
|
@@ -155,7 +151,6 @@ CALL_SAVE = lambda do |call_to_save, rules|
|
|
155
151
|
end
|
156
152
|
|
157
153
|
RELATIONSHIP_SAVE = lambda do |users_to_save, rules|
|
158
|
-
$LOG.debug "RELATIONSHIP SAVE"
|
159
154
|
follower = users_to_save[:follower]
|
160
155
|
friend = users_to_save[:friend]
|
161
156
|
|
@@ -179,9 +174,7 @@ end
|
|
179
174
|
|
180
175
|
|
181
176
|
REACTION_SAVE = lambda do |reaction_to_save, rules|
|
182
|
-
|
183
|
-
|
184
|
-
|
177
|
+
|
185
178
|
initiator = reaction_to_save[:initiator]
|
186
179
|
responder = reaction_to_save[:responder]
|
187
180
|
tweet = reaction_to_save[:tweet]
|
data/lib/pork_sandwich/search.rb
CHANGED
@@ -20,7 +20,7 @@ module Pork
|
|
20
20
|
@tweets_pulled.each do |tweet|
|
21
21
|
tweet.status_id = tweet.id
|
22
22
|
@db_ids_created << $SAVER.save(tweet, &TWEET_SAVE).id
|
23
|
-
$CRAWLER.append(tweet.from_user) if @collect_users
|
23
|
+
# $CRAWLER.append(tweet.from_user) if @collect_users
|
24
24
|
@current_count += 1
|
25
25
|
if reached_desired_count?
|
26
26
|
break
|
@@ -42,11 +42,11 @@ module Pork
|
|
42
42
|
p "Error: JSON Parsing error, trying to skip past problem tweet"
|
43
43
|
@search_params.query[:max_id] -= 1000
|
44
44
|
rescue Errno::ETIMEDOUT
|
45
|
-
|
45
|
+
p "ERROR: Puller timed out, retrying in 10"
|
46
46
|
sleep 10
|
47
47
|
retry
|
48
48
|
rescue Twitter::InformTwitter
|
49
|
-
|
49
|
+
p "ERROR: Twitter internal error, retrying in 30"
|
50
50
|
sleep 30
|
51
51
|
retry
|
52
52
|
# rescue NoMethodError
|
data/lib/pork_sandwich.rb
CHANGED
data/test/puller_test.rb
CHANGED
@@ -8,8 +8,6 @@ class PullerTest < Test::Unit::TestCase
|
|
8
8
|
@user_info_keys = ["created_at", "description", "favourites_count", "followers_count", "following", "friends_count", "geo_enabled", "id", "location", "name", "notifications", "profile_background_color", "profile_background_image_url", "profile_background_tile", "profile_image_url", "profile_link_color", "profile_sidebar_border_color", "profile_sidebar_fill_color", "profile_text_color", "protected", "screen_name", "status", "statuses_count", "time_zone", "url", "utc_offset", "verified"]
|
9
9
|
db_user_object = TwitterAccount.create({:twitter_id => 15019521,:screen_name => 'sam1vp'})
|
10
10
|
@test_user = Pork::TwitterUser.new(:twitter_id => 15019521, :db_object => db_user_object)
|
11
|
-
$LOG = Logger.new(STDOUT)
|
12
|
-
$LOG.level = Logger::INFO
|
13
11
|
end
|
14
12
|
|
15
13
|
should "be able to be created" do
|
data/test/saver_test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pork_sandwich
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Gilbert
|
@@ -56,7 +56,6 @@ files:
|
|
56
56
|
- generators/pork_sandwich_models/templates/models/twitter_relationship.rb
|
57
57
|
- lib/pork_sandwich.rb
|
58
58
|
- lib/pork_sandwich/auth.rb
|
59
|
-
- lib/pork_sandwich/config.rb
|
60
59
|
- lib/pork_sandwich/crawler.rb
|
61
60
|
- lib/pork_sandwich/log.rb
|
62
61
|
- lib/pork_sandwich/puller.rb
|
data/lib/pork_sandwich/config.rb
DELETED