pork_sandwich 0.4.8 → 0.4.9

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 CHANGED
@@ -16,6 +16,6 @@ sudo rake gems:install
16
16
  5. script/generate pork_sandwich_migration
17
17
 
18
18
  6. rake db:migrate
19
- (may have to comment the seed and with timestamp stuff out in the migration. See recommendations)
19
+ (may have to comment the "with timestamp" stuff out in the migration. Starts with "begin" and has a lot of execute statements in it.)
20
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.
21
+ Pork Classes and db Objects can now be referenced throughout your project. Happy porking.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.8
1
+ 0.4.9
@@ -1,7 +1,7 @@
1
1
  module Pork
2
2
  class Auth
3
3
  attr_accessor :auth
4
-
4
+ attr_reader :username, :password
5
5
  def initialize(username, password, user_agent = '')
6
6
  @auth = Twitter::Base.new(Twitter::HTTPAuth.new(username, password, :user_agent => user_agent))
7
7
  end
@@ -4,13 +4,13 @@ module Pork
4
4
 
5
5
  def initialize(output, options = {})
6
6
  @log = Logger.new(output)
7
- @log.level = "info"
8
- @researcher = options[:researcher] if options[:researcher]
9
- @project = options[:project] if options[:project]
7
+ @log.level = Logger::INFO
8
+ @researcher = options[:researcher]? options[:researcher] : ""
9
+ @project = options[:project]? options[:project] : ""
10
10
  end
11
11
 
12
12
  def write(message)
13
- @log.info("#{@project}, #{@researcher}, #{Time.now}: " + message)
13
+ @log.info("#{@project}, #{@researcher}, #{Time.now.to_s} -- " + message)
14
14
  end
15
15
  end
16
16
  end
@@ -72,7 +72,10 @@ FOLLOWER_IDS = lambda do |user, auth_object|
72
72
  @pull_data = auth_object.follower_ids({:user_id => user.twitter_id})
73
73
  @pull_data.each do |user_id|
74
74
  db_user_object = $SAVER.save(Pork::TwitterUser.new(:twitter_id => user_id), &TWITTER_ACCOUNT_SAVE)
75
- follower_relationship_db_ids << $SAVER.save({:friend => user, :follower => Pork::TwitterUser.new(:twitter_id => user_id, :db_object => db_user_object)}, &RELATIONSHIP_SAVE)
75
+ follower_relationship_db_ids << $SAVER.save({:friend => user,
76
+ :follower => Pork::TwitterUser.new(:twitter_id => user_id,
77
+ :db_object => db_user_object)},
78
+ &RELATIONSHIP_SAVE)
76
79
  end
77
80
  $SAVER.rules[:complete_follower_set] = false
78
81
  {:follower_relationship_db_ids => follower_relationship_db_ids}
@@ -0,0 +1,40 @@
1
+ module Pork
2
+ class RandomPuller
3
+
4
+ def self.pull(opts)
5
+
6
+
7
+ # if (!opts[:desired_count] and !opts[:duration_in_minutes]) or (opts[:desired_count] and opts[:duration_in_minutes])
8
+ # #raise an error that you must specify EITHER a :duration in minutes or a :desired_count
9
+ # end
10
+
11
+ # twitter_username = AppConfig.twitter_username
12
+ # twitter_password = AppConfig.twitter_password
13
+ #
14
+ # TweetStream::Client.new(twitter_username,twitter_password).track(Hashtag.search_string, :delete => Proc.new{ |status_id, user_id|}, :limit => Proc.new{ |skip_count| }) do |tweet|
15
+ # if tweet.geo.present? && tweet.geo.coordinates.present?
16
+ # latitude, longitude = *tweet.geo.coordinates
17
+ # else
18
+ # latitude, longitude = nil, nil
19
+ # end
20
+ # if Tweet.create(:tweet_id => tweet[:id],
21
+ # :text => tweet.text,
22
+ # :from_user => tweet.user.screen_name,
23
+ # :time_of_tweet => tweet.created_at,
24
+ # :to_user => tweet.in_reply_to_screen_name,
25
+ # :profile_image_url => tweet.user.profile_image_url,
26
+ # :source => tweet.source,
27
+ # :latitude => latitude,
28
+ # :longitude => longitude
29
+ # ).valid?
30
+ # p tweet.text
31
+ # end
32
+
33
+ end
34
+ end
35
+
36
+
37
+
38
+
39
+ end
40
+ end
@@ -154,7 +154,9 @@ RELATIONSHIP_SAVE = lambda do |users_to_save, rules|
154
154
  follower = users_to_save[:follower]
155
155
  friend = users_to_save[:friend]
156
156
 
157
- twitter_relationship = TwitterRelationship.new(:follower_id => follower.db_object.id, :friend_id => friend.db_object.id, :current => true)
157
+ twitter_relationship = TwitterRelationship.new(:follower_id => follower.db_object.id,
158
+ :friend_id => friend.db_object.id,
159
+ :current => true)
158
160
  if rules[:complete_friend_set]
159
161
  twitter_relationship[:complete_friend_set] = rules[:complete_friend_set]
160
162
  end
@@ -16,6 +16,9 @@ module Pork
16
16
  @search_params.from(@from_user) if @from_user
17
17
  begin
18
18
  loop do
19
+ if $PORK_LOG
20
+ $PORK_LOG.write("historical pull, query = #{@query}, max_id = #{@search_params.query[:max_id].to_s}")
21
+ end
19
22
  @tweets_pulled = @search_params.dup.fetch.results
20
23
  @tweets_pulled.each do |tweet|
21
24
  tweet.status_id = tweet.id
@@ -33,20 +36,30 @@ module Pork
33
36
  end
34
37
  end
35
38
  rescue Twitter::Unavailable
36
- p "ERROR: Twitter unavailable, trying in 60"
39
+ if $PORK_LOG
40
+ $PORK_LOG.write("ERROR: Twitter unavailable, trying in 60")
41
+ end
37
42
  sleep 60
38
43
  retry
39
44
  rescue Twitter::NotFound
40
- p "ERROR: Info target not found, trying to skip"
45
+ if $PORK_LOG
46
+ $PORK_LOG.write("ERROR: Info target not found, trying to skip")
47
+ end
41
48
  rescue Crack::ParseError
42
- p "Error: JSON Parsing error, trying to skip past problem tweet"
49
+ if $PORK_LOG
50
+ $PORK_LOG.write("Error: JSON Parsing error, trying to skip past problem tweet")
51
+ end
43
52
  @search_params.query[:max_id] -= 1000
44
53
  rescue Errno::ETIMEDOUT
45
- p "ERROR: Puller timed out, retrying in 10"
54
+ if $PORK_LOG
55
+ $PORK_LOG.write("ERROR: Puller timed out, retrying in 10")
56
+ end
46
57
  sleep 10
47
58
  retry
48
59
  rescue Twitter::InformTwitter
49
- p "ERROR: Twitter internal error, retrying in 30"
60
+ if $PORK_LOG
61
+ $PORK_LOG.write("ERROR: Twitter internal error, retrying in 30")
62
+ end
50
63
  sleep 30
51
64
  retry
52
65
  # rescue NoMethodError
@@ -0,0 +1,6 @@
1
+ module Pork
2
+ class TrendPuller
3
+
4
+
5
+ end
6
+ end
data/test/log_test.rb CHANGED
@@ -3,12 +3,26 @@ require "#{File.dirname(__FILE__)}/test_helper"
3
3
  class LogTest < Test::Unit::TestCase
4
4
  context "A default Log" do
5
5
  setup do
6
- @log = Pork::Log.new(STDOUT,{:researcher => "Researcher", :project => "Project"})
6
+ @log = Pork::Log.new('testlog.txt',{:researcher => "Researcher", :project => "Project"})
7
7
  end
8
8
 
9
9
  should "be able to be created" do
10
10
  @log.inspect
11
11
  end
12
+
13
+ should 'be able to write to the specified log file' do
14
+ @log.write("testing123")
15
+ log_string = ""
16
+ File.open('testlog.txt','r').each do |line|
17
+ log_string << line
18
+ end
19
+ assert log_string.include? ("testing123")
20
+ assert log_string.include? ("Project, Researcher")
21
+ end
22
+
23
+ teardown do
24
+ File.delete('testlog.txt')
25
+ end
12
26
  end
13
27
 
14
28
  end
@@ -0,0 +1,4 @@
1
+ # class RandomPullerTest < Test::Unit::TestCase
2
+ #
3
+ #
4
+ # end
data/test/saver_test.rb CHANGED
@@ -42,11 +42,11 @@ class SaverTest < Test::Unit::TestCase
42
42
  context "when saving a tweet_reaction" do
43
43
  setup do
44
44
  @tweet_reaction_size = TweetReaction.all.size
45
- @tweet_reaction = Factory.build(:tweet_reaction)
46
- @saver.save(@tweet_reaction, &REACTION_SAVE)
45
+ @tweet_reaction = {:tweet => Factory.create(:tweet),:initiator => Factory.create(:twitter_account), :responder => Factory.create(:twitter_account), :type => 'retweet'}
47
46
  end
48
47
 
49
48
  should "allow the reaction to be saved" do
49
+ @saver.save(@tweet_reaction, &REACTION_SAVE)
50
50
  assert_equal @tweet_reaction_size+1, TweetReaction.all.size
51
51
  end
52
52
  end
@@ -94,11 +94,11 @@ class SaverTest < Test::Unit::TestCase
94
94
  end
95
95
  context "when saving a tweet_reaction" do
96
96
  setup do
97
- @tweet_reaction = Factory.build(:tweet_reaction)
98
- @saver.save(@tweet_reaction, &REACTION_SAVE)
97
+ @tweet_reaction = {:tweet => Factory.create(:tweet),:initiator => Factory.create(:twitter_account), :responder => Factory.create(:twitter_account), :type => 'retweet'}
99
98
  end
100
99
 
101
100
  should "allow the reaction to be tagged" do
101
+ @saver.save(@tweet_reaction, &REACTION_SAVE)
102
102
  assert_contains TweetReaction.last.tag_list,@rules["tags"]["tag"]
103
103
  end
104
104
  end
data/test/test_helper.rb CHANGED
@@ -13,10 +13,18 @@ require 'rr'
13
13
 
14
14
  require "#{File.dirname(__FILE__)}/../lib/pork_sandwich"
15
15
 
16
+ Object.send :undef_method, :id
17
+
16
18
  class Test::Unit::TestCase
17
19
  include RR::Adapters::TestUnit
18
20
  config = YAML::load(File.open("#{File.dirname(__FILE__)}/../config/pork_config.yml"))
19
21
  $AUTH = Pork::Auth.new(config['config']['twitter_auth']['username'], config['config']['twitter_auth']['password'], :user_agent => 'web_ecology_project')
22
+ reaction_types = ['retweet', 'mention', 'reply']
23
+ reaction_types.each do |r|
24
+ unless Reaction.find_by_reaction_type(r)
25
+ Reaction.create(:reaction_type => r)
26
+ end
27
+ end
20
28
  end
21
29
 
22
30
 
@@ -33,6 +33,12 @@ class TwitterUserTest < Test::Unit::TestCase
33
33
  @user.update_account_info
34
34
  assert_equal 'Sam Gilbert', @user.user_info[:name]
35
35
  assert_equal 'sam1vp', @user.twitter_screen_name
36
+ assert_equal 'sam1vp', @user.db_object.screen_name
37
+ end
38
+ end
39
+ context "A TwitterUser with only a twitter_id" do
40
+ setup do
41
+ @user = Pork::TwitterUser.new({:twitter_id => 15019521})
36
42
  end
37
43
 
38
44
  should "be able to pull tweets" do
@@ -60,7 +66,6 @@ class TwitterUserTest < Test::Unit::TestCase
60
66
  assert_equal @user.db_object.id, TwitterRelationship.find(@user.follower_relationship_db_ids.first).friend_id
61
67
  end
62
68
 
63
-
64
69
  end
65
70
 
66
71
  end
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.8
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Gilbert
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-02-06 00:00:00 -05:00
13
+ date: 2010-02-17 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -59,9 +59,11 @@ files:
59
59
  - lib/pork_sandwich/crawler.rb
60
60
  - lib/pork_sandwich/log.rb
61
61
  - lib/pork_sandwich/puller.rb
62
+ - lib/pork_sandwich/random_puller.rb
62
63
  - lib/pork_sandwich/reaction_processor.rb
63
64
  - lib/pork_sandwich/saver.rb
64
65
  - lib/pork_sandwich/search.rb
66
+ - lib/pork_sandwich/trend_puller.rb
65
67
  - lib/pork_sandwich/twitter_user.rb
66
68
  has_rdoc: true
67
69
  homepage: http://github.com/sam1vp/pork_sandwich
@@ -98,6 +100,7 @@ test_files:
98
100
  - test/fakewebs.rb
99
101
  - test/log_test.rb
100
102
  - test/puller_test.rb
103
+ - test/random_puller_test.rb
101
104
  - test/reaction_processor_test.rb
102
105
  - test/saver_test.rb
103
106
  - test/schema.rb